dojox/dtl/dom.js

  • Provides:

    • dojox.dtl.dom
  • Requires:

    • dojox.dtl._base in common
    • dojox.dtl.Context in common
  • dojox.dtl.BOOLS

    • type
      Object
    • summary
  • dojox.dtl.TOKEN_CHANGE

    • summary
  • dojox.dtl.TOKEN_ATTR

    • summary
  • dojox.dtl.TOKEN_CUSTOM

    • summary
  • dojox.dtl.TOKEN_NODE

    • summary
  • dojox.dtl.DomTemplate

    • type
      Function
    • parameters:
      • obj: (typeof String|DOMNode|dojo._Url)
    • source: [view]
        if(!obj.nodes){
         var node = dojo.byId(obj);
         if(node && node.nodeType == 1){
          dojo.forEach(["class", "src", "href", "name", "value"], function(item){
           ddh._attributes[item] = true;
          });
          obj = {
           nodes: [node]
          };
         }else{
          if(typeof obj == "object"){
           obj = ddt.getTemplateString(obj);
          }
          obj = ddh.getTemplate(obj);
         }
        }


        var tokens = ddh.tokenize(obj.nodes);
        if(dd.tests){
         this.tokens = tokens.slice(0);
        }


        var parser = new dd._DomParser(tokens);
        this.nodelist = parser.parse();
    • summary
      Use this object for DOM templating
  • dojox.dtl.DomBuffer

    • type
      Function
    • parameters:
      • parent: (typeof Node)
    • source: [view]
        this._parent = parent;
        this._cache = [];
    • summary
      Allows the manipulation of DOM
    • description
      Use this to append a child, change the parent, or
      change the attribute of the current node.
  • dojox.dtl._DomNode

    • type
      Function
    • parameters:
      • node: (typeof )
    • source: [view]
        this.contents = node;
    • summary
      Places a node into DOM
  • dojox.dtl._DomNodeList

    • type
      Function
    • parameters:
      • nodes: (typeof Node[])
    • source: [view]
        this.contents = nodes || [];
    • summary
      A list of any DOM-specific node objects
    • description
      Any object that's used in the constructor or added
      through the push function much implement the
      render, unrender, and clone functions.
  • dojox.dtl._DomVarNode

    • type
      Function
    • parameters:
      • str: (typeof )
    • source: [view]
        this.contents = new dd._Filter(str);
    • summary
      A node to be processed as a variable
    • description
      Will render an object that supports the render function
      and the getRootNode function
  • dojox.dtl.ChangeNode

    • type
      Function
    • parameters:
      • node: (typeof )
      • up: (typeof Boolean)
      • root: (typeof Bookean)
    • source: [view]
        this.contents = node;
        this.up = up;
        this.root = root;
    • summary
      Changes the parent during render/unrender
  • dojox.dtl.AttributeNode

    • type
      Function
    • parameters:
      • key: (typeof )
      • value: (typeof )
    • source: [view]
        this.key = key;
        this.value = value;
        this.contents = value;
        if(this._pool[value]){
         this.nodelist = this._pool[value];
        }else{
         if(!(this.nodelist = dd.quickFilter(value))){
          this.nodelist = (new dd.Template(value, true)).nodelist;
         }
         this._pool[value] = this.nodelist;
        }


        this.contents = "";
    • summary
      Works on attributes
  • dojox.dtl._DomTextNode

    • type
      Function
    • parameters:
      • str: (typeof )
    • source: [view]
        this.contents = document.createTextNode(str);
        this.upcoming = str;
    • summary
      Adds a straight text node without any processing
  • dojox.dtl._DomParser

    • type
      Function
    • parameters:
      • tokens: (typeof )
    • source: [view]
        this.contents = tokens;
    • summary
      Turn a simple array into a set of objects
    • description
      This is also used by all tags to move through
      the list of nodes.
  • dojox.dtl.BOOLS.checked

    • summary
  • dojox.dtl.BOOLS.disabled

    • summary
  • dojox.dtl.BOOLS.readonly

    • summary
  • dojox.dtl.dom._attributes

    • type
      Object
    • summary
  • dojox.dtl.dom._uppers

    • type
      Object
    • summary
  • dojox.dtl.dom._re4

    • summary
  • dojox.dtl.dom._reTrim

    • summary
  • dojox.dtl.dom._reSplit

    • summary
  • dojox.dtl.dom.getTemplate

    • type
      Function
    • parameters:
      • text: (typeof )
    • source: [view]
         if(typeof this._commentable == "undefined"){
          // Check to see if the browser can handle comments
          this._commentable = false;
          var div = document.createElement("div");
          div.innerHTML = "";
          if(div.childNodes.length && div.childNodes[0].nodeType == 8 && div.childNodes[0].data == "comment"){
           this._commentable = true;
          }
         }


         if(!this._commentable){
          // Strip comments
          text = text.replace(//g, "$1");
         }


         if(dojo.isIE){
          text = text.replace(/\b(checked|disabled|readonly|style)="/g, 't$1="');
         }
         text = text.replace(/\bstyle="/g, 'tstyle="');


         var match;
         var table = dojo.isWebKit;
         var pairs = [ // Format: [enable, parent, allowed children (first for nesting), nestings]
          [true, "select", "option"],
          [table, "tr", "td|th"],
          [table, "thead", "tr", "th"],
          [table, "tbody", "tr", "td"],
          [table, "table", "tbody|thead|tr", "tr", "td"]
         ];
         var replacements = [];
         // Some tags can't contain text. So we wrap the text in tags that they can have.
         for(var i = 0, pair; pair = pairs[i]; i++){
          if(!pair[0]){
           continue;
          }
          if(text.indexOf("<" + pair[1]) != -1){
           var selectRe = new RegExp("<" + pair[1] + "(?:.|\n)*?>((?:.|\n)+?)", "ig");
           tagLoop: while(match = selectRe.exec(text)){
            // Do it like this to make sure we don't double-wrap
            var inners = pair[2].split("|");
            var innerRe = [];
            for(var j = 0, inner; inner = inners[j]; j++){
             innerRe.push("<" + inner + "(?:.|\n)*?>(?:.|\n)*?");
            }
            var tags = [];
            var tokens = dojox.string.tokenize(match[1], new RegExp("(" + innerRe.join("|") + ")", "ig"), function(data){
             var tag = /<(\w+)/.exec(data)[1];
             if(!tags[tag]){
              tags[tag] = true;
              tags.push(tag);
             }
             return {data: data};
            });
            if(tags.length){
             var tag = (tags.length == 1) ? tags[0] : pair[2].split("|")[0];


             var replace = [];
             for(var j = 0, jl = tokens.length; j < jl; j++) {
              var token = tokens[j];
              if(dojo.isObject(token)){
               replace.push(token.data);
              }else{
               var stripped = token.replace(this._reTrim, "");
               if(!stripped){ continue; }
               token = stripped.split(this._reSplit);
               for(var k = 0, kl = token.length; k < kl; k++){
                var replacement = "";
                for(var p = 2, pl = pair.length; p < pl; p++){
                 if(p == 2){
                  replacement += "<" + tag + ' dtlinstruction="{% ' + token[k].replace('"', '\\"') + ' %}">';
                 }else if(tag == pair[p]) {
                  continue;
                 }else{
                  replacement += "<" + pair[p] + ">";
                 }
                }
                replacement += "DTL";
                for(var p = pair.length - 1; p > 1; p--){
                 if(p == 2){
                  replacement += "";
                 }else if(tag == pair[p]) {
                  continue;
                 }else{
                  replacement += "";
                 }
                }
                replace.push("\xFF" + replacements.length);
                replacements.push(replacement);
               }
              }
             }
             text = text.replace(match[1], replace.join(""));
            }
           }
          }
         }


         for(var i=replacements.length; i--;){
          text = text.replace("\xFF" + i, replacements[i]);
         }


         var re = /\b([a-zA-Z_:][a-zA-Z0-9_\-\.:]*)=['"]/g;
         while(match = re.exec(text)){
          var lower = match[1].toLowerCase();
          if(lower == "dtlinstruction"){ continue; }
          if(lower != match[1]){
           this._uppers[lower] = match[1];
          }
          this._attributes[lower] = true;
         }
         var div = document.createElement("div");
         div.innerHTML = text;
         var output = {nodes: []};
         while(div.childNodes.length){
          output.nodes.push(div.removeChild(div.childNodes[0]))
         }


         return output;
    • summary
  • dojox.dtl.dom.getTemplate._commentable

    • summary
  • dojox.dtl.dom.tokenize

    • type
      Function
    • parameters:
      • nodes: (typeof Node)
    • source: [view]
         var tokens = [];


         for(var i = 0, node; node = nodes[i++];){
          if(node.nodeType != 1){
           this.__tokenize(node, tokens);
          }else{
           this._tokenize(node, tokens);
          }
         }


         return tokens;
    • summary
  • dojox.dtl.dom._swallowed

    • summary
  • dojox.dtl.dom._tokenize

    • type
      Function
    • parameters:
      • node: (typeof Node)
      • tokens: (typeof Array)
    • source: [view]
         var first = false;
         var swallowed = this._swallowed;
         var i, j, tag, child;


         if(!tokens.first){
          // Try to efficiently associate tags that use an attribute to
          // remove the node from DOM (eg dojoType) so that we can efficiently
          // locate them later in the tokenizing.
          first = tokens.first = true;
          var tags = dd.register.getAttributeTags();
          for(i = 0; tag = tags[i]; i++){
           try{
            (tag[2])({ swallowNode: function(){ throw 1; }}, new dd.Token(dd.TOKEN_ATTR, ""));
           }catch(e){
            swallowed.push(tag);
           }
          }
         }


         for(i = 0; tag = swallowed[i]; i++){
          var text = node.getAttribute(tag[0]);
          if(text){
           var swallowed = false;
           var custom = (tag[2])({ swallowNode: function(){ swallowed = true; return node; }}, new dd.Token(dd.TOKEN_ATTR, tag[0] + " " + text));
           if(swallowed){
            if(node.parentNode && node.parentNode.removeChild){
             node.parentNode.removeChild(node);
            }
            tokens.push([dd.TOKEN_CUSTOM, custom]);
            return;
           }
          }
         }


         var children = [];
         if(dojo.isIE && node.tagName == "SCRIPT"){
          children.push({
           nodeType: 3,
           data: node.text
          });
          node.text = "";
         }else{
          for(i = 0; child = node.childNodes[i]; i++){
           children.push(child);
          }
         }


         tokens.push([dd.TOKEN_NODE, node]);


         var change = false;
         if(children.length){
          // Only do a change request if we need to
          tokens.push([dd.TOKEN_CHANGE, node]);
          change = true;
         }


         for(var key in this._attributes){
          var clear = false;


          var value = "";
          if(key == "class"){
           value = node.className || value;
          }else if(key == "for"){
           value = node.htmlFor || value;
          }else if(key == "value" && node.value == node.innerHTML){
           // Sometimes .value is set the same as the contents of the item (button)
           continue;
          }else if(node.getAttribute){
           value = node.getAttribute(key, 2) || value;
           if(key == "href" || key == "src"){
            if(dojo.isIE){
             var hash = location.href.lastIndexOf(location.hash);
             var href = location.href.substring(0, hash).split("/");
             href.pop();
             href = href.join("/") + "/";
             if(value.indexOf(href) == 0){
              value = value.replace(href, "");
             }
             value = decodeURIComponent(value);
            }
           }else if(key == "tstyle"){
            clear = key; // Placeholder because we can't use style
            key = "style";
           }else if(dd.BOOLS[key.slice(1)] && dojo.trim(value)){
            key = key.slice(1);
           }else if(this._uppers[key] && dojo.trim(value)){
            clear = this._uppers[key]; // Replaced by lowercase
           }
          }


          if(clear){
           // Clear out values that are different than will
           // be used in plugins
           node.setAttribute(clear, "");
           node.removeAttribute(clear);
          }


          if(typeof value == "function"){
           value = value.toString().replace(this._re4, "$1");
          }


          if(!change){
           // Only do a change request if we need to
           tokens.push([dd.TOKEN_CHANGE, node]);
           change = true;
          }


          // We'll have to resolve attributes during parsing (some ref plugins)


          tokens.push([dd.TOKEN_ATTR, node, key, value]);
         }


         for(i = 0, child; child = children[i]; i++){
          if(child.nodeType == 1){
           var instruction = child.getAttribute("dtlinstruction");
           if(instruction){
            child.parentNode.removeChild(child);
            child = {
             nodeType: 8,
             data: instruction
            };
           }
          }
          this.__tokenize(child, tokens);
         }


         if(!first && node.parentNode && node.parentNode.tagName){
          if(change){
           tokens.push([dd.TOKEN_CHANGE, node, true]);
          }
          tokens.push([dd.TOKEN_CHANGE, node.parentNode]);
          node.parentNode.removeChild(node);
         }else{
          // If this node is parentless, it's a base node, so we have to "up" change to itself
          // and note that it's a top-level to watch for errors
          tokens.push([dd.TOKEN_CHANGE, node, true, true]);
         }
    • summary
  • dojox.dtl.dom.__tokenize

    • type
      Function
    • parameters:
      • child: (typeof )
      • tokens: (typeof )
    • source: [view]
         var data = child.data;
         switch(child.nodeType){
          case 1:
           this._tokenize(child, tokens);
           return;
          case 3:
           if(data.match(/[^\s\n]/) && (data.indexOf("{{") != -1 || data.indexOf("{%") != -1)){
            var texts = ddt.tokenize(data);
            for(var j = 0, text; text = texts[j]; j++){
             if(typeof text == "string"){
              tokens.push([dd.TOKEN_TEXT, text]);
             }else{
              tokens.push(text);
             }
            }
           }else{
            tokens.push([child.nodeType, child]);
           }
           if(child.parentNode) child.parentNode.removeChild(child);
           return;
          case 8:
           if(data.indexOf("{%") == 0){
            var text = dojo.trim(data.slice(2, -2));
            if(text.substr(0, 5) == "load "){
             var parts = dojo.trim(text).split(/\s+/g);
             for(var i = 1, part; part = parts[i]; i++){
              dojo["require"](part);
             }
            }
            tokens.push([dd.TOKEN_BLOCK, text]);
           }
           if(data.indexOf("{{") == 0){
            tokens.push([dd.TOKEN_VAR, dojo.trim(data.slice(2, -2))]);
           }
           if(child.parentNode) child.parentNode.removeChild(child);
           return;
         }
    • summary
  • dojox.dtl.dom

    • type
      Object
    • summary
  • dojox.dtl.DomTemplate.tokens

    • summary
  • dojox.dtl.DomTemplate.nodelist

    • summary
  • dojox.dtl.DomTemplate._count

    • summary
  • dojox.dtl.DomTemplate._re

    • summary
  • dojox.dtl.DomTemplate.setClass

    • type
      Function
    • parameters:
      • str: (typeof )
    • source: [view]
         this.getRootNode().className = str;
    • summary
  • dojox.dtl.DomTemplate.getRootNode

    • type
      Function
    • source: [view]
         return this.buffer.rootNode;
    • summary
  • dojox.dtl.DomTemplate.getBuffer

    • type
      Function
    • source: [view]
         return new dd.DomBuffer();
    • summary
  • dojox.dtl.DomTemplate.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         buffer = this.buffer = buffer || this.getBuffer();
         this.rootNode = null;
         var output = this.nodelist.render(context || new dd.Context({}), buffer);
         for(var i = 0, node; node = buffer._cache[i]; i++){
          if(node._cache){
           node._cache.length = 0;
          }
         }
         return output;
    • summary
  • dojox.dtl.DomTemplate.buffer

    • summary
  • dojox.dtl.DomTemplate.rootNode

    • summary
  • dojox.dtl.DomTemplate.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         return this.nodelist.unrender(context, buffer);
    • summary
  • dojox.dtl.DomBuffer._parent

    • summary
  • dojox.dtl.DomBuffer._cache

    • summary
  • dojox.dtl.DomBuffer.concat

    • type
      Function
    • parameters:
      • node: (typeof DOMNode)
    • source: [view]
         var parent = this._parent;
         if(parent && node.parentNode && node.parentNode === parent && !parent._dirty){
          return this;
         }


         if(node.nodeType == 1 && !this.rootNode){
          this.rootNode = node || true;
          return this;
         }


         if(!parent){
          if(node.nodeType == 3 && dojo.trim(node.data)){
           throw new Error("Text should not exist outside of the root node in template");
          }
          return this;
         }
         if(this._closed){
          if(node.nodeType == 3 && !dojo.trim(node.data)){
           return this;
          }else{
           throw new Error("Content should not exist outside of the root node in template");
          }
         }
         if(parent._dirty){
          if(node._drawn && node.parentNode == parent){
           var caches = parent._cache;
           if(caches){
            for(var i = 0, cache; cache = caches[i]; i++){
             this.onAddNode && this.onAddNode(cache);
             parent.insertBefore(cache, node);
             this.onAddNodeComplete && this.onAddNodeComplete(cache);
            }
            caches.length = 0;
           }
          }
          parent._dirty = false;
         }
         if(!parent._cache){
          parent._cache = [];
          this._cache.push(parent);
         }
         parent._dirty = true;
         parent._cache.push(node);
         return this;
    • summary
  • dojox.dtl.DomBuffer.rootNode

    • summary
  • dojox.dtl.DomBuffer.remove

    • type
      Function
    • parameters:
      • obj: (typeof )
    • source: [view]
         if(typeof obj == "string"){
          if(this._parent){
           this._parent.removeAttribute(obj);
          }
         }else{
          if(obj.nodeType == 1 && !this.getRootNode() && !this._removed){
           this._removed = true;
           return this;
          }
          if(obj.parentNode){
           this.onRemoveNode && this.onRemoveNode(obj);
           if(obj.parentNode){
            obj.parentNode.removeChild(obj);
           }
          }
         }
         return this;
    • summary
  • dojox.dtl.DomBuffer._removed

    • summary
  • dojox.dtl.DomBuffer.setAttribute

    • type
      Function
    • parameters:
      • key: (typeof )
      • value: (typeof )
    • source: [view]
         var old = dojo.attr(this._parent, key);
         if(this.onChangeAttribute && old != value){
          this.onChangeAttribute(this._parent, key, old, value);
         }
         if(key == "style"){
          //console.log(value);
          this._parent.style.cssText = value;
         }else{
          dojo.attr(this._parent, key, value);
          //console.log(this._parent, key, value);
         }
         return this;
    • summary
  • dojox.dtl.DomBuffer._parent.style.cssText

    • summary
  • dojox.dtl.DomBuffer.addEvent

    • type
      Function
    • parameters:
      • context: (typeof )
      • type: (typeof )
      • fn: (typeof )
      • args: (typeof Array|Function)
    • source: [view]
         if(!context.getThis()){ throw new Error("You must use Context.setObject(instance)"); }
         this.onAddEvent && this.onAddEvent(this.getParent(), type, fn);
         var resolved = fn;
         if(dojo.isArray(args)){
          resolved = function(e){
           this[fn].apply(this, [e].concat(args));
          }
         }
         return dojo.connect(this.getParent(), type, context.getThis(), resolved);
    • summary
  • dojox.dtl.DomBuffer.setParent

    • type
      Function
    • parameters:
      • node: (typeof )
      • up: (typeof Boolean)
      • root: (typeof Boolean)
    • source: [view]
         if(!this._parent) this._parent = this._first = node;


         if(up && root && node === this._first){
          this._closed = true;
         }


         if(up){
          var parent = this._parent;
          var script = "";
          var ie = dojo.isIE && parent.tagName == "SCRIPT";
          if(ie){
           parent.text = "";
          }
          if(parent._dirty){
           var caches = parent._cache;
           var select = (parent.tagName == "SELECT" && !parent.options.length);
           for(var i = 0, cache; cache = caches[i]; i++){
            if(cache !== parent){
             this.onAddNode && this.onAddNode(cache);
             if(ie){
              script += cache.data;
             }else{
              parent.appendChild(cache);
              if(select && cache.defaultSelected && i){
               select = i;
              }
             }
             this.onAddNodeComplete && this.onAddNodeComplete(cache);
            }
           }
           if(select){
            parent.options.selectedIndex = (typeof select == "number") ? select : 0;
           }
           caches.length = 0;
           parent._dirty = false;
          }
          if(ie){
           parent.text = script;
          }
         }


         this._parent = node;
         this.onSetParent && this.onSetParent(node, up, root);
         return this;
    • summary
  • dojox.dtl.DomBuffer._closed

    • summary
  • dojox.dtl.DomBuffer.getParent

    • type
      Function
    • source: [view]
         return this._parent;
    • summary
  • dojox.dtl.DomBuffer.getRootNode

    • type
      Function
    • source: [view]
         return this.rootNode;
    • summary
  • dojox.dtl.DomBuffer.onSetParent

    • type
      Function
    • parameters:
      • node: (typeof )
      • up: (typeof )
    • source: [view]
         // summary: Stub called when setParent is used.
    • summary
      Stub called when setParent is used.
  • dojox.dtl.DomBuffer.onAddNode

    • type
      Function
    • parameters:
      • node: (typeof )
    • source: [view]
         // summary: Stub called before new nodes are added
    • summary
      Stub called before new nodes are added
  • dojox.dtl.DomBuffer.onAddNodeComplete

    • type
      Function
    • parameters:
      • node: (typeof )
    • source: [view]
         // summary: Stub called after new nodes are added
    • summary
      Stub called after new nodes are added
  • dojox.dtl.DomBuffer.onRemoveNode

    • type
      Function
    • parameters:
      • node: (typeof )
    • source: [view]
         // summary: Stub called when nodes are removed
    • summary
      Stub called when nodes are removed
  • dojox.dtl.DomBuffer.onChangeAttribute

    • type
      Function
    • parameters:
      • node: (typeof )
      • attribute: (typeof )
      • old: (typeof )
      • updated: (typeof )
    • source: [view]
         // summary: Stub called when an attribute is changed
    • summary
      Stub called when an attribute is changed
  • dojox.dtl.DomBuffer.onChangeData

    • type
      Function
    • parameters:
      • node: (typeof )
      • old: (typeof )
      • updated: (typeof )
    • source: [view]
         // summary: Stub called when a data in a node is changed
    • summary
      Stub called when a data in a node is changed
  • dojox.dtl.DomBuffer.onClone

    • type
      Function
    • parameters:
      • from: (typeof DOMNode)
      • to: (typeof DOMNode)
    • source: [view]
         // summary: Stub called when a node is duplicated
         // from: DOMNode
         // to: DOMNode
    • summary
      Stub called when a node is duplicated
  • dojox.dtl.DomBuffer.onAddEvent

    • type
      Function
    • parameters:
      • node: (typeof DOMNode)
      • type: (typeof String)
      • description: (typeof String)
    • source: [view]
         // summary: Stub to call when you're adding an event
         // node: DOMNode
         // type: String
         // description: String
    • summary
      Stub to call when you're adding an event
    • description
      String
  • dojox.dtl._DomNode.contents

    • summary
  • dojox.dtl._DomNode.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         this._rendered = true;
         return buffer.concat(this.contents);
    • summary
  • dojox.dtl._DomNode._rendered

    • summary
  • dojox.dtl._DomNode.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         if(!this._rendered){
          return buffer;
         }
         this._rendered = false;
         return buffer.remove(this.contents);
    • summary
  • dojox.dtl._DomNode.clone

    • type
      Function
    • parameters:
      • buffer: (typeof )
    • source: [view]
         return new this.constructor(this.contents);
    • summary
  • dojox.dtl._DomNodeList.contents

    • summary
  • dojox.dtl._DomNodeList.push

    • type
      Function
    • parameters:
      • node: (typeof )
    • source: [view]
         this.contents.push(node);
    • summary
  • dojox.dtl._DomNodeList.unshift

    • type
      Function
    • parameters:
      • node: (typeof )
    • source: [view]
         this.contents.unshift(node);
    • summary
  • dojox.dtl._DomNodeList.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
      • instance: (typeof Node)
    • source: [view]
         buffer = buffer || dd.DomTemplate.prototype.getBuffer();


         if(instance){
          var parent = buffer.getParent();
         }
         for(var i = 0; i < this.contents.length; i++){
          buffer = this.contents[i].render(context, buffer);
          if(!buffer) throw new Error("Template node render functions must return their buffer");
         }
         if(parent){
          buffer.setParent(parent);
         }
         return buffer;
    • summary
  • dojox.dtl._DomNodeList.dummyRender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
      • asNode: (typeof )
    • source: [view]
         var div = document.createElement("div");


         var parent = buffer.getParent();
         var old = parent._clone;
         // Tell the clone system to attach itself to our new div
         parent._clone = div;
         var nodelist = this.clone(buffer, div);
         if(old){
          // Restore state if there was a previous clone
          parent._clone = old;
         }else{
          // Remove if there was no clone
          parent._clone = null;
         }


         buffer = dd.DomTemplate.prototype.getBuffer();
         nodelist.unshift(new dd.ChangeNode(div));
         nodelist.unshift(new dd._DomNode(div));
         nodelist.push(new dd.ChangeNode(div, true));
         nodelist.render(context, buffer);


         if(asNode){
          return buffer.getRootNode();
         }


         var html = div.innerHTML;
         return (dojo.isIE) ? html.replace(/\s*_(dirty|clone)="[^"]*"/g, "") : html;
    • summary
      A really expensive way of checking to see how a rendering will look.
      Used in the ifchanged tag
  • dojox.dtl._DomNodeList.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
      • instance: (typeof )
    • source: [view]
         if(instance){
          var parent = buffer.getParent();
         }
         for(var i = 0; i < this.contents.length; i++){
          buffer = this.contents[i].unrender(context, buffer);
          if(!buffer) throw new Error("Template node render functions must return their buffer");
         }
         if(parent){
          buffer.setParent(parent);
         }
         return buffer;
    • summary
  • dojox.dtl._DomNodeList.clone

    • type
      Function
    • parameters:
      • buffer: (typeof )
    • source: [view]
         var parent = buffer.getParent();
         var contents = this.contents;
         var nodelist = new dd._DomNodeList();
         var cloned = [];
         for(var i = 0; i < contents.length; i++){
          var clone = contents[i].clone(buffer);
          if(clone instanceof dd.ChangeNode || clone instanceof dd._DomNode){
           var item = clone.contents._clone;
           if(item){
            clone.contents = item;
           }else if(parent != clone.contents && clone instanceof dd._DomNode){
            var node = clone.contents;
            clone.contents = clone.contents.cloneNode(false);
            buffer.onClone && buffer.onClone(node, clone.contents);
            cloned.push(node);
            node._clone = clone.contents;
           }
          }
          nodelist.push(clone);
         }


         for(var i = 0, clone; clone = cloned[i]; i++){
          clone._clone = null;
         }


         return nodelist;
    • summary
      Used to create an identical copy of a NodeList, useful for things like the for tag.
  • dojox.dtl._DomNodeList.rtrim

    • type
      Function
    • source: [view]
         while(1){
          var i = this.contents.length - 1;
          if(this.contents[i] instanceof dd._DomTextNode && this.contents[i].isEmpty()){
           this.contents.pop();
          }else{
           break;
          }
         }


         return this;
    • summary
  • dojox.dtl._DomVarNode.contents

    • summary
  • dojox.dtl._DomVarNode.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         var str = this.contents.resolve(context);


         // What type of rendering?
         var type = "text";
         if(str){
          if(str.render && str.getRootNode){
           type = "injection";
          }else if(str.safe){
           if(str.nodeType){
            type = "node";
           }else if(str.toString){
            str = str.toString();
            type = "html";
           }
          }
         }


         // Has the typed changed?
         if(this._type && type != this._type){
          this.unrender(context, buffer);
         }
         this._type = type;


         // Now render
         switch(type){
         case "text":
          this._rendered = true;
          this._txt = this._txt || document.createTextNode(str);
          if(this._txt.data != str){
           var old = this._txt.data;
           this._txt.data = str;
           buffer.onChangeData && buffer.onChangeData(this._txt, old, this._txt.data);
          }
          return buffer.concat(this._txt);
         case "injection":
          var root = str.getRootNode();


          if(this._rendered && root != this._root){
           buffer = this.unrender(context, buffer);
          }
          this._root = root;


          var injected = this._injected = new dd._DomNodeList();
          injected.push(new dd.ChangeNode(buffer.getParent()));
          injected.push(new dd._DomNode(root));
          injected.push(str);
          injected.push(new dd.ChangeNode(buffer.getParent()));
          this._rendered = true;


          return injected.render(context, buffer);
         case "node":
          this._rendered = true;
          if(this._node && this._node != str && this._node.parentNode && this._node.parentNode === buffer.getParent()){
           this._node.parentNode.removeChild(this._node);
          }
          this._node = str;
          return buffer.concat(str);
         case "html":
          if(this._rendered && this._src != str){
           buffer = this.unrender(context, buffer);
          }
          this._src = str;


          // This can get reset in the above tag
          if(!this._rendered){
           this._rendered = true;
           this._html = this._html || [];
           var div = (this._div = this._div || document.createElement("div"));
           div.innerHTML = str;
           var children = div.childNodes;
           while(children.length){
            var removed = div.removeChild(children[0]);
            this._html.push(removed);
            buffer = buffer.concat(removed);
           }
          }


          return buffer;
         default:
          return buffer;
         }
    • summary
  • dojox.dtl._DomVarNode._type

    • summary
  • dojox.dtl._DomVarNode._rendered

    • summary
  • dojox.dtl._DomVarNode._txt

    • summary
  • dojox.dtl._DomVarNode._txt.data

    • summary
  • dojox.dtl._DomVarNode._root

    • summary
  • dojox.dtl._DomVarNode._injected

    • summary
  • dojox.dtl._DomVarNode._node.parentNode

    • summary
  • dojox.dtl._DomVarNode._node

    • summary
  • dojox.dtl._DomVarNode._src

    • summary
  • dojox.dtl._DomVarNode._html

    • summary
  • dojox.dtl._DomVarNode._div

    • summary
  • dojox.dtl._DomVarNode.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         if(!this._rendered){
          return buffer;
         }
         this._rendered = false;


         // Unrender injected nodes
         switch(this._type){
         case "text":
          return buffer.remove(this._txt);
         case "injection":
          return this._injection.unrender(context, buffer);
         case "node":
          if(this._node.parentNode === buffer.getParent()){
           return buffer.remove(this._node);
          }
          return buffer;
         case "html":
          for(var i=0, l=this._html.length; i     buffer = buffer.remove(this._html[i]);
          }
          return buffer;
         default:
          return buffer;
         }
    • summary
  • dojox.dtl._DomVarNode.clone

    • type
      Function
    • source: [view]
         return new this.constructor(this.contents.getExpression());
    • summary
  • dojox.dtl.ChangeNode.contents

    • summary
  • dojox.dtl.ChangeNode.up

    • summary
  • dojox.dtl.ChangeNode.root

    • summary
  • dojox.dtl.ChangeNode.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         return buffer.setParent(this.contents, this.up, this.root);
    • summary
  • dojox.dtl.ChangeNode.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         if(!buffer.getParent()){
          return buffer;
         }
         return buffer.setParent(this.contents);
    • summary
  • dojox.dtl.ChangeNode.clone

    • type
      Function
    • source: [view]
         return new this.constructor(this.contents, this.up, this.root);
    • summary
  • dojox.dtl.AttributeNode.key

    • summary
  • dojox.dtl.AttributeNode.value

    • summary
  • dojox.dtl.AttributeNode.contents

    • summary
  • dojox.dtl.AttributeNode.nodelist

    • summary
  • dojox.dtl.AttributeNode._pool

    • type
      Object
    • summary
  • dojox.dtl.AttributeNode.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         var key = this.key;
         var value = this.nodelist.dummyRender(context);
         if(dd.BOOLS[key]){
          value = !(value == "false" || value == "undefined" || !value);
         }
         if(value !== this.contents){
          this.contents = value;
          return buffer.setAttribute(key, value);
         }
         return buffer;
    • summary
  • dojox.dtl.AttributeNode.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         this.contents = "";
         return buffer.remove(this.key);
    • summary
  • dojox.dtl.AttributeNode.clone

    • type
      Function
    • parameters:
      • buffer: (typeof )
    • source: [view]
         return new this.constructor(this.key, this.value);
    • summary
  • dojox.dtl._DomTextNode.contents

    • summary
  • dojox.dtl._DomTextNode.upcoming

    • summary
  • dojox.dtl._DomTextNode.set

    • type
      Function
    • parameters:
      • data: (typeof )
    • source: [view]
         this.upcoming = data;
         return this;
    • summary
  • dojox.dtl._DomTextNode.render

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         if(this.contents.data != this.upcoming){
          var old = this.contents.data;
          this.contents.data = this.upcoming;
          buffer.onChangeData && buffer.onChangeData(this.contents, old, this.upcoming);
         }
         return buffer.concat(this.contents);
    • summary
  • dojox.dtl._DomTextNode.contents.data

    • summary
  • dojox.dtl._DomTextNode.unrender

    • type
      Function
    • parameters:
      • context: (typeof )
      • buffer: (typeof )
    • source: [view]
         return buffer.remove(this.contents);
    • summary
  • dojox.dtl._DomTextNode.isEmpty

    • type
      Function
    • source: [view]
         return !dojo.trim(this.contents.data);
    • summary
  • dojox.dtl._DomTextNode.clone

    • type
      Function
    • source: [view]
         return new this.constructor(this.contents.data);
    • summary
  • dojox.dtl._DomParser.contents

    • summary
  • dojox.dtl._DomParser.i

    • summary
  • dojox.dtl._DomParser.parse

    • type
      Function
    • parameters:
      • stop_at: (typeof Array)
    • source: [view]
         var terminators = {};
         var tokens = this.contents;
         if(!stop_at){
          stop_at = [];
         }
         for(var i = 0; i < stop_at.length; i++){
          terminators[stop_at[i]] = true;
         }
         var nodelist = new dd._DomNodeList();
         while(this.i < tokens.length){
          var token = tokens[this.i++];
          var type = token[0];
          var value = token[1];
          if(type == dd.TOKEN_CUSTOM){
           nodelist.push(value);
          }else if(type == dd.TOKEN_CHANGE){
           var changeNode = new dd.ChangeNode(value, token[2], token[3]);
           value[changeNode.attr] = changeNode;
           nodelist.push(changeNode);
          }else if(type == dd.TOKEN_ATTR){
           var fn = ddt.getTag("attr:" + token[2], true);
           if(fn && token[3]){
            if (token[3].indexOf("{%") != -1 || token[3].indexOf("{{") != -1) {
             value.setAttribute(token[2], "");
            }
            nodelist.push(fn(null, new dd.Token(type, token[2] + " " + token[3])));
           }else if(dojo.isString(token[3])){
            if(token[2] == "style" || token[3].indexOf("{%") != -1 || token[3].indexOf("{{") != -1){
             nodelist.push(new dd.AttributeNode(token[2], token[3]));
            }else if(dojo.trim(token[3])){
             try{
              dojo.attr(value, token[2], token[3]);
             }catch(e){}
            }
           }
          }else if(type == dd.TOKEN_NODE){
           var fn = ddt.getTag("node:" + value.tagName.toLowerCase(), true);
           if(fn){
            // TODO: We need to move this to tokenization so that it's before the
            //     node and the parser can be passed here instead of null
            nodelist.push(fn(null, new dd.Token(type, value), value.tagName.toLowerCase()));
           }
           nodelist.push(new dd._DomNode(value));
          }else if(type == dd.TOKEN_VAR){
           nodelist.push(new dd._DomVarNode(value));
          }else if(type == dd.TOKEN_TEXT){
           nodelist.push(new dd._DomTextNode(value.data || value));
          }else if(type == dd.TOKEN_BLOCK){
           if(terminators[value]){
            --this.i;
            return nodelist;
           }
           var cmd = value.split(/\s+/g);
           if(cmd.length){
            cmd = cmd[0];
            var fn = ddt.getTag(cmd);
            if(typeof fn != "function"){
             throw new Error("Function not found for " + cmd);
            }
            var tpl = fn(this, new dd.Token(type, value));
            if(tpl){
             nodelist.push(tpl);
            }
           }
          }
         }


         if(stop_at.length){
          throw new Error("Could not find closing tag(s): " + stop_at.toString());
         }


         return nodelist;
    • summary
  • dojox.dtl._DomParser.next_token

    • type
      Function
    • source: [view]
         var token = this.contents[this.i++];
         return new dd.Token(token[0], token[1]);
    • summary
      Returns the next token in the list.
  • dojox.dtl._DomParser.delete_first_token

    • type
      Function
    • source: [view]
         this.i++;
    • summary
  • dojox.dtl._DomParser.skip_past

    • type
      Function
    • parameters:
      • endtag: (typeof )
    • source: [view]
         return dd._Parser.prototype.skip_past.call(this, endtag);
    • chains:
      • dd._Parser.prototype.skip_past: (call)
    • summary
  • dojox.dtl._DomParser.create_variable_node

    • type
      Function
    • parameters:
      • expr: (typeof )
    • source: [view]
         return new dd._DomVarNode(expr);
    • summary
  • dojox.dtl._DomParser.create_text_node

    • type
      Function
    • parameters:
      • expr: (typeof )
    • source: [view]
         return new dd._DomTextNode(expr || "");
    • summary
  • dojox.dtl._DomParser.getTemplate

    • type
      Function
    • parameters:
      • loc: (typeof String)
    • source: [view]
         return new dd.DomTemplate(ddh.getTemplate(loc));
    • summary
  • dojox.dtl

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary