?? browser.js
字號:
/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.event.browser");dojo.require("dojo.event.common");// FIXME: any particular reason this is in the global scope?dojo._ie_clobber = new function(){ this.clobberNodes = []; function nukeProp(node, prop){ // try{ node.removeAttribute(prop); }catch(e){ /* squelch */ } try{ node[prop] = null; }catch(e){ /* squelch */ } try{ delete node[prop]; }catch(e){ /* squelch */ } // FIXME: JotLive needs this, but I'm not sure if it's too slow or not try{ node.removeAttribute(prop); }catch(e){ /* squelch */ } } this.clobber = function(nodeRef){ var na; var tna; if(nodeRef){ tna = nodeRef.all || nodeRef.getElementsByTagName("*"); na = [nodeRef]; for(var x=0; x<tna.length; x++){ // if we're gonna be clobbering the thing, at least make sure // we aren't trying to do it twice if(tna[x]["__doClobber__"]){ na.push(tna[x]); } } }else{ try{ window.onload = null; }catch(e){} na = (this.clobberNodes.length) ? this.clobberNodes : document.all; } tna = null; var basis = {}; for(var i = na.length-1; i>=0; i=i-1){ var el = na[i]; try{ if(el && el["__clobberAttrs__"]){ for(var j=0; j<el.__clobberAttrs__.length; j++){ nukeProp(el, el.__clobberAttrs__[j]); } nukeProp(el, "__clobberAttrs__"); nukeProp(el, "__doClobber__"); } }catch(e){ /* squelch! */}; } na = null; }}if(dojo.render.html.ie){ dojo.addOnUnload(function(){ dojo._ie_clobber.clobber(); try{ if((dojo["widget"])&&(dojo.widget["manager"])){ dojo.widget.manager.destroyAll(); } }catch(e){} // Workaround for IE leak recommended in ticket #1727 by schallm if(dojo.widget){ for(var name in dojo.widget._templateCache){ if(dojo.widget._templateCache[name].node){ dojo.dom.destroyNode(dojo.widget._templateCache[name].node); dojo.widget._templateCache[name].node = null; delete dojo.widget._templateCache[name].node; } } } try{ window.onload = null; }catch(e){} try{ window.onunload = null; }catch(e){} dojo._ie_clobber.clobberNodes = []; // CollectGarbage(); });}dojo.event.browser = new function(){ var clobberIdx = 0; this.normalizedEventName = function(/*String*/eventName){ switch(eventName){ case "CheckboxStateChange": case "DOMAttrModified": case "DOMMenuItemActive": case "DOMMenuItemInactive": case "DOMMouseScroll": case "DOMNodeInserted": case "DOMNodeRemoved": case "RadioStateChange": return eventName; break; default: return eventName.toLowerCase(); break; } } this.clean = function(/*DOMNode*/node){ // summary: // removes native event handlers so that destruction of the node // will not leak memory. On most browsers this is a no-op, but // it's critical for manual node removal on IE. // node: // A DOM node. All of it's children will also be cleaned. if(dojo.render.html.ie){ dojo._ie_clobber.clobber(node); } } this.addClobberNode = function(/*DOMNode*/node){ // summary: // register the passed node to support event stripping // node: // A DOM node if(!dojo.render.html.ie){ return; } if(!node["__doClobber__"]){ node.__doClobber__ = true; dojo._ie_clobber.clobberNodes.push(node); // this might not be the most efficient thing to do, but it's // much less error prone than other approaches which were // previously tried and failed node.__clobberAttrs__ = []; } } this.addClobberNodeAttrs = function(/*DOMNode*/node, /*Array*/props){ // summary: // register the passed node to support event stripping // node: // A DOM node to stip properties from later // props: // A list of propeties to strip from the node if(!dojo.render.html.ie){ return; } this.addClobberNode(node); for(var x=0; x<props.length; x++){ node.__clobberAttrs__.push(props[x]); } } this.removeListener = function( /*DOMNode*/ node, /*String*/ evtName, /*Function*/fp, /*Boolean*/ capture){ // summary: // clobbers the listener from the node // evtName: // the name of the handler to remove the function from // node: // DOM node to attach the event to // fp: // the function to register // capture: // Optional. should this listener prevent propigation? if(!capture){ var capture = false; } evtName = dojo.event.browser.normalizedEventName(evtName); if( (evtName == "onkey") || (evtName == "key") ){ if(dojo.render.html.ie){ this.removeListener(node, "onkeydown", fp, capture); } evtName = "onkeypress"; } if(evtName.substr(0,2)=="on"){ evtName = evtName.substr(2); } // FIXME: this is mostly a punt, we aren't actually doing anything on IE if(node.removeEventListener){ node.removeEventListener(evtName, fp, capture); } } this.addListener = function(/*DOMNode*/node, /*String*/evtName, /*Function*/fp, /*Boolean*/capture, /*Boolean*/dontFix){ // summary: // adds a listener to the node // evtName: // the name of the handler to add the listener to can be either of // the form "onclick" or "click" // node: // DOM node to attach the event to // fp: // the function to register // capture: // Optional. Should this listener prevent propigation? // dontFix: // Optional. Should we avoid registering a new closure around the // listener to enable fixEvent for dispatch of the registered // function? if(!node){ return; } // FIXME: log and/or bail? if(!capture){ var capture = false; } evtName = dojo.event.browser.normalizedEventName(evtName); if( (evtName == "onkey") || (evtName == "key") ){ if(dojo.render.html.ie){ this.addListener(node, "onkeydown", fp, capture, dontFix); } evtName = "onkeypress"; } if(evtName.substr(0,2)!="on"){ evtName = "on"+evtName; } if(!dontFix){ // build yet another closure around fp in order to inject fixEvent // around the resulting event var newfp = function(evt){ if(!evt){ evt = window.event; } var ret = fp(dojo.event.browser.fixEvent(evt, this)); if(capture){ dojo.event.browser.stopEvent(evt); } return ret; } }else{ newfp = fp; } if(node.addEventListener){ node.addEventListener(evtName.substr(2), newfp, capture); return newfp; }else{ if(typeof node[evtName] == "function" ){ var oldEvt = node[evtName]; node[evtName] = function(e){ oldEvt(e); return newfp(e); } }else{ node[evtName]=newfp; } if(dojo.render.html.ie){ this.addClobberNodeAttrs(node, [evtName]); } return newfp; } } this.isEvent = function(/*Object*/obj){ // summary: // Tries to determine whether or not the object is a DOM event. // FIXME: event detection hack ... could test for additional attributes // if necessary return (typeof obj != "undefined")&&(obj)&&(typeof Event != "undefined")&&(obj.eventPhase); // Boolean // Event does not support instanceof in Opera, otherwise: //return (typeof Event != "undefined")&&(obj instanceof Event); } this.currentEvent = null; this.callListener = function(/*Function*/listener, /*DOMNode*/curTarget){ // summary: // calls the specified listener in the context of the passed node // with the current DOM event object as the only parameter // listener: // the function to call // curTarget: // the Node to call the function in the scope of if(typeof listener != 'function'){ dojo.raise("listener not a function: " + listener); } dojo.event.browser.currentEvent.currentTarget = curTarget; return listener.call(curTarget, dojo.event.browser.currentEvent); } this._stopPropagation = function(){ dojo.event.browser.currentEvent.cancelBubble = true; } this._preventDefault = function(){ dojo.event.browser.currentEvent.returnValue = false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -