summaryrefslogtreecommitdiff
path: root/lib/dojo/_base/connect.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/_base/connect.js')
-rw-r--r--lib/dojo/_base/connect.js307
1 files changed, 2 insertions, 305 deletions
diff --git a/lib/dojo/_base/connect.js b/lib/dojo/_base/connect.js
index 7e8006221..6fa7aabc3 100644
--- a/lib/dojo/_base/connect.js
+++ b/lib/dojo/_base/connect.js
@@ -4,308 +4,5 @@
see: http://dojotoolkit.org/license for details
*/
-
-if(!dojo._hasResource["dojo._base.connect"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
-dojo._hasResource["dojo._base.connect"] = true;
-dojo.provide("dojo._base.connect");
-dojo.require("dojo._base.lang");
-
-
-// this file courtesy of the TurboAjax Group, licensed under a Dojo CLA
-
-// low-level delegation machinery
-dojo._listener = {
- // create a dispatcher function
- getDispatcher: function(){
- // following comments pulled out-of-line to prevent cloning them
- // in the returned function.
- // - indices (i) that are really in the array of listeners (ls) will
- // not be in Array.prototype. This is the 'sparse array' trick
- // that keeps us safe from libs that take liberties with built-in
- // objects
- // - listener is invoked with current scope (this)
- return function(){
- var ap = Array.prototype, c = arguments.callee, ls = c._listeners, t = c.target,
- // return value comes from original target function
- r = t && t.apply(this, arguments),
- // make local copy of listener array so it is immutable during processing
- i, lls = [].concat(ls)
- ;
-
- // invoke listeners after target function
- for(i in lls){
- if(!(i in ap)){
- lls[i].apply(this, arguments);
- }
- }
- // return value comes from original target function
- return r;
- };
- },
- // add a listener to an object
- add: function(/*Object*/ source, /*String*/ method, /*Function*/ listener){
- // Whenever 'method' is invoked, 'listener' will have the same scope.
- // Trying to supporting a context object for the listener led to
- // complexity.
- // Non trivial to provide 'once' functionality here
- // because listener could be the result of a dojo.hitch call,
- // in which case two references to the same hitch target would not
- // be equivalent.
- source = source || dojo.global;
- // The source method is either null, a dispatcher, or some other function
- var f = source[method];
- // Ensure a dispatcher
- if(!f || !f._listeners){
- var d = dojo._listener.getDispatcher();
- // original target function is special
- d.target = f;
- // dispatcher holds a list of listeners
- d._listeners = [];
- // redirect source to dispatcher
- f = source[method] = d;
- }
- // The contract is that a handle is returned that can
- // identify this listener for disconnect.
- //
- // The type of the handle is private. Here is it implemented as Integer.
- // DOM event code has this same contract but handle is Function
- // in non-IE browsers.
- //
- // We could have separate lists of before and after listeners.
- return f._listeners.push(listener); /*Handle*/
- },
- // remove a listener from an object
- remove: function(/*Object*/ source, /*String*/ method, /*Handle*/ handle){
- var f = (source || dojo.global)[method];
- // remember that handle is the index+1 (0 is not a valid handle)
- if(f && f._listeners && handle--){
- delete f._listeners[handle];
- }
- }
-};
-
-// Multiple delegation for arbitrary methods.
-
-// This unit knows nothing about DOM, but we include DOM aware documentation
-// and dontFix argument here to help the autodocs. Actual DOM aware code is in
-// event.js.
-
-dojo.connect = function(/*Object|null*/ obj,
- /*String*/ event,
- /*Object|null*/ context,
- /*String|Function*/ method,
- /*Boolean?*/ dontFix){
- // summary:
- // `dojo.connect` is the core event handling and delegation method in
- // Dojo. It allows one function to "listen in" on the execution of
- // any other, triggering the second whenever the first is called. Many
- // listeners may be attached to a function, and source functions may
- // be either regular function calls or DOM events.
- //
- // description:
- // Connects listeners to actions, so that after event fires, a
- // listener is called with the same arguments passed to the original
- // function.
- //
- // Since `dojo.connect` allows the source of events to be either a
- // "regular" JavaScript function or a DOM event, it provides a uniform
- // interface for listening to all the types of events that an
- // application is likely to deal with though a single, unified
- // interface. DOM programmers may want to think of it as
- // "addEventListener for everything and anything".
- //
- // When setting up a connection, the `event` parameter must be a
- // string that is the name of the method/event to be listened for. If
- // `obj` is null, `dojo.global` is assumed, meaning that connections
- // to global methods are supported but also that you may inadvertently
- // connect to a global by passing an incorrect object name or invalid
- // reference.
- //
- // `dojo.connect` generally is forgiving. If you pass the name of a
- // function or method that does not yet exist on `obj`, connect will
- // not fail, but will instead set up a stub method. Similarly, null
- // arguments may simply be omitted such that fewer than 4 arguments
- // may be required to set up a connection See the examples for details.
- //
- // The return value is a handle that is needed to
- // remove this connection with `dojo.disconnect`.
- //
- // obj:
- // The source object for the event function.
- // Defaults to `dojo.global` if null.
- // If obj is a DOM node, the connection is delegated
- // to the DOM event manager (unless dontFix is true).
- //
- // event:
- // String name of the event function in obj.
- // I.e. identifies a property `obj[event]`.
- //
- // context:
- // The object that method will receive as "this".
- //
- // If context is null and method is a function, then method
- // inherits the context of event.
- //
- // If method is a string then context must be the source
- // object object for method (context[method]). If context is null,
- // dojo.global is used.
- //
- // method:
- // A function reference, or name of a function in context.
- // The function identified by method fires after event does.
- // method receives the same arguments as the event.
- // See context argument comments for information on method's scope.
- //
- // dontFix:
- // If obj is a DOM node, set dontFix to true to prevent delegation
- // of this connection to the DOM event manager.
- //
- // example:
- // When obj.onchange(), do ui.update():
- // | dojo.connect(obj, "onchange", ui, "update");
- // | dojo.connect(obj, "onchange", ui, ui.update); // same
- //
- // example:
- // Using return value for disconnect:
- // | var link = dojo.connect(obj, "onchange", ui, "update");
- // | ...
- // | dojo.disconnect(link);
- //
- // example:
- // When onglobalevent executes, watcher.handler is invoked:
- // | dojo.connect(null, "onglobalevent", watcher, "handler");
- //
- // example:
- // When ob.onCustomEvent executes, customEventHandler is invoked:
- // | dojo.connect(ob, "onCustomEvent", null, "customEventHandler");
- // | dojo.connect(ob, "onCustomEvent", "customEventHandler"); // same
- //
- // example:
- // When ob.onCustomEvent executes, customEventHandler is invoked
- // with the same scope (this):
- // | dojo.connect(ob, "onCustomEvent", null, customEventHandler);
- // | dojo.connect(ob, "onCustomEvent", customEventHandler); // same
- //
- // example:
- // When globalEvent executes, globalHandler is invoked
- // with the same scope (this):
- // | dojo.connect(null, "globalEvent", null, globalHandler);
- // | dojo.connect("globalEvent", globalHandler); // same
-
- // normalize arguments
- var a=arguments, args=[], i=0;
- // if a[0] is a String, obj was omitted
- args.push(dojo.isString(a[0]) ? null : a[i++], a[i++]);
- // if the arg-after-next is a String or Function, context was NOT omitted
- var a1 = a[i+1];
- args.push(dojo.isString(a1)||dojo.isFunction(a1) ? a[i++] : null, a[i++]);
- // absorb any additional arguments
- for(var l=a.length; i<l; i++){ args.push(a[i]); }
- // do the actual work
- return dojo._connect.apply(this, args); /*Handle*/
-}
-
-// used by non-browser hostenvs. always overriden by event.js
-dojo._connect = function(obj, event, context, method){
- var l=dojo._listener, h=l.add(obj, event, dojo.hitch(context, method));
- return [obj, event, h, l]; // Handle
-};
-
-dojo.disconnect = function(/*Handle*/ handle){
- // summary:
- // Remove a link created by dojo.connect.
- // description:
- // Removes the connection between event and the method referenced by handle.
- // handle:
- // the return value of the dojo.connect call that created the connection.
- if(handle && handle[0] !== undefined){
- dojo._disconnect.apply(this, handle);
- // let's not keep this reference
- delete handle[0];
- }
-};
-
-dojo._disconnect = function(obj, event, handle, listener){
- listener.remove(obj, event, handle);
-};
-
-// topic publish/subscribe
-
-dojo._topics = {};
-
-dojo.subscribe = function(/*String*/ topic, /*Object|null*/ context, /*String|Function*/ method){
- // summary:
- // Attach a listener to a named topic. The listener function is invoked whenever the
- // named topic is published (see: dojo.publish).
- // Returns a handle which is needed to unsubscribe this listener.
- // context:
- // Scope in which method will be invoked, or null for default scope.
- // method:
- // The name of a function in context, or a function reference. This is the function that
- // is invoked when topic is published.
- // example:
- // | dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); });
- // | dojo.publish("alerts", [ "read this", "hello world" ]);
-
- // support for 2 argument invocation (omitting context) depends on hitch
- return [topic, dojo._listener.add(dojo._topics, topic, dojo.hitch(context, method))]; /*Handle*/
-};
-
-dojo.unsubscribe = function(/*Handle*/ handle){
- // summary:
- // Remove a topic listener.
- // handle:
- // The handle returned from a call to subscribe.
- // example:
- // | var alerter = dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
- // | ...
- // | dojo.unsubscribe(alerter);
- if(handle){
- dojo._listener.remove(dojo._topics, handle[0], handle[1]);
- }
-};
-
-dojo.publish = function(/*String*/ topic, /*Array*/ args){
- // summary:
- // Invoke all listener method subscribed to topic.
- // topic:
- // The name of the topic to publish.
- // args:
- // An array of arguments. The arguments will be applied
- // to each topic subscriber (as first class parameters, via apply).
- // example:
- // | dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
- // | dojo.publish("alerts", [ "read this", "hello world" ]);
-
- // Note that args is an array, which is more efficient vs variable length
- // argument list. Ideally, var args would be implemented via Array
- // throughout the APIs.
- var f = dojo._topics[topic];
- if(f){
- f.apply(this, args||[]);
- }
-};
-
-dojo.connectPublisher = function( /*String*/ topic,
- /*Object|null*/ obj,
- /*String*/ event){
- // summary:
- // Ensure that every time obj.event() is called, a message is published
- // on the topic. Returns a handle which can be passed to
- // dojo.disconnect() to disable subsequent automatic publication on
- // the topic.
- // topic:
- // The name of the topic to publish.
- // obj:
- // The source object for the event function. Defaults to dojo.global
- // if null.
- // event:
- // The name of the event function in obj.
- // I.e. identifies a property obj[event].
- // example:
- // | dojo.connectPublisher("/ajax/start", dojo, "xhrGet");
- var pf = function(){ dojo.publish(topic, arguments); }
- return event ? dojo.connect(obj, event, pf) : dojo.connect(obj, pf); //Handle
-};
-
-}
+//>>built
+define("dojo/_base/connect",["./kernel","../on","../topic","../aspect","./event","../mouse","./sniff","./lang","../keys"],function(_1,on,_2,_3,_4,_5,_6,_7){_6.add("events-keypress-typed",function(){var _8={charCode:0};try{_8=document.createEvent("KeyboardEvent");(_8.initKeyboardEvent||_8.initKeyEvent).call(_8,"keypress",true,true,null,false,false,false,false,9,3);}catch(e){}return _8.charCode==0&&!_6("opera");});function _9(_a,_b,_c,_d,_e){_d=_7.hitch(_c,_d);if(!_a||!(_a.addEventListener||_a.attachEvent)){return _3.after(_a||_1.global,_b,_d,true);}if(typeof _b=="string"&&_b.substring(0,2)=="on"){_b=_b.substring(2);}if(!_a){_a=_1.global;}if(!_e){switch(_b){case "keypress":_b=_f;break;case "mouseenter":_b=_5.enter;break;case "mouseleave":_b=_5.leave;break;}}return on(_a,_b,_d,_e);};var _10={106:42,111:47,186:59,187:43,188:44,189:45,190:46,191:47,192:96,219:91,220:92,221:93,222:39,229:113};var _11=_6("mac")?"metaKey":"ctrlKey";var _12=function(evt,_13){var _14=_7.mixin({},evt,_13);_15(_14);_14.preventDefault=function(){evt.preventDefault();};_14.stopPropagation=function(){evt.stopPropagation();};return _14;};function _15(evt){evt.keyChar=evt.charCode?String.fromCharCode(evt.charCode):"";evt.charOrCode=evt.keyChar||evt.keyCode;};var _f;if(_6("events-keypress-typed")){var _16=function(e,_17){try{return (e.keyCode=_17);}catch(e){return 0;}};_f=function(_18,_19){var _1a=on(_18,"keydown",function(evt){var k=evt.keyCode;var _1b=(k!=13||(_6("ie")>=9&&!_6("quirks")))&&k!=32&&(k!=27||!_6("ie"))&&(k<48||k>90)&&(k<96||k>111)&&(k<186||k>192)&&(k<219||k>222)&&k!=229;if(_1b||evt.ctrlKey){var c=_1b?0:k;if(evt.ctrlKey){if(k==3||k==13){return _19.call(evt.currentTarget,evt);}else{if(c>95&&c<106){c-=48;}else{if((!evt.shiftKey)&&(c>=65&&c<=90)){c+=32;}else{c=_10[c]||c;}}}}var _1c=_12(evt,{type:"keypress",faux:true,charCode:c});_19.call(evt.currentTarget,_1c);if(_6("ie")){_16(evt,_1c.keyCode);}}});var _1d=on(_18,"keypress",function(evt){var c=evt.charCode;c=c>=32?c:0;evt=_12(evt,{charCode:c,faux:true});return _19.call(this,evt);});return {remove:function(){_1a.remove();_1d.remove();}};};}else{if(_6("opera")){_f=function(_1e,_1f){return on(_1e,"keypress",function(evt){var c=evt.which;if(c==3){c=99;}c=c<32&&!evt.shiftKey?0:c;if(evt.ctrlKey&&!evt.shiftKey&&c>=65&&c<=90){c+=32;}return _1f.call(this,_12(evt,{charCode:c}));});};}else{_f=function(_20,_21){return on(_20,"keypress",function(evt){_15(evt);return _21.call(this,evt);});};}}var _22={_keypress:_f,connect:function(obj,_23,_24,_25,_26){var a=arguments,_27=[],i=0;_27.push(typeof a[0]=="string"?null:a[i++],a[i++]);var a1=a[i+1];_27.push(typeof a1=="string"||typeof a1=="function"?a[i++]:null,a[i++]);for(var l=a.length;i<l;i++){_27.push(a[i]);}return _9.apply(this,_27);},disconnect:function(_28){if(_28){_28.remove();}},subscribe:function(_29,_2a,_2b){return _2.subscribe(_29,_7.hitch(_2a,_2b));},publish:function(_2c,_2d){return _2.publish.apply(_2,[_2c].concat(_2d));},connectPublisher:function(_2e,obj,_2f){var pf=function(){_22.publish(_2e,arguments);};return _2f?_22.connect(obj,_2f,pf):_22.connect(obj,pf);},isCopyKey:function(e){return e[_11];}};_22.unsubscribe=_22.disconnect;1&&_7.mixin(_1,_22);return _22;}); \ No newline at end of file