NodeList-html.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojo.NodeList-html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo.NodeList-html"] = true;
  8. dojo.provide("dojo.NodeList-html");
  9. dojo.require("dojo.html");
  10. /*=====
  11. dojo["NodeList-html"] = {
  12. // summary: Adds a chainable html method to dojo.query() / Nodelist instances for setting/replacing node content
  13. };
  14. =====*/
  15. dojo.extend(dojo.NodeList, {
  16. html: function(content, /* Object? */params){
  17. // summary:
  18. // see `dojo.html.set()`. Set the content of all elements of this NodeList
  19. //
  20. // description:
  21. // Based around `dojo.html.set()`, set the content of the Elements in a
  22. // NodeList to the given content (string/node/nodelist), with optional arguments
  23. // to further tune the set content behavior.
  24. //
  25. // example:
  26. // | 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>",
  27. // | {
  28. // | parseContent: true,
  29. // | onBegin: function(){
  30. // | this.content = this.content.replace(/([0-9])/g, this.id + ": $1");
  31. // | this.inherited("onBegin", arguments);
  32. // | }
  33. // | }).removeClass("notdone").addClass("done");
  34. var dhs = new dojo.html._ContentSetter(params || {});
  35. this.forEach(function(elm){
  36. dhs.node = elm;
  37. dhs.set(content);
  38. dhs.tearDown();
  39. });
  40. return this; // dojo.NodeList
  41. }
  42. });
  43. }