NodeList-html.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. define("dojo/NodeList-html", ["./query", "./_base/lang", "./html"], function(query, lang, html) {
  2. // module:
  3. // dojo/NodeList-html
  4. // summary:
  5. // TODOC
  6. var NodeList = query.NodeList;
  7. /*=====
  8. dojo["NodeList-html"] = {
  9. // summary: Adds a chainable html method to dojo.query() / Nodelist instances for setting/replacing node content
  10. };
  11. // doc helper aliases:
  12. NodeList = dojo.NodeList;
  13. =====*/
  14. lang.extend(NodeList, {
  15. html: function(/* String|DomNode|NodeList? */ content, /* Object? */params){
  16. // summary:
  17. // see `dojo.html.set()`. Set the content of all elements of this NodeList
  18. //
  19. // content:
  20. // An html string, node or enumerable list of nodes for insertion into the dom
  21. //
  22. // params:
  23. // Optional flags/properties to configure the content-setting. See dojo.html._ContentSetter
  24. //
  25. // description:
  26. // Based around `dojo.html.set()`, set the content of the Elements in a
  27. // NodeList to the given content (string/node/nodelist), with optional arguments
  28. // to further tune the set content behavior.
  29. //
  30. // example:
  31. // | dojo.query(".thingList").html("<li dojoType='dojo.dnd.Moveable'>1</li><li dojoType='dojo.dnd.Moveable'>2</li><li dojoType='dojo.dnd.Moveable'>3</li>",
  32. // | {
  33. // | parseContent: true,
  34. // | onBegin: function(){
  35. // | this.content = this.content.replace(/([0-9])/g, this.id + ": $1");
  36. // | this.inherited("onBegin", arguments);
  37. // | }
  38. // | }).removeClass("notdone").addClass("done");
  39. var dhs = new html._ContentSetter(params || {});
  40. this.forEach(function(elm){
  41. dhs.node = elm;
  42. dhs.set(content);
  43. dhs.tearDown();
  44. });
  45. return this; // dojo.NodeList
  46. }
  47. });
  48. return NodeList;
  49. });