NodeList-html.js 1.7 KB

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