Changeset 7508
- Timestamp:
- 03/01/07 14:40:11 (23 months ago)
- Location:
- branches/0.4/src/event
- Files:
-
- 2 modified
-
browser.js (modified) (4 diffs)
-
common.js (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4/src/event/browser.js
r6718 r7508 93 93 break; 94 94 default: 95 return eventName.toLowerCase(); 95 var lcn = eventName.toLowerCase(); 96 return (lcn.indexOf("on") == 0) ? lcn.substr(2) : lcn; 96 97 break; 97 98 } … … 156 157 if(!capture){ var capture = false; } 157 158 evtName = dojo.event.browser.normalizedEventName(evtName); 158 if( (evtName == "onkey") || (evtName == "key")){159 if(evtName == "key"){ 159 160 if(dojo.render.html.ie){ 160 161 this.removeListener(node, "onkeydown", fp, capture); 161 162 } 162 evtName = "onkeypress"; 163 } 164 if(evtName.substr(0,2)=="on"){ evtName = evtName.substr(2); } 163 evtName = "keypress"; 164 } 165 165 // FIXME: this is mostly a punt, we aren't actually doing anything on IE 166 166 if(node.removeEventListener){ … … 188 188 if(!capture){ var capture = false; } 189 189 evtName = dojo.event.browser.normalizedEventName(evtName); 190 if( (evtName == "onkey") || (evtName == "key")){190 if(evtName == "key"){ 191 191 if(dojo.render.html.ie){ 192 192 this.addListener(node, "onkeydown", fp, capture, dontFix); 193 193 } 194 evtName = "onkeypress"; 195 } 196 if(evtName.substr(0,2)!="on"){ evtName = "on"+evtName; } 194 evtName = "keypress"; 195 } 197 196 198 197 if(!dontFix){ … … 212 211 213 212 if(node.addEventListener){ 214 node.addEventListener(evtName .substr(2), newfp, capture);213 node.addEventListener(evtName, newfp, capture); 215 214 return newfp; 216 215 }else{ 216 evtName = "on"+evtName; 217 217 if(typeof node[evtName] == "function" ){ 218 218 var oldEvt = node[evtName]; -
branches/0.4/src/event/common.js
r6628 r7508 38 38 delay: null, 39 39 rate: 0, 40 adviceMsg: false 40 adviceMsg: false, 41 maxCalls: -1 41 42 }; 42 43 … … 137 138 ao.rate = args[9]; 138 139 ao.adviceMsg = args[10]; 140 ao.maxCalls = (!isNaN(parseInt(args[11]))) ? args[11] : -1; 139 141 break; 140 142 } … … 269 271 ao.rate = args[9]; 270 272 ao.adviceMsg = args[10]; 273 ao.maxCalls = args[11]; 271 274 */ 272 275 if(arguments.length == 1){ … … 275 278 var ao = interpolateArgs(arguments, true); 276 279 } 280 /* 277 281 if(dojo.lang.isString(ao.srcFunc) && (ao.srcFunc.toLowerCase() == "onkey") ){ 278 282 if(dojo.render.html.ie){ … … 282 286 ao.srcFunc = "onkeypress"; 283 287 } 284 288 */ 285 289 286 290 if(dojo.lang.isArray(ao.srcObj) && ao.srcObj!=""){ … … 341 345 } 342 346 dojo.debug("("+kwArgs.srcObj+")."+kwArgs.srcFunc, ":", argsStr.join(", ")); 343 } 347 }; 344 348 this.kwConnect(kwArgs); 345 349 } … … 369 373 var ao = interpolateArgs(arguments, true); 370 374 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; 371 384 return this.connect(ao); // a MethodJoinPoint object 372 385 } … … 513 526 // the name of the function to return a MethodJoinPoint for 514 527 if(!obj){ obj = dj_global; } 515 if(!obj[funcName]){ 528 var ofn = obj[funcName]; 529 if(!ofn){ 516 530 // supply a do-nothing method implementation 517 o bj[funcName] = function(){};531 ofn = obj[funcName] = function(){}; 518 532 if(!obj[funcName]){ 519 533 // e.g. cannot add to inbuilt objects in IE6 520 534 dojo.raise("Cannot set do-nothing method on that object "+funcName); 521 535 } 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))){ 523 537 // FIXME: should we throw an exception here instead? 524 538 return null; … … 538 552 } 539 553 } 540 var origArity = o bj[funcName].length;541 obj[jpfuncname] = o bj[funcName];554 var origArity = ofn.length; 555 obj[jpfuncname] = ofn; 542 556 // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, funcName); 543 557 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){ 557 585 evt = window.event; 558 586 } 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 } 572 598 } 573 599 } 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 } 577 603 } 578 604 obj[funcName].__preJoinArity = origArity; … … 582 608 583 609 dojo.lang.extend(dojo.event.MethodJoinPoint, { 610 squelch: false, 611 584 612 unintercept: function(){ 585 613 // summary: … … 625 653 var aroundFunc = marr[3]; 626 654 var msg = marr[6]; 655 var maxCount = marr[7]; 656 if(maxCount > -1){ 657 if(maxCount == 0){ 658 return; 659 } 660 marr[7]--; 661 } 627 662 var undef; 628 663 … … 688 723 } 689 724 } 690 } 725 }; 691 726 692 727 var unRollSquelch = function(){ … … 700 735 return unrollAdvice.apply(this, arguments); 701 736 } 702 } 737 }; 703 738 704 739 if((this["before"])&&(this.before.length>0)){ … … 760 795 // - rate 761 796 // - adviceMsg 797 // - maxCalls 762 798 this.addAdvice( args["adviceObj"], args["adviceFunc"], 763 799 args["aroundObj"], args["aroundFunc"], 764 800 args["adviceType"], args["precedence"], 765 801 args["once"], args["delay"], args["rate"], 766 args["adviceMsg"] );802 args["adviceMsg"], args["maxCalls"]); 767 803 }, 768 804 … … 770 806 thisAroundObj, thisAround, 771 807 adviceType, precedence, 772 once, delay, rate, asMessage){ 808 once, delay, rate, asMessage, 809 maxCalls){ 773 810 // summary: 774 811 // add advice to this joinpoint using positional parameters … … 799 836 // boolean. Should the listener have all the parameters passed in 800 837 // 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. 801 842 var arr = this.getArr(adviceType); 802 843 if(!arr){ … … 804 845 } 805 846 806 var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage ];847 var ao = [thisAdviceObj, thisAdvice, thisAroundObj, thisAround, delay, rate, asMessage, maxCalls]; 807 848 808 849 if(once){