summaryrefslogtreecommitdiff
path: root/lib/dojo/html.js
blob: 7c15e5812cb6e13a6659dfd3ebde67fb52d88eb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
	Copyright (c) 2004-2010, 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
*/


if(!dojo._hasResource["dojo.html"]){
dojo._hasResource["dojo.html"]=true;
dojo.provide("dojo.html");
dojo.require("dojo.parser");
(function(){
var _1=0,d=dojo;
dojo.html._secureForInnerHtml=function(_2){
return _2.replace(/(?:\s*<!DOCTYPE\s[^>]+>|<title[^>]*>[\s\S]*?<\/title>)/ig,"");
};
dojo.html._emptyNode=dojo.empty;
dojo.html._setNodeContent=function(_3,_4){
d.empty(_3);
if(_4){
if(typeof _4=="string"){
_4=d._toDom(_4,_3.ownerDocument);
}
if(!_4.nodeType&&d.isArrayLike(_4)){
for(var _5=_4.length,i=0;i<_4.length;i=_5==_4.length?i+1:0){
d.place(_4[i],_3,"last");
}
}else{
d.place(_4,_3,"last");
}
}
return _3;
};
dojo.declare("dojo.html._ContentSetter",null,{node:"",content:"",id:"",cleanContent:false,extractContent:false,parseContent:false,constructor:function(_6,_7){
dojo.mixin(this,_6||{});
_7=this.node=dojo.byId(this.node||_7);
if(!this.id){
this.id=["Setter",(_7)?_7.id||_7.tagName:"",_1++].join("_");
}
},set:function(_8,_9){
if(undefined!==_8){
this.content=_8;
}
if(_9){
this._mixin(_9);
}
this.onBegin();
this.setContent();
this.onEnd();
return this.node;
},setContent:function(){
var _a=this.node;
if(!_a){
throw new Error(this.declaredClass+": setContent given no node");
}
try{
_a=dojo.html._setNodeContent(_a,this.content);
}
catch(e){
var _b=this.onContentError(e);
try{
_a.innerHTML=_b;
}
catch(e){
console.error("Fatal "+this.declaredClass+".setContent could not change content due to "+e.message,e);
}
}
this.node=_a;
},empty:function(){
if(this.parseResults&&this.parseResults.length){
dojo.forEach(this.parseResults,function(w){
if(w.destroy){
w.destroy();
}
});
delete this.parseResults;
}
dojo.html._emptyNode(this.node);
},onBegin:function(){
var _c=this.content;
if(dojo.isString(_c)){
if(this.cleanContent){
_c=dojo.html._secureForInnerHtml(_c);
}
if(this.extractContent){
var _d=_c.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
if(_d){
_c=_d[1];
}
}
}
this.empty();
this.content=_c;
return this.node;
},onEnd:function(){
if(this.parseContent){
this._parse();
}
return this.node;
},tearDown:function(){
delete this.parseResults;
delete this.node;
delete this.content;
},onContentError:function(_e){
return "Error occured setting content: "+_e;
},_mixin:function(_f){
var _10={},key;
for(key in _f){
if(key in _10){
continue;
}
this[key]=_f[key];
}
},_parse:function(){
var _11=this.node;
try{
this.parseResults=dojo.parser.parse({rootNode:_11,dir:this.dir,lang:this.lang});
}
catch(e){
this._onError("Content",e,"Error parsing in _ContentSetter#"+this.id);
}
},_onError:function(_12,err,_13){
var _14=this["on"+_12+"Error"].call(this,err);
if(_13){
console.error(_13,err);
}else{
if(_14){
dojo.html._setNodeContent(this.node,_14,true);
}
}
}});
dojo.html.set=function(_15,_16,_17){
if(undefined==_16){
console.warn("dojo.html.set: no cont argument provided, using empty string");
_16="";
}
if(!_17){
return dojo.html._setNodeContent(_15,_16,true);
}else{
var op=new dojo.html._ContentSetter(dojo.mixin(_17,{content:_16,node:_15}));
return op.set();
}
};
})();
}