Changeset 7508

Show
Ignore:
Timestamp:
03/01/07 14:40:11 (23 months ago)
Author:
alex
Message:

no idea how these files go so far behind the curve. This adds connectRunOnce back and implements some efficiency improvements.

Location:
branches/0.4/src/event
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.4/src/event/browser.js

    r6718 r7508  
    9393                                break; 
    9494                        default: 
    95                                 return eventName.toLowerCase(); 
     95                                var lcn = eventName.toLowerCase(); 
     96                                return (lcn.indexOf("on") == 0) ? lcn.substr(2) : lcn; 
    9697                                break; 
    9798                } 
     
    156157                if(!capture){ var capture = false; } 
    157158                evtName = dojo.event.browser.normalizedEventName(evtName); 
    158                 if( (evtName == "onkey") || (evtName == "key") ){ 
     159                if(evtName == "key"){ 
    159160                        if(dojo.render.html.ie){ 
    160161                                this.removeListener(node, "onkeydown", fp, capture); 
    161162                        } 
    162                         evtName = "onkeypress"; 
    163                 } 
    164                 if(evtName.substr(0,2)=="on"){ evtName = evtName.substr(2); } 
     163                        evtName = "keypress"; 
     164                } 
    165165                // FIXME: this is mostly a punt, we aren't actually doing anything on IE 
    166166                if(node.removeEventListener){ 
     
    188188                if(!capture){ var capture = false; } 
    189189                evtName = dojo.event.browser.normalizedEventName(evtName); 
    190                 if( (evtName == "onkey") || (evtName == "key") ){ 
     190                if(evtName == "key"){ 
    191191                        if(dojo.render.html.ie){ 
    192192                                this.addListener(node, "onkeydown", fp, capture, dontFix); 
    193193                        } 
    194                         evtName = "onkeypress"; 
    195                 } 
    196                 if(evtName.substr(0,2)!="on"){ evtName = "on"+evtName; } 
     194                        evtName = "keypress"; 
     195                } 
    197196 
    198197                if(!dontFix){ 
     
    212211 
    213212                if(node.addEventListener){  
    214                         node.addEventListener(evtName.substr(2), newfp, capture); 
     213                        node.addEventListener(evtName, newfp, capture); 
    215214                        return newfp; 
    216215                }else{ 
     216                        evtName = "on"+evtName; 
    217217                        if(typeof node[evtName] == "function" ){ 
    218218                                var oldEvt = node[evtName]; 
  • branches/0.4/src/event/common.js

    r6628 r7508  
    3838                        delay: null, 
    3939                        rate: 0, 
    40                         adviceMsg: false 
     40                        adviceMsg: false, 
     41                        maxCalls: -1 
    4142                }; 
    4243 
     
    137138                                ao.rate = args[9]; 
    138139                                ao.adviceMsg = args[10]; 
     140                                ao.maxCalls = (!isNaN(parseInt(args[11]))) ? args[11] : -1; 
    139141                                break; 
    140142                } 
     
    269271                                ao.rate = args[9]; 
    270272                                ao.adviceMsg = args[10]; 
     273                                ao.maxCalls = args[11]; 
    271274                */ 
    272275                if(arguments.length == 1){ 
     
    275278                        var ao = interpolateArgs(arguments, true); 
    276279                } 
     280                /* 
    277281                if(dojo.lang.isString(ao.srcFunc) && (ao.srcFunc.toLowerCase() == "onkey") ){ 
    278282                        if(dojo.render.html.ie){ 
     
    282286                        ao.srcFunc = "onkeypress"; 
    283287                } 
    284  
     288                */ 
    285289 
    286290                if(dojo.lang.isArray(ao.srcObj) && ao.srcObj!=""){ 
     
    341345                        } 
    342346                        dojo.debug("("+kwArgs.srcObj+")."+kwArgs.srcFunc, ":", argsStr.join(", ")); 
    343                 } 
     347                }; 
    344348                this.kwConnect(kwArgs); 
    345349        } 
     
    369373                var ao = interpolateArgs(arguments, true); 
    370374                ao.once = true; 
     375                return this.connect(ao); // a MethodJoinPoint object 
     376        } 
     377 
     378        this.connectRunOnce = function(){ 
     379                // summary: 
     380                //              takes the same parameters as dojo.event.connect(), except that 
     381                //              the "maxCalls" flag will always be set to 1 
     382                var ao = interpolateArgs(arguments, true); 
     383                ao.maxCalls = 1; 
    371384                return this.connect(ao); // a MethodJoinPoint object 
    372385        } 
     
    513526        //              the name of the function to return a MethodJoinPoint for 
    514527        if(!obj){ obj = dj_global; } 
    515         if(!obj[funcName]){ 
     528        var ofn = obj[funcName]; 
     529        if(!ofn){ 
    516530                // supply a do-nothing method implementation 
    517                 obj[funcName] = function(){}; 
     531                ofn = obj[funcName] = function(){}; 
    518532                if(!obj[funcName]){ 
    519533                        // e.g. cannot add to inbuilt objects in IE6 
    520534                        dojo.raise("Cannot set do-nothing method on that object "+funcName); 
    521535                } 
    522         }else if((!dojo.lang.isFunction(obj[funcName]))&&(!dojo.lang.isAlien(obj[funcName]))){ 
     536        }else if((typeof ofn != "function")&&(!dojo.lang.isFunction(ofn))&&(!dojo.lang.isAlien(ofn))){ 
    523537                // FIXME: should we throw an exception here instead? 
    524538                return null;  
     
    538552                        } 
    539553                } 
    540                 var origArity = obj[funcName].length; 
    541                 obj[jpfuncname] = obj[funcName]; 
     554                var origArity = ofn.length; 
     555                obj[jpfuncname] = ofn; 
    542556                // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, funcName); 
    543557                joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, jpfuncname); 
    544                 obj[funcName] = function(){  
    545                         var args = []; 
    546  
    547                         if((isNode)&&(!arguments.length)){ 
    548                                 var evt = null; 
    549                                 try{ 
    550                                         if(obj.ownerDocument){ 
    551                                                 evt = obj.ownerDocument.parentWindow.event; 
    552                                         }else if(obj.documentElement){ 
    553                                                 evt = obj.documentElement.ownerDocument.parentWindow.event; 
    554                                         }else if(obj.event){ //obj is a window 
    555                                                 evt = obj.event; 
    556                                         }else{ 
     558 
     559                if(!isNode){ 
     560                        obj[funcName] = function(){  
     561                                // var args = []; 
     562                                // for(var x=0; x<arguments.length; x++){ 
     563                                        // args.push(arguments[x]); 
     564                                // } 
     565                                // return joinpoint.run.apply(joinpoint, args);  
     566                                return joinpoint.run.apply(joinpoint, arguments);  
     567                        } 
     568                }else{ 
     569                        obj[funcName] = function(){  
     570                                var args = []; 
     571 
     572                                if(!arguments.length){ 
     573                                        var evt = null; 
     574                                        try{ 
     575                                                if(obj.ownerDocument){ 
     576                                                        evt = obj.ownerDocument.parentWindow.event; 
     577                                                }else if(obj.documentElement){ 
     578                                                        evt = obj.documentElement.ownerDocument.parentWindow.event; 
     579                                                }else if(obj.event){ //obj is a window 
     580                                                        evt = obj.event; 
     581                                                }else{ 
     582                                                        evt = window.event; 
     583                                                } 
     584                                        }catch(e){ 
    557585                                                evt = window.event; 
    558586                                        } 
    559                                 }catch(e){ 
    560                                         evt = window.event; 
    561                                 } 
    562  
    563                                 if(evt){ 
    564                                         args.push(dojo.event.browser.fixEvent(evt, this)); 
    565                                 } 
    566                         }else{ 
    567                                 for(var x=0; x<arguments.length; x++){ 
    568                                         if((x==0)&&(isNode)&&(dojo.event.browser.isEvent(arguments[x]))){ 
    569                                                 args.push(dojo.event.browser.fixEvent(arguments[x], this)); 
    570                                         }else{ 
    571                                                 args.push(arguments[x]); 
     587 
     588                                        if(evt){ 
     589                                                args.push(dojo.event.browser.fixEvent(evt, this)); 
     590                                        } 
     591                                }else{ 
     592                                        for(var x=0; x<arguments.length; x++){ 
     593                                                if((x==0)&&(dojo.event.browser.isEvent(arguments[x]))){ 
     594                                                        args.push(dojo.event.browser.fixEvent(arguments[x], this)); 
     595                                                }else{ 
     596                                                        args.push(arguments[x]); 
     597                                                } 
    572598                                        } 
    573599                                } 
    574                         } 
    575                         // return joinpoint.run.apply(joinpoint, arguments);  
    576                         return joinpoint.run.apply(joinpoint, args);  
     600                                // return joinpoint.run.apply(joinpoint, arguments);  
     601                                return joinpoint.run.apply(joinpoint, args);  
     602                        } 
    577603                } 
    578604                obj[funcName].__preJoinArity = origArity; 
     
    582608 
    583609dojo.lang.extend(dojo.event.MethodJoinPoint, { 
     610        squelch: false, 
     611 
    584612        unintercept: function(){ 
    585613                // summary:  
     
    625653                        var aroundFunc = marr[3]; 
    626654                        var msg = marr[6]; 
     655                        var maxCount = marr[7]; 
     656                        if(maxCount > -1){ 
     657                                if(maxCount == 0){ 
     658                                        return; 
     659                                } 
     660                                marr[7]--; 
     661                        } 
    627662                        var undef; 
    628663 
     
    688723                                } 
    689724                        } 
    690                 } 
     725                }; 
    691726 
    692727                var unRollSquelch = function(){ 
     
    700735                                return unrollAdvice.apply(this, arguments); 
    701736                        } 
    702                 } 
     737                }; 
    703738 
    704739                if((this["before"])&&(this.before.length>0)){ 
     
    760795                //                      - rate 
    761796                //                      - adviceMsg 
     797                //                      - maxCalls 
    762798                this.addAdvice( args["adviceObj"], args["adviceFunc"],  
    763799                                                args["aroundObj"], args["aroundFunc"],  
    764800                                                args["adviceType"], args["precedence"],  
    765801                                                args["once"], args["delay"], args["rate"],  
    766                                                 args["adviceMsg"]); 
     802                                                args["adviceMsg"], args["maxCalls"]); 
    767803        }, 
    768804 
     
    770806                                                        thisAroundObj, thisAround,  
    771807                                                        adviceType, precedence,  
    772                                                         once, delay, rate, asMessage){ 
     808                                                        once, delay, rate, asMessage, 
     809                                                        maxCalls){ 
    773810                // summary: 
    774811                //              add advice to this joinpoint using positional parameters 
     
    799836                //              boolean. Should the listener have all the parameters passed in 
    800837                //              as a single argument? 
     838                // maxCalls: 
     839                //              Integer. The maximum number of times this connection can be 
     840                //              used before being auto-disconnected. -1 signals that the 
     841                //              connection should never be disconnected. 
    801842                var arr = this.getArr(adviceType); 
    802843                if(!arr){ 
     
    804845                } 
    805846 
    806                 var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage]; 
     847                var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage, maxCalls]; 
    807848                 
    808849                if(once){