Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / html / _base.js @ 12

History | View | Annotate | Download (5.24 KB)

1
/*
2
        Copyright (c) 2004-2010, 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["dojox.html._base"]){
9
dojo._hasResource["dojox.html._base"]=true;
10
dojo.provide("dojox.html._base");
11
dojo.require("dojo.html");
12
(function(){
13
if(dojo.isIE){
14
var _1=/(AlphaImageLoader\([^)]*?src=(['"]))(?![a-z]+:|\/)([^\r\n;}]+?)(\2[^)]*\)\s*[;}]?)/g;
15
}
16
var _2=/(?:(?:@import\s*(['"])(?![a-z]+:|\/)([^\r\n;{]+?)\1)|url\(\s*(['"]?)(?![a-z]+:|\/)([^\r\n;]+?)\3\s*\))([a-z, \s]*[;}]?)/g;
17
var _3=dojox.html._adjustCssPaths=function(_4,_5){
18
if(!_5||!_4){
19
return;
20
}
21
if(_1){
22
_5=_5.replace(_1,function(_6,_7,_8,_9,_a){
23
return _7+(new dojo._Url(_4,"./"+_9).toString())+_a;
24
});
25
}
26
return _5.replace(_2,function(_b,_c,_d,_e,_f,_10){
27
if(_d){
28
return "@import \""+(new dojo._Url(_4,"./"+_d).toString())+"\""+_10;
29
}else{
30
return "url("+(new dojo._Url(_4,"./"+_f).toString())+")"+_10;
31
}
32
});
33
};
34
var _11=/(<[a-z][a-z0-9]*\s[^>]*)(?:(href|src)=(['"]?)([^>]*?)\3|style=(['"]?)([^>]*?)\5)([^>]*>)/gi;
35
var _12=dojox.html._adjustHtmlPaths=function(_13,_14){
36
var url=_13||"./";
37
return _14.replace(_11,function(tag,_15,_16,_17,_18,_19,_1a,end){
38
return _15+(_16?(_16+"="+_17+(new dojo._Url(url,_18).toString())+_17):("style="+_19+_3(url,_1a)+_19))+end;
39
});
40
};
41
var _1b=dojox.html._snarfStyles=function(_1c,_1d,_1e){
42
_1e.attributes=[];
43
return _1d.replace(/(?:<style([^>]*)>([\s\S]*?)<\/style>|<link\s+(?=[^>]*rel=['"]?stylesheet)([^>]*?href=(['"])([^>]*?)\4[^>\/]*)\/?>)/gi,function(_1f,_20,_21,_22,_23,_24){
44
var i,_25=(_20||_22||"").replace(/^\s*([\s\S]*?)\s*$/i,"$1");
45
if(_21){
46
i=_1e.push(_1c?_3(_1c,_21):_21);
47
}else{
48
i=_1e.push("@import \""+_24+"\";");
49
_25=_25.replace(/\s*(?:rel|href)=(['"])?[^\s]*\1\s*/gi,"");
50
}
51
if(_25){
52
_25=_25.split(/\s+/);
53
var _26={},tmp;
54
for(var j=0,e=_25.length;j<e;j++){
55
tmp=_25[j].split("=");
56
_26[tmp[0]]=tmp[1].replace(/^\s*['"]?([\s\S]*?)['"]?\s*$/,"$1");
57
}
58
_1e.attributes[i-1]=_26;
59
}
60
return "";
61
});
62
};
63
var _27=dojox.html._snarfScripts=function(_28,_29){
64
_29.code="";
65
_28=_28.replace(/<[!][-][-](.|\s){5,}?[-][-]>/g,function(_2a){
66
return _2a.replace(/<(\/?)script\b/ig,"&lt;$1Script");
67
});
68
function _2b(src){
69
if(_29.downloadRemote){
70
src=src.replace(/&([a-z0-9#]+);/g,function(m,_2c){
71
switch(_2c){
72
case "amp":
73
return "&";
74
case "gt":
75
return ">";
76
case "lt":
77
return "<";
78
default:
79
return _2c.charAt(0)=="#"?String.fromCharCode(_2c.substring(1)):"&"+_2c+";";
80
}
81
});
82
dojo.xhrGet({url:src,sync:true,load:function(_2d){
83
_29.code+=_2d+";";
84
},error:_29.errBack});
85
}
86
};
87
return _28.replace(/<script\s*(?![^>]*type=['"]?(?:dojo\/|text\/html\b))(?:[^>]*?(?:src=(['"]?)([^>]*?)\1[^>]*)?)*>([\s\S]*?)<\/script>/gi,function(_2e,_2f,src,_30){
88
if(src){
89
_2b(src);
90
}else{
91
_29.code+=_30;
92
}
93
return "";
94
});
95
};
96
var _31=dojox.html.evalInGlobal=function(_32,_33){
97
_33=_33||dojo.doc.body;
98
var n=_33.ownerDocument.createElement("script");
99
n.type="text/javascript";
100
_33.appendChild(n);
101
n.text=_32;
102
};
103
dojo.declare("dojox.html._ContentSetter",[dojo.html._ContentSetter],{adjustPaths:false,referencePath:".",renderStyles:false,executeScripts:false,scriptHasHooks:false,scriptHookReplacement:null,_renderStyles:function(_34){
104
this._styleNodes=[];
105
var st,att,_35,doc=this.node.ownerDocument;
106
var _36=doc.getElementsByTagName("head")[0];
107
for(var i=0,e=_34.length;i<e;i++){
108
_35=_34[i];
109
att=_34.attributes[i];
110
st=doc.createElement("style");
111
st.setAttribute("type","text/css");
112
for(var x in att){
113
st.setAttribute(x,att[x]);
114
}
115
this._styleNodes.push(st);
116
_36.appendChild(st);
117
if(st.styleSheet){
118
st.styleSheet.cssText=_35;
119
}else{
120
st.appendChild(doc.createTextNode(_35));
121
}
122
}
123
},empty:function(){
124
this.inherited("empty",arguments);
125
this._styles=[];
126
},onBegin:function(){
127
this.inherited("onBegin",arguments);
128
var _37=this.content,_38=this.node;
129
var _39=this._styles;
130
if(dojo.isString(_37)){
131
if(this.adjustPaths&&this.referencePath){
132
_37=_12(this.referencePath,_37);
133
}
134
if(this.renderStyles||this.cleanContent){
135
_37=_1b(this.referencePath,_37,_39);
136
}
137
if(this.executeScripts){
138
var _3a=this;
139
var _3b={downloadRemote:true,errBack:function(e){
140
_3a._onError.call(_3a,"Exec","Error downloading remote script in \""+_3a.id+"\"",e);
141
}};
142
_37=_27(_37,_3b);
143
this._code=_3b.code;
144
}
145
}
146
this.content=_37;
147
},onEnd:function(){
148
var _3c=this._code,_3d=this._styles;
149
if(this._styleNodes&&this._styleNodes.length){
150
while(this._styleNodes.length){
151
dojo.destroy(this._styleNodes.pop());
152
}
153
}
154
if(this.renderStyles&&_3d&&_3d.length){
155
this._renderStyles(_3d);
156
}
157
if(this.executeScripts&&_3c){
158
if(this.cleanContent){
159
_3c=_3c.replace(/(<!--|(?:\/\/)?-->|<!\[CDATA\[|\]\]>)/g,"");
160
}
161
if(this.scriptHasHooks){
162
_3c=_3c.replace(/_container_(?!\s*=[^=])/g,this.scriptHookReplacement);
163
}
164
try{
165
_31(_3c,this.node);
166
}
167
catch(e){
168
this._onError("Exec","Error eval script in "+this.id+", "+e.message,e);
169
}
170
}
171
this.inherited("onEnd",arguments);
172
},tearDown:function(){
173
this.inherited(arguments);
174
delete this._styles;
175
if(this._styleNodes&&this._styleNodes.length){
176
while(this._styleNodes.length){
177
dojo.destroy(this._styleNodes.pop());
178
}
179
}
180
delete this._styleNodes;
181
dojo.mixin(this,dojo.getObject(this.declaredClass).prototype);
182
}});
183
dojox.html.set=function(_3e,_3f,_40){
184
if(!_40){
185
return dojo.html._setNodeContent(_3e,_3f,true);
186
}else{
187
var op=new dojox.html._ContentSetter(dojo.mixin(_40,{content:_3f,node:_3e}));
188
return op.set();
189
}
190
};
191
})();
192
}