Changeset 17117 for lang/actionscript
- Timestamp:
- 08/05/08 23:52:42 (4 months ago)
- Location:
- lang/actionscript/todoshare
- Files:
-
- 5 modified
-
js/common.js (modified) (3 diffs)
-
js/jsonScr.js (modified) (5 diffs)
-
nohada.cgi (modified) (4 diffs)
-
perl/Obj.pm (modified) (1 diff)
-
suggest.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/actionscript/todoshare/js/common.js
r17019 r17117 6 6 onSuccess:function(httpObj){ 7 7 try { 8 print ("Applying: "+onComplete);8 //print ("Applying: "+onComplete); 9 9 onComplete.apply(env, [httpObj.responseText.evalJSON()] ); 10 print ("Applyed");10 //print ("Applyed"); 11 11 } catch(e) {handleError(e);} 12 12 }, … … 16 16 }); 17 17 } 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 27 19 function dbPut(query,after) { 28 20 db.apply(this,[["INSERT3",query],function (res) { … … 41 33 dbDel.async=true; 42 34 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;69 35 function link2obj(id) { 70 36 var href=encodeURI(id); -
lang/actionscript/todoshare/js/jsonScr.js
r17019 r17117 7 7 if (!b) throw e; 8 8 } 9 var state; 9 10 function compile() { 10 11 var f=_compile($A(arguments)); 11 return function () { 12 return function () { 12 13 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._; 16 17 } catch(e) {handleError(e);} 17 18 }; 18 19 } 19 20 function NOP(){} 20 // _compile:: scr -> ( this-> void )21 // _compile:: scr -> ( state -> void ) 21 22 function _compile(scr2) { 22 23 var scr=$A(scr2); … … 45 46 } 46 47 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 }56 48 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) 62 50 function compilePrimitive(value,next) { 63 51 return function () { 64 this._=value;65 next.apply( this,arguments);52 state._=value; 53 next.apply(state,arguments); 66 54 }; 67 55 } 68 // compileConstFunc :: Function -> ( this->void) -> (this->void)56 // compileConstFunc :: Function -> (state->void) -> (state->void) 69 57 function compileConstFunc(func,next) { 70 58 if (isAsyncFunc(func)) { 71 59 return function () { 72 traceCall( this,arguments);60 traceCall(state,arguments); 73 61 var a=$A(arguments); 74 62 a.push(next); 75 this._=func.apply(this,a);63 state._=func.apply(state,a); 76 64 }; 77 65 } else { 78 66 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); 82 70 }; 83 71 } 84 72 } 85 73 86 // compileArgs:: [argExpr] -> [ this->void]74 // compileArgs:: [argExpr] -> [state->void] 87 75 function compileArgs(argExpr) { 88 76 return argExpr.map(function (e) { … … 91 79 }); 92 80 } 93 // compileFunc:: Function -> [( this->void)] -> (this->void) -> ( this-> void )81 // compileFunc:: Function -> [(state->void)] -> (state->void) -> ( state -> void ) 94 82 function compileFunc(func,args,next) { 95 83 if (isAsyncFunc(func)) { … … 100 88 } 101 89 } 102 // compileSync:: Function -> [( this->void)] -> (this->void) -> ( this-> void )90 // compileSync:: Function -> [(state->void)] -> (state->void) -> ( state -> void ) 103 91 function compileSync(func,args,next) { 104 92 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); 110 98 }; 111 99 } 112 // compileAsync:: Function -> [( this->void)] -> (this->void) -> ( this-> void )100 // compileAsync:: Function -> [(state->void)] -> (state->void) -> ( state -> void ) 113 101 function compileAsync(afunc, args,next) { 114 102 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]); 117 106 args2.push(function (res) { 118 this._=res; 119 next.apply(this,arguments); 107 state=sts; 108 state._=res; 109 next.apply(state,arguments); 120 110 }); 121 this.arguments=arguments;122 this._=afunc.apply(this,args2);111 state.arguments=arguments; 112 state._=afunc.apply(state,args2); 123 113 }; 124 114 } 125 // evalArgs:: this -> [this->void] -> [Objects]115 // evalArgs:: state -> [state->void] -> [Objects] 126 116 function evalArgs(args) { 127 var env= this;117 var env=state; 128 118 var _save=env._; 129 119 var res=args.map(function (func) { … … 140 130 function gv(name) { 141 131 return [ 142 function () {return this[name];}132 function () {return state[name];} 143 133 ]; 144 134 } 135 // --------- Value type check 136 function isPrimitive(o) { 137 return o==null || 138 typeof(o)=="number" || 139 typeof(o)=="string" || 140 typeof(o)=="boolean"; 141 } 142 function isAsyncFunc (o) { 143 return isFunc(o) && o.async; 144 } 145 146 function isObj(o) { 147 return typeof(o)=="object"; 148 } 149 function isArray(o) { 150 return o instanceof Array; 151 } 152 function isFunc(o) { 153 return o instanceof Function; 154 } 155 function isHash(e) { 156 return typeof(e)=="object" && !isFunc(e) && !isArray(e); 157 } 158 159 //------ Debug 145 160 function traceCall(t,args) { 146 161 // print(Object.toJSON([t,args])); 147 162 } 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 }*/ 163 var consoleBuf=""; 164 var indent=""; 165 function 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 } 183 var handleError=print; 184 -
lang/actionscript/todoshare/nohada.cgi
r16697 r17117 35 35 }); 36 36 } 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 }54 37 55 38 var sugs=[]; 39 function 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 } 56 59 function init(id) { 57 60 sugs[id]= new Suggest.Local( 58 61 id, id+"_suggest",[id,id+"!"], 59 {dispAllKey: true });62 {dispAllKey: true, ajaxAction: doSearch(id)}); 60 63 } 61 64 var start = function(){ … … 94 97 script(src=>"suggest.js"), 95 98 script(src=>"js/common.js"), 99 script(src=>"js/jsonScr.js"), 96 100 [script,$scr], 97 101 link(rel=>"Stylesheet",type=>"text/css",href=>"css/default.css"), … … 105 109 [button(onClick=>"exe(this)"),"OK"], 106 110 [button(onClick=>"clearForm(this)"),"Clear"], 107 [div(id=>"test"),"test"] 111 [div(id=>"test"),"test"], 112 [span(id=>"console")] 108 113 ]] 109 114 ] … … 115 120 [td, 116 121 input(id=>$id,type=>"text",name=>$id,size=>50 117 ,onFocus =>"doFocus(this)", autocomplete=>"off" ),122 ,onFocus2=>"doFocus(this)", autocomplete=>"off" ), 118 123 $tail, 119 124 div(id=>"$id\_suggest",class=>"suggest")] -
lang/actionscript/todoshare/perl/Obj.pm
r17024 r17117 37 37 } 38 38 sub setUTF { 39 # query result not set utf flag 40 # query objects set utf flag 41 # if these will be concated, bakeru 39 42 my $href=shift; 40 43 for (values %$href) { -
lang/actionscript/todoshare/suggest.js
r16259 r17117 10 10 For details, see the web site: 11 11 http://www.enjoyxstudy.com/javascript/suggest/ 12 13 Modified by hoge1e3 14 12 15 13 16 -------------------------------------------------------- … … 40 43 Suggest.Local.prototype = { 41 44 initialize: function(input, suggestArea, candidateList) { 42 43 45 this.input = this._getElement(input); 44 46 this.suggestArea = this._getElement(suggestArea); … … 47 49 48 50 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; 49 55 50 56 // reg event … … 91 97 checkLoop: function() { 92 98 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 } 93 104 if (text != this.oldText) { 94 105 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 } 99 126 }, 100 127
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)