dojox.dtl.html._tokenize
dojo.require("dojox.dtl.html");
defined in dojox/dtl/html.js
Usage
var types = this.types; 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; }}, ""); }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; }}, text); if(swallowed){ if(node.parentNode && node.parentNode.removeChild){ node.parentNode.removeChild(node); } tokens.push([types.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([types.elem, node]); var change = false; if(children.length){ // Only do a change request if we need to tokens.push([types.change, node]); change = true; } for(var key in this._attributes){ 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); } if(value.indexOf("{%") != -1 || value.indexOf("{{") != -1){ node.setAttribute(key, ""); } } } if(typeof value == "function"){ value = value.toString().replace(this._re4, "$1"); } if(!change){ // Only do a change request if we need to tokens.push([types.change, node]); change = true; } // We'll have to resolve attributes during parsing tokens.push([types.attr, node, key, value]); } for(i = 0, child; child = children[i]; i++){ if(child.nodeType == 1 && child.getAttribute("iscomment")){ child.parentNode.removeChild(child); child = { nodeType: 8, data: child.innerHTML }; } this.__tokenize(child, tokens); } if(!first && node.parentNode && node.parentNode.tagName){ if(change){ tokens.push([types.change, node, true]); } tokens.push([types.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([types.change, node, true, true]); }
parameter | type | description |
---|---|---|
node | Node | |
tokens | Array |