Changeset 17117 for lang/actionscript

Show
Ignore:
Timestamp:
08/05/08 23:52:42 (4 months ago)
Author:
hoge1e3
Message:
 
Location:
lang/actionscript/todoshare
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/todoshare/js/common.js

    r17019 r17117  
    66                onSuccess:function(httpObj){ 
    77                   try { 
    8                      print ("Applying: "+onComplete); 
     8                     //print ("Applying: "+onComplete); 
    99                     onComplete.apply(env, [httpObj.responseText.evalJSON()] ); 
    10                      print ("Applyed"); 
     10                     //print ("Applyed"); 
    1111                   } catch(e) {handleError(e);} 
    1212                }, 
     
    1616   }); 
    1717} 
    18 function isArray(o) { 
    19   return o instanceof Array; 
    20 } 
    21 function isFunc(o) { 
    22   return o instanceof Function; 
    23 } 
    24 function isHash(e) { 
    25   return typeof(e)=="object" && !isFunc(e) && !isArray(e); 
    26 } 
     18 
    2719function dbPut(query,after) { 
    2820  db.apply(this,[["INSERT3",query],function (res) { 
     
    4133dbDel.async=true; 
    4234 
    43 Function.prototype.then=function (n) { 
    44   return function () { 
    45      return n(this.apply(this,arguments)); 
    46   }; 
    47 }; 
    48 var consoleBuf=""; 
    49 var indent=""; 
    50 function print() { 
    51   var app=indent; 
    52   $A(arguments).each(function (e) { 
    53     if (typeof(e)=="object") { 
    54        app+=Object.toJSON(e); 
    55     } else { 
    56        if (e==">") indent+="--"; 
    57        else if (e=="<") indent=indent.substring("--".length);        
    58        else app+=e; 
    59     } 
    60     app+=" "; 
    61   }); 
    62   var c=$("console"); 
    63   if (c) { 
    64      consoleBuf+=app+"<BR>\n"; 
    65      c.innerHTML=consoleBuf; 
    66   } else {alert(app);} 
    67 } 
    68 var handleError=print; 
    6935function link2obj(id) { 
    7036   var href=encodeURI(id); 
  • lang/actionscript/todoshare/js/jsonScr.js

    r17019 r17117  
    77  if (!b) throw e; 
    88} 
     9var state; 
    910function compile() { 
    1011  var f=_compile($A(arguments)); 
    11   return function () { 
     12  return function () {      
    1213     try { 
    13        var t={target:this, arguments:arguments, flag:"OK"}; 
    14        f.apply(t,[]); 
    15        return t._; 
     14       state={target:this, arguments:arguments, flag:"OK"}; 
     15       f.apply(state,[]); 
     16       return state._; 
    1617     } catch(e) {handleError(e);} 
    1718  }; 
    1819} 
    1920function NOP(){} 
    20 // _compile:: scr -> ( this -> void ) 
     21// _compile:: scr -> ( state -> void ) 
    2122function _compile(scr2) { 
    2223  var scr=$A(scr2); 
     
    4546} 
    4647 
    47 function isPrimitive(o) { 
    48   return o==null || 
    49       typeof(o)=="number" || 
    50       typeof(o)=="string" || 
    51       typeof(o)=="boolean"; 
    52 } 
    53 function isAsyncFunc (o) { 
    54   return isFunc(o) && o.async; 
    55 } 
    5648 
    57 function isObj(o) { 
    58   return typeof(o)=="object"; 
    59 }  
    60  
    61 // compilePrimitive :: value -> (this->void) -> (this->void) 
     49// compilePrimitive :: value -> (state->void) -> (state->void) 
    6250function compilePrimitive(value,next) { 
    6351   return function () { 
    64      this._=value; 
    65      next.apply(this,arguments); 
     52     state._=value; 
     53     next.apply(state,arguments); 
    6654   }; 
    6755} 
    68 // compileConstFunc :: Function -> (this->void) -> (this->void) 
     56// compileConstFunc :: Function -> (state->void) -> (state->void) 
    6957function compileConstFunc(func,next) { 
    7058  if (isAsyncFunc(func)) { 
    7159    return function () { 
    72       traceCall(this,arguments); 
     60      traceCall(state,arguments); 
    7361      var a=$A(arguments); 
    7462      a.push(next); 
    75       this._=func.apply(this,a); 
     63      state._=func.apply(state,a); 
    7664    }; 
    7765  } else { 
    7866    return function () { 
    79       traceCall(this,arguments); 
    80       this._=func.apply(this, arguments); 
    81       next.apply(this,arguments); 
     67      traceCall(state,arguments); 
     68      state._=func.apply(state, arguments); 
     69      next.apply(state,arguments); 
    8270    }; 
    8371  } 
    8472} 
    8573 
    86 // compileArgs:: [argExpr] -> [this->void] 
     74// compileArgs:: [argExpr] -> [state->void] 
    8775function compileArgs(argExpr) { 
    8876   return argExpr.map(function (e) { 
     
    9179   }); 
    9280}  
    93 // compileFunc:: Function -> [(this->void)] -> (this->void) -> ( this -> void )  
     81// compileFunc:: Function -> [(state->void)] -> (state->void) -> ( state -> void )  
    9482function compileFunc(func,args,next) { 
    9583    if (isAsyncFunc(func)) { 
     
    10088    }  
    10189} 
    102 // compileSync:: Function -> [(this->void)] -> (this->void) -> ( this -> void )  
     90// compileSync:: Function -> [(state->void)] -> (state->void) -> ( state -> void )  
    10391function compileSync(func,args,next) { 
    10492    return function () { 
    105       traceCall(this,arguments); 
    106       var args2=evalArgs.apply(this,[args]); 
    107       this.arguments=arguments; 
    108       this._=func.apply(this,args2); 
    109       next.apply(this,arguments); 
     93      traceCall(state,arguments); 
     94      var args2=evalArgs.apply(state,[args]); 
     95      state.arguments=arguments; 
     96      state._=func.apply(state,args2); 
     97      next.apply(state,arguments); 
    11098    }; 
    11199} 
    112 // compileAsync:: Function -> [(this->void)] -> (this->void) -> ( this -> void )  
     100// compileAsync:: Function -> [(state->void)] -> (state->void) -> ( state -> void )  
    113101function compileAsync(afunc, args,next) { 
    114102    return function () { 
    115       traceCall(this,arguments); 
    116       var args2=evalArgs.apply(this,[args]); 
     103      var sts=state; 
     104      traceCall(state,arguments); 
     105      var args2=evalArgs.apply(state,[args]); 
    117106      args2.push(function (res) { 
    118         this._=res; 
    119         next.apply(this,arguments); 
     107        state=sts; 
     108        state._=res; 
     109        next.apply(state,arguments); 
    120110      }); 
    121       this.arguments=arguments; 
    122       this._=afunc.apply(this,args2); 
     111      state.arguments=arguments; 
     112      state._=afunc.apply(state,args2); 
    123113    }; 
    124114} 
    125 // evalArgs:: this -> [this->void] -> [Objects] 
     115// evalArgs:: state -> [state->void] -> [Objects] 
    126116function evalArgs(args) { 
    127    var env=this; 
     117   var env=state; 
    128118   var _save=env._; 
    129119   var res=args.map(function (func) { 
     
    140130function gv(name) { 
    141131   return [ 
    142       function () {return this[name];} 
     132      function () {return state[name];} 
    143133   ]; 
    144134} 
     135// --------- Value type check 
     136function isPrimitive(o) { 
     137  return o==null || 
     138      typeof(o)=="number" || 
     139      typeof(o)=="string" || 
     140      typeof(o)=="boolean"; 
     141} 
     142function isAsyncFunc (o) { 
     143  return isFunc(o) && o.async; 
     144} 
     145 
     146function isObj(o) { 
     147  return typeof(o)=="object"; 
     148}  
     149function isArray(o) { 
     150  return o instanceof Array; 
     151} 
     152function isFunc(o) { 
     153  return o instanceof Function; 
     154} 
     155function isHash(e) { 
     156  return typeof(e)=="object" && !isFunc(e) && !isArray(e); 
     157} 
     158 
     159//------ Debug 
    145160function traceCall(t,args) { 
    146161//   print(Object.toJSON([t,args])); 
    147162} 
    148 //######################## 
    149 // compileObjOpr:: target -> options -> (this->void) -> (this->void) 
    150 /*function compileObjOpr(target,options,next) { 
    151   if (options.length==1) { 
    152      //options=[varName]; 
    153      var varName=options.shift(); 
    154      return function () { 
    155         this._=target[varName]; 
    156         next.apply(this,[]);  
    157      }; 
    158   } else if (options.length==2) { 
    159      //options=[varName,value]; 
    160      var varName=options.shift(); 
    161      var value  =options.shift(); 
    162      return function () { 
    163         target[varName]=value; 
    164         next.apply(this,[]);  
    165      };   
    166   } 
    167 }*/ 
     163var consoleBuf=""; 
     164var indent=""; 
     165function print() { 
     166  var app=indent; 
     167  $A(arguments).each(function (e) { 
     168    if (typeof(e)=="object") { 
     169       app+=Object.toJSON(e); 
     170    } else { 
     171       if (e==">") indent+="--"; 
     172       else if (e=="<") indent=indent.substring("--".length);        
     173       else app+=e; 
     174    } 
     175    app+=" "; 
     176  }); 
     177  var c=$("console"); 
     178  if (c) { 
     179     consoleBuf+=app+"<BR>\n"; 
     180     c.innerHTML=consoleBuf; 
     181  } else {alert(app);} 
     182} 
     183var handleError=print; 
     184 
  • lang/actionscript/todoshare/nohada.cgi

    r16697 r17117  
    3535  }); 
    3636} 
    37 function db(cmd,onComplete) { 
    38    new Ajax.Request("db.cgi", { 
    39                 method: "put", 
    40                 parameters: 'cmd='+encodeURI(Object.toJSON(cmd)) , 
    41                 onSuccess:function(httpObj){ 
    42                    try { 
    43                      onComplete( httpObj.responseText.evalJSON() ); 
    44                    } catch(e) {print(e);} 
    45                 }, 
    46                 onFailure:function(httpObj) { 
    47                    print (httpObj.responseText); 
    48                 } 
    49    }); 
    50 } 
    51 function print(c) { 
    52   $("test").innerHTML=c; 
    53 } 
    5437 
    5538var sugs=[]; 
     39function doSearch(tName) { 
     40  var val=function (name) { 
     41    return (name==tName?["*"]:["like",$(name).value+"%"]); 
     42  } 
     43  var list=[ 
     44     "FINDREL" , 
     45     val("obj"), 
     46     val("name"), 
     47     val("val") 
     48  ]; 
     49   
     50  return function (str,max,onEnd) { 
     51    db(list,function (data) { 
     52      var cand=data.map(function (e) { 
     53         return e[tName]; 
     54      }).sort().uniq(); 
     55      onEnd(cand); 
     56    }); 
     57  }; 
     58} 
    5659function init(id) { 
    5760   sugs[id]= new Suggest.Local( 
    5861             id, id+"_suggest",[id,id+"!"], 
    59              {dispAllKey: true});    
     62             {dispAllKey: true, ajaxAction: doSearch(id)});    
    6063}  
    6164var start = function(){ 
     
    9497      script(src=>"suggest.js"), 
    9598      script(src=>"js/common.js"), 
     99      script(src=>"js/jsonScr.js"), 
    96100      [script,$scr], 
    97101      link(rel=>"Stylesheet",type=>"text/css",href=>"css/default.css"), 
     
    105109      [button(onClick=>"exe(this)"),"OK"], 
    106110      [button(onClick=>"clearForm(this)"),"Clear"], 
    107       [div(id=>"test"),"test"] 
     111      [div(id=>"test"),"test"], 
     112      [span(id=>"console")] 
    108113    ]] 
    109114  ] 
     
    115120       [td, 
    116121            input(id=>$id,type=>"text",name=>$id,size=>50 
    117                   ,onFocus=>"doFocus(this)", autocomplete=>"off" ), 
     122                  ,onFocus2=>"doFocus(this)", autocomplete=>"off" ), 
    118123            $tail, 
    119124            div(id=>"$id\_suggest",class=>"suggest")] 
  • lang/actionscript/todoshare/perl/Obj.pm

    r17024 r17117  
    3737} 
    3838sub setUTF { 
     39# query result not set utf flag 
     40# query objects    set utf flag 
     41# if these will be concated, bakeru  
    3942  my $href=shift; 
    4043  for (values %$href) { 
  • lang/actionscript/todoshare/suggest.js

    r16259 r17117  
    1010For details, see the web site: 
    1111 http://www.enjoyxstudy.com/javascript/suggest/ 
     12  
     13Modified by hoge1e3 
     14  
    1215 
    1316-------------------------------------------------------- 
     
    4043Suggest.Local.prototype = { 
    4144  initialize: function(input, suggestArea, candidateList) { 
    42  
    4345    this.input = this._getElement(input); 
    4446    this.suggestArea = this._getElement(suggestArea); 
     
    4749 
    4850    if (arguments[3]) this.setOptions(arguments[3]); 
     51    // option may contain ajaxAction  
     52    // ajaxAction:: String -> maxResult:Int -> ([String] -> Unit) -> Unit  
     53    // ajaxArg!=null => ajaxAction(ajaxArg) == candidateList 
     54    this.ajaxArg=null; 
    4955 
    5056    // reg event 
     
    9197  checkLoop: function() { 
    9298    var text = this.getInputText(); 
     99    var t=this; 
     100    var nextTimer=function () { 
     101       if (t.timerId) clearTimeout(t.timerId); 
     102       t.timerId = setTimeout(t._bind(t.checkLoop), t.interval); 
     103    } 
    93104    if (text != this.oldText) { 
    94105      this.oldText = text; 
    95       this.search(); 
    96     } 
    97     if (this.timerId) clearTimeout(this.timerId); 
    98     this.timerId = setTimeout(this._bind(this.checkLoop), this.interval); 
     106      print ("starts? "+text.startsWith(this.ajaxArg)); 
     107      if (this.ajaxAction==null || 
     108          (this.ajaxArg!=null && text.startsWith(this.ajaxArg))  ) { 
     109      // ajaxArg: foo   text: fooo  
     110         this.search(); 
     111         nextTimer.apply(this,[]); 
     112      } else { 
     113      // ajaxArg: foo   text: fo  
     114         this.ajaxAction(text,this.dispMax,function (result) { 
     115           try{ 
     116             t.candidateList=result; 
     117             t.ajaxArg = text; 
     118             print ("Set ajaxArg = "+ t.ajaxArg); 
     119             t.search(); 
     120             if (result.length>t.dispMax) t.ajaxArg=null; 
     121             nextTimer.apply(t,[]); 
     122           } catch(e) {print (e);} 
     123         });   
     124      } 
     125    } 
    99126  }, 
    100127