summaryrefslogtreecommitdiff
path: root/lib/dojo/html.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/html.js')
-rw-r--r--lib/dojo/html.js101
1 files changed, 60 insertions, 41 deletions
diff --git a/lib/dojo/html.js b/lib/dojo/html.js
index ec5c4986e..f88f899cc 100644
--- a/lib/dojo/html.js
+++ b/lib/dojo/html.js
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
@@ -8,25 +8,26 @@
if(!dojo._hasResource["dojo.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojo.html"] = true;
dojo.provide("dojo.html");
+dojo.require("dojo.parser");
-// the parser might be needed..
-dojo.require("dojo.parser");
+dojo.getObject("html", true, dojo);
+// the parser might be needed..
(function(){ // private scope, sort of a namespace
// idCounter is incremented with each instantiation to allow asignment of a unique id for tracking, logging purposes
- var idCounter = 0,
+ var idCounter = 0,
d = dojo;
dojo.html._secureForInnerHtml = function(/*String*/ cont){
// summary:
// removes !DOCTYPE and title elements from the html string.
- //
+ //
// khtml is picky about dom faults, you can't attach a style or <title> node as child of body
// must go into head, so we need to cut out those tags
// cont:
// An html string for insertion into the dom
- //
+ //
return cont.replace(/(?:\s*<!DOCTYPE\s[^>]+>|<title[^>]*>[\s\S]*?<\/title>)/ig, ""); // String
};
@@ -46,7 +47,7 @@ dojo.require("dojo.parser");
// node:
// the parent element
// content:
- // the content to be set on the parent element.
+ // the content to be set on the parent element.
// This can be an html string, a node reference or a NodeList, dojo.NodeList, Array or other enumerable list of nodes
// always empty
@@ -72,7 +73,7 @@ dojo.require("dojo.parser");
};
// we wrap up the content-setting operation in a object
- dojo.declare("dojo.html._ContentSetter", null,
+ dojo.declare("dojo.html._ContentSetter", null,
{
// node: DomNode|String
// An node which will be the parent element that we set content into
@@ -83,11 +84,11 @@ dojo.require("dojo.parser");
content: "",
// id: String?
- // Usually only used internally, and auto-generated with each instance
+ // Usually only used internally, and auto-generated with each instance
id: "",
// cleanContent: Boolean
- // Should the content be treated as a full html document,
+ // Should the content be treated as a full html document,
// and the real content stripped of <html>, <body> wrapper before injection
cleanContent: false,
@@ -98,6 +99,17 @@ dojo.require("dojo.parser");
// parseContent: Boolean
// Should the node by passed to the parser after the new content is set
parseContent: false,
+
+ // parserScope: String
+ // Flag passed to parser. Root for attribute names to search for. If scopeName is dojo,
+ // will search for data-dojo-type (or dojoType). For backwards compatibility
+ // reasons defaults to dojo._scopeName (which is "dojo" except when
+ // multi-version support is used, when it will be something like dojo16, dojo20, etc.)
+ parserScope: dojo._scopeName,
+
+ // startup: Boolean
+ // Start the child widgets after parsing them. Only obeyed if parseContent is true.
+ startup: true,
// lifecyle methods
constructor: function(/* Object */params, /* String|DomNode */node){
@@ -115,14 +127,14 @@ dojo.require("dojo.parser");
if(!this.id){
this.id = [
"Setter",
- (node) ? node.id || node.tagName : "",
+ (node) ? node.id || node.tagName : "",
idCounter++
].join("_");
}
},
set: function(/* String|DomNode|NodeList? */ cont, /* Object? */ params){
// summary:
- // front-end to the set-content sequence
+ // front-end to the set-content sequence
// cont:
// An html string, node or enumerable list of nodes for insertion into the dom
// If not provided, the object's content property will be used
@@ -142,9 +154,9 @@ dojo.require("dojo.parser");
},
setContent: function(){
// summary:
- // sets the content on the node
+ // sets the content on the node
- var node = this.node;
+ var node = this.node;
if(!node) {
// can't proceed
throw new Error(this.declaredClass + ": setContent given no node");
@@ -156,7 +168,7 @@ dojo.require("dojo.parser");
// like for instance if domNode is a UL and we try append a DIV
// FIXME: need to allow the user to provide a content error message string
- var errMess = this.onContentError(e);
+ var errMess = this.onContentError(e);
try{
node.innerHTML = errMess;
}catch(e){
@@ -172,7 +184,7 @@ dojo.require("dojo.parser");
// cleanly empty out existing content
// destroy any widgets from a previous run
- // NOTE: if you dont want this you'll need to empty
+ // NOTE: if you dont want this you'll need to empty
// the parseResults array property yourself to avoid bad things happenning
if(this.parseResults && this.parseResults.length) {
dojo.forEach(this.parseResults, function(w) {
@@ -182,17 +194,17 @@ dojo.require("dojo.parser");
});
delete this.parseResults;
}
- // this is fast, but if you know its already empty or safe, you could
+ // this is fast, but if you know its already empty or safe, you could
// override empty to skip this step
dojo.html._emptyNode(this.node);
},
onBegin: function(){
// summary
- // Called after instantiation, but before set();
- // It allows modification of any of the object properties
+ // Called after instantiation, but before set();
+ // It allows modification of any of the object properties
// - including the node and content provided - before the set operation actually takes place
- // This default implementation checks for cleanContent and extractContent flags to
+ // This default implementation checks for cleanContent and extractContent flags to
// optionally pre-process html string content
var cont = this.content;
@@ -230,21 +242,21 @@ dojo.require("dojo.parser");
// summary
// manually reset the Setter instance if its being re-used for example for another set()
// description
- // tearDown() is not called automatically.
+ // tearDown() is not called automatically.
// In normal use, the Setter instance properties are simply allowed to fall out of scope
// but the tearDown method can be called to explicitly reset this instance.
- delete this.parseResults;
- delete this.node;
- delete this.content;
+ delete this.parseResults;
+ delete this.node;
+ delete this.content;
},
onContentError: function(err){
- return "Error occured setting content: " + err;
+ return "Error occured setting content: " + err;
},
_mixin: function(params){
// mix properties/methods into the instance
- // TODO: the intention with tearDown is to put the Setter's state
+ // TODO: the intention with tearDown is to put the Setter's state
// back to that of the original constructor (vs. deleting/resetting everything regardless of ctor params)
// so we could do something here to move the original properties aside for later restoration
var empty = {}, key;
@@ -252,21 +264,28 @@ dojo.require("dojo.parser");
if(key in empty){ continue; }
// TODO: here's our opportunity to mask the properties we dont consider configurable/overridable
// .. but history shows we'll almost always guess wrong
- this[key] = params[key];
+ this[key] = params[key];
}
},
_parse: function(){
- // summary:
+ // summary:
// runs the dojo parser over the node contents, storing any results in this.parseResults
// Any errors resulting from parsing are passed to _onError for handling
var rootNode = this.node;
try{
// store the results (widgets, whatever) for potential retrieval
+ var inherited = {};
+ dojo.forEach(["dir", "lang", "textDir"], function(name){
+ if(this[name]){
+ inherited[name] = this[name];
+ }
+ }, this);
this.parseResults = dojo.parser.parse({
rootNode: rootNode,
- dir: this.dir,
- lang: this.lang
+ noStart: !this.startup,
+ inherited: inherited,
+ scope: this.parserScope
});
}catch(e){
this._onError('Content', e, "Error parsing in _ContentSetter#"+this.id);
@@ -299,29 +318,29 @@ dojo.require("dojo.parser");
// node:
// the parent element that will receive the content
// cont:
- // the content to be set on the parent element.
+ // the content to be set on the parent element.
// This can be an html string, a node reference or a NodeList, dojo.NodeList, Array or other enumerable list of nodes
- // params:
+ // params:
// Optional flags/properties to configure the content-setting. See dojo.html._ContentSetter
// example:
// A safe string/node/nodelist content replacement/injection with hooks for extension
- // Example Usage:
- // dojo.html.set(node, "some string");
- // dojo.html.set(node, contentNode, {options});
- // dojo.html.set(node, myNode.childNodes, {options});
+ // Example Usage:
+ // dojo.html.set(node, "some string");
+ // dojo.html.set(node, contentNode, {options});
+ // dojo.html.set(node, myNode.childNodes, {options});
if(undefined == cont){
console.warn("dojo.html.set: no cont argument provided, using empty string");
cont = "";
- }
+ }
if(!params){
// simple and fast
return dojo.html._setNodeContent(node, cont, true);
- }else{
+ }else{
// more options but slower
// note the arguments are reversed in order, to match the convention for instantiation via the parser
- var op = new dojo.html._ContentSetter(dojo.mixin(
- params,
- { content: cont, node: node }
+ var op = new dojo.html._ContentSetter(dojo.mixin(
+ params,
+ { content: cont, node: node }
));
return op.set();
}