1 | define(["./kernel", "../query", "./array", "./html", "../NodeList-dom"], function(dojo, query, array){ |
---|
2 | // module: |
---|
3 | // dojo/_base/NodeList |
---|
4 | |
---|
5 | /*===== |
---|
6 | return { |
---|
7 | // summary: |
---|
8 | // This module extends dojo/NodeList with the legacy connect(), coords(), |
---|
9 | // blur(), focus(), change(), click(), error(), keydown(), keypress(), |
---|
10 | // keyup(), load(), mousedown(), mouseenter(), mouseleave(), mousemove(), |
---|
11 | // mouseout(), mouseover(), mouseup(), and submit() methods. |
---|
12 | }; |
---|
13 | =====*/ |
---|
14 | |
---|
15 | var NodeList = query.NodeList, |
---|
16 | nlp = NodeList.prototype; |
---|
17 | |
---|
18 | nlp.connect = NodeList._adaptAsForEach(function(){ |
---|
19 | // don't bind early to dojo.connect since we no longer explicitly depend on it |
---|
20 | return dojo.connect.apply(this, arguments); |
---|
21 | }); |
---|
22 | /*===== |
---|
23 | nlp.connect = function(methodName, objOrFunc, funcName){ |
---|
24 | // summary: |
---|
25 | // Attach event handlers to every item of the NodeList. Uses dojo.connect() |
---|
26 | // so event properties are normalized. |
---|
27 | // |
---|
28 | // Application must manually require() "dojo/_base/connect" before using this method. |
---|
29 | // methodName: String |
---|
30 | // the name of the method to attach to. For DOM events, this should be |
---|
31 | // the lower-case name of the event |
---|
32 | // objOrFunc: Object|Function|String |
---|
33 | // if 2 arguments are passed (methodName, objOrFunc), objOrFunc should |
---|
34 | // reference a function or be the name of the function in the global |
---|
35 | // namespace to attach. If 3 arguments are provided |
---|
36 | // (methodName, objOrFunc, funcName), objOrFunc must be the scope to |
---|
37 | // locate the bound function in |
---|
38 | // funcName: String? |
---|
39 | // optional. A string naming the function in objOrFunc to bind to the |
---|
40 | // event. May also be a function reference. |
---|
41 | // example: |
---|
42 | // add an onclick handler to every button on the page |
---|
43 | // | query("div:nth-child(odd)").connect("onclick", function(e){ |
---|
44 | // | console.log("clicked!"); |
---|
45 | // | }); |
---|
46 | // example: |
---|
47 | // attach foo.bar() to every odd div's onmouseover |
---|
48 | // | query("div:nth-child(odd)").connect("onmouseover", foo, "bar"); |
---|
49 | |
---|
50 | return null; // NodeList |
---|
51 | }; |
---|
52 | =====*/ |
---|
53 | |
---|
54 | nlp.coords = NodeList._adaptAsMap(dojo.coords); |
---|
55 | /*===== |
---|
56 | nlp.coords = function(){ |
---|
57 | // summary: |
---|
58 | // Deprecated: Use position() for border-box x/y/w/h |
---|
59 | // or marginBox() for margin-box w/h/l/t. |
---|
60 | // Returns the box objects of all elements in a node list as |
---|
61 | // an Array (*not* a NodeList). Acts like `domGeom.coords`, though assumes |
---|
62 | // the node passed is each node in this list. |
---|
63 | |
---|
64 | return []; // Array |
---|
65 | }; |
---|
66 | =====*/ |
---|
67 | |
---|
68 | NodeList.events = [ |
---|
69 | // summary: |
---|
70 | // list of all DOM events used in NodeList |
---|
71 | "blur", "focus", "change", "click", "error", "keydown", "keypress", |
---|
72 | "keyup", "load", "mousedown", "mouseenter", "mouseleave", "mousemove", |
---|
73 | "mouseout", "mouseover", "mouseup", "submit" |
---|
74 | ]; |
---|
75 | |
---|
76 | // FIXME: pseudo-doc the above automatically generated on-event functions |
---|
77 | |
---|
78 | // syntactic sugar for DOM events |
---|
79 | array.forEach(NodeList.events, function(evt){ |
---|
80 | var _oe = "on" + evt; |
---|
81 | nlp[_oe] = function(a, b){ |
---|
82 | return this.connect(_oe, a, b); |
---|
83 | }; |
---|
84 | // FIXME: should these events trigger publishes? |
---|
85 | /* |
---|
86 | return (a ? this.connect(_oe, a, b) : |
---|
87 | this.forEach(function(n){ |
---|
88 | // FIXME: |
---|
89 | // listeners get buried by |
---|
90 | // addEventListener and can't be dug back |
---|
91 | // out to be triggered externally. |
---|
92 | // see: |
---|
93 | // http://developer.mozilla.org/en/docs/DOM:element |
---|
94 | |
---|
95 | console.log(n, evt, _oe); |
---|
96 | |
---|
97 | // FIXME: need synthetic event support! |
---|
98 | var _e = { target: n, faux: true, type: evt }; |
---|
99 | // dojo._event_listener._synthesizeEvent({}, { target: n, faux: true, type: evt }); |
---|
100 | try{ n[evt](_e); }catch(e){ console.log(e); } |
---|
101 | try{ n[_oe](_e); }catch(e){ console.log(e); } |
---|
102 | }) |
---|
103 | ); |
---|
104 | */ |
---|
105 | } |
---|
106 | ); |
---|
107 | |
---|
108 | dojo.NodeList = NodeList; |
---|
109 | return NodeList; |
---|
110 | }); |
---|