1
|
/*
|
2
|
Copyright (c) 2004-2008, 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
|
|
7
|
|
8
|
if(!dojo._hasResource["dojo.html"]){
|
9
|
dojo._hasResource["dojo.html"]=true;
|
10
|
dojo.provide("dojo.html");
|
11
|
dojo.require("dojo.parser");
|
12
|
(function(){
|
13
|
var _1=0;
|
14
|
dojo.html._secureForInnerHtml=function(_2){
|
15
|
return _2.replace(/(?:\s*<!DOCTYPE\s[^>]+>|<title[^>]*>[\s\S]*?<\/title>)/ig,"");
|
16
|
};
|
17
|
dojo.html._emptyNode=function(_3){
|
18
|
while(_3.firstChild){
|
19
|
dojo._destroyElement(_3.firstChild);
|
20
|
}
|
21
|
};
|
22
|
dojo.html._setNodeContent=function(_4,_5,_6){
|
23
|
if(_6){
|
24
|
dojo.html._emptyNode(_4);
|
25
|
}
|
26
|
if(typeof _5=="string"){
|
27
|
var _7="",_8="",_9=0,_a=_4.nodeName.toLowerCase();
|
28
|
switch(_a){
|
29
|
case "tr":
|
30
|
_7="<tr>";
|
31
|
_8="</tr>";
|
32
|
_9+=1;
|
33
|
case "tbody":
|
34
|
case "thead":
|
35
|
_7="<tbody>"+_7;
|
36
|
_8+="</tbody>";
|
37
|
_9+=1;
|
38
|
case "table":
|
39
|
_7="<table>"+_7;
|
40
|
_8+="</table>";
|
41
|
_9+=1;
|
42
|
break;
|
43
|
}
|
44
|
if(_9){
|
45
|
var n=_4.ownerDocument.createElement("div");
|
46
|
n.innerHTML=_7+_5+_8;
|
47
|
do{
|
48
|
n=n.firstChild;
|
49
|
}while(--_9);
|
50
|
dojo.forEach(n.childNodes,function(n){
|
51
|
_4.appendChild(n.cloneNode(true));
|
52
|
});
|
53
|
}else{
|
54
|
_4.innerHTML=_5;
|
55
|
}
|
56
|
}else{
|
57
|
if(_5.nodeType){
|
58
|
_4.appendChild(_5);
|
59
|
}else{
|
60
|
dojo.forEach(_5,function(n){
|
61
|
_4.appendChild(n.cloneNode(true));
|
62
|
});
|
63
|
}
|
64
|
}
|
65
|
return _4;
|
66
|
};
|
67
|
dojo.declare("dojo.html._ContentSetter",null,{node:"",content:"",id:"",cleanContent:false,extractContent:false,parseContent:false,constructor:function(_e,_f){
|
68
|
dojo.mixin(this,_e||{});
|
69
|
_f=this.node=dojo.byId(this.node||_f);
|
70
|
if(!this.id){
|
71
|
this.id=["Setter",(_f)?_f.id||_f.tagName:"",_1++].join("_");
|
72
|
}
|
73
|
if(!(this.node||_f)){
|
74
|
new Error(this.declaredClass+": no node provided to "+this.id);
|
75
|
}
|
76
|
},set:function(_10,_11){
|
77
|
if(undefined!==_10){
|
78
|
this.content=_10;
|
79
|
}
|
80
|
if(_11){
|
81
|
this._mixin(_11);
|
82
|
}
|
83
|
this.onBegin();
|
84
|
this.setContent();
|
85
|
this.onEnd();
|
86
|
return this.node;
|
87
|
},setContent:function(){
|
88
|
var _12=this.node;
|
89
|
if(!_12){
|
90
|
console.error("setContent given no node");
|
91
|
}
|
92
|
try{
|
93
|
_12=dojo.html._setNodeContent(_12,this.content);
|
94
|
}
|
95
|
catch(e){
|
96
|
var _13=this.onContentError(e);
|
97
|
try{
|
98
|
_12.innerHTML=_13;
|
99
|
}
|
100
|
catch(e){
|
101
|
console.error("Fatal "+this.declaredClass+".setContent could not change content due to "+e.message,e);
|
102
|
}
|
103
|
}
|
104
|
this.node=_12;
|
105
|
},empty:function(){
|
106
|
if(this.parseResults&&this.parseResults.length){
|
107
|
dojo.forEach(this.parseResults,function(w){
|
108
|
if(w.destroy){
|
109
|
w.destroy();
|
110
|
}
|
111
|
});
|
112
|
delete this.parseResults;
|
113
|
}
|
114
|
dojo.html._emptyNode(this.node);
|
115
|
},onBegin:function(){
|
116
|
var _15=this.content;
|
117
|
if(dojo.isString(_15)){
|
118
|
if(this.cleanContent){
|
119
|
_15=dojo.html._secureForInnerHtml(_15);
|
120
|
}
|
121
|
if(this.extractContent){
|
122
|
var _16=_15.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
|
123
|
if(_16){
|
124
|
_15=_16[1];
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
this.empty();
|
129
|
this.content=_15;
|
130
|
return this.node;
|
131
|
},onEnd:function(){
|
132
|
if(this.parseContent){
|
133
|
this._parse();
|
134
|
}
|
135
|
return this.node;
|
136
|
},tearDown:function(){
|
137
|
delete this.parseResults;
|
138
|
delete this.node;
|
139
|
delete this.content;
|
140
|
},onContentError:function(err){
|
141
|
return "Error occured setting content: "+err;
|
142
|
},_mixin:function(_18){
|
143
|
var _19={},key;
|
144
|
for(key in _18){
|
145
|
if(key in _19){
|
146
|
continue;
|
147
|
}
|
148
|
this[key]=_18[key];
|
149
|
}
|
150
|
},_parse:function(){
|
151
|
var _1b=this.node;
|
152
|
try{
|
153
|
this.parseResults=dojo.parser.parse(_1b,true);
|
154
|
}
|
155
|
catch(e){
|
156
|
this._onError("Content",e,"Error parsing in _ContentSetter#"+this.id);
|
157
|
}
|
158
|
},_onError:function(_1c,err,_1e){
|
159
|
var _1f=this["on"+_1c+"Error"].call(this,err);
|
160
|
if(_1e){
|
161
|
console.error(_1e,err);
|
162
|
}else{
|
163
|
if(_1f){
|
164
|
dojo.html._setNodeContent(this.node,_1f,true);
|
165
|
}
|
166
|
}
|
167
|
}});
|
168
|
dojo.html.set=function(_20,_21,_22){
|
169
|
if(undefined==_21){
|
170
|
console.warn("dojo.html.set: no cont argument provided, using empty string");
|
171
|
_21="";
|
172
|
}
|
173
|
if(!_22){
|
174
|
return dojo.html._setNodeContent(_20,_21,true);
|
175
|
}else{
|
176
|
var op=new dojo.html._ContentSetter(dojo.mixin(_22,{content:_21,node:_20}));
|
177
|
return op.set();
|
178
|
}
|
179
|
};
|
180
|
})();
|
181
|
}
|