DomInline.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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["dojox.dtl.DomInline"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.dtl.DomInline"] = true;
  8. dojo.provide("dojox.dtl.DomInline");
  9. dojo.require("dojox.dtl.dom");
  10. dojo.require("dijit._Widget");
  11. dojox.dtl.DomInline = dojo.extend(function(args, node){
  12. this.create(args, node);
  13. },
  14. dijit._Widget.prototype,
  15. {
  16. context: null,
  17. render: function(/*dojox.dtl.Context?*/ context){
  18. this.context = context || this.context;
  19. this.postMixInProperties();
  20. var root = this.template.render(this.context).getRootNode();
  21. if(root != this.containerNode){
  22. this.containerNode.parentNode.replaceChild(root, this.containerNode);
  23. this.containerNode = root;
  24. }
  25. },
  26. declaredClass: "dojox.dtl.Inline",
  27. buildRendering: function(){
  28. var div = this.domNode = document.createElement("div");
  29. this.containerNode = div.appendChild(document.createElement("div"));
  30. var node = this.srcNodeRef;
  31. if(node.parentNode){
  32. node.parentNode.replaceChild(div, node);
  33. }
  34. this.template = new dojox.dtl.DomTemplate(dojo.trim(node.text), true);
  35. this.render();
  36. },
  37. postMixInProperties: function(){
  38. this.context = (this.context.get === dojox.dtl._Context.prototype.get) ? this.context : new dojox.dtl.Context(this.context);
  39. }
  40. });
  41. }