NodeList.js 3.4 KB

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