]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/html.js
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
8 if(!dojo
._hasResource
["dojo.html"]){
9 dojo
._hasResource
["dojo.html"]=true;
10 dojo
.provide("dojo.html");
11 dojo
.require("dojo.parser");
14 dojo
.html
._secureForInnerHtml=function(_2
){
15 return _2
.replace(/(?:\s*<!DOCTYPE\s[^>]+>|<title[^>]*>[\s\S]*?<\/title>)/ig,"");
17 dojo
.html
._emptyNode
=dojo
.empty
;
18 dojo
.html
._setNodeContent=function(_3
,_4
){
21 if(typeof _4
=="string"){
22 _4
=d
._toDom(_4
,_3
.ownerDocument
);
24 if(!_4
.nodeType
&&d
.isArrayLike(_4
)){
25 for(var _5
=_4
.length
,i
=0;i
<_4
.length
;i
=_5
==_4
.length
?i
+1:0){
26 d
.place(_4
[i
],_3
,"last");
29 d
.place(_4
,_3
,"last");
34 dojo
.declare("dojo.html._ContentSetter",null,{node
:"",content
:"",id
:"",cleanContent
:false,extractContent
:false,parseContent
:false,constructor:function(_6
,_7
){
35 dojo
.mixin(this,_6
||{});
36 _7
=this.node
=dojo
.byId(this.node
||_7
);
38 this.id
=["Setter",(_7
)?_7
.id
||_7
.tagName
:"",_1
++].join("_");
40 },set:function(_8
,_9
){
51 },setContent:function(){
54 throw new Error(this.declaredClass
+": setContent given no node");
57 _a
=dojo
.html
._setNodeContent(_a
,this.content
);
60 var _b
=this.onContentError(e
);
65 console
.error("Fatal "+this.declaredClass
+".setContent could not change content due to "+e
.message
,e
);
70 if(this.parseResults
&&this.parseResults
.length
){
71 dojo
.forEach(this.parseResults
,function(w
){
76 delete this.parseResults
;
78 dojo
.html
._emptyNode(this.node
);
81 if(dojo
.isString(_c
)){
82 if(this.cleanContent
){
83 _c
=dojo
.html
._secureForInnerHtml(_c
);
85 if(this.extractContent
){
86 var _d
=_c
.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
96 if(this.parseContent
){
100 },tearDown:function(){
101 delete this.parseResults
;
104 },onContentError:function(_e
){
105 return "Error occured setting content: "+_e
;
106 },_mixin:function(_f
){
117 this.parseResults
=dojo
.parser
.parse({rootNode
:_11
,dir
:this.dir
,lang
:this.lang
});
120 this._onError("Content",e
,"Error parsing in _ContentSetter#"+this.id
);
122 },_onError:function(_12
,err
,_13
){
123 var _14
=this["on"+_12
+"Error"].call(this,err
);
125 console
.error(_13
,err
);
128 dojo
.html
._setNodeContent(this.node
,_14
,true);
132 dojo
.html
.set=function(_15
,_16
,_17
){
134 console
.warn("dojo.html.set: no cont argument provided, using empty string");
138 return dojo
.html
._setNodeContent(_15
,_16
,true);
140 var op
=new dojo
.html
._ContentSetter(dojo
.mixin(_17
,{content
:_16
,node
:_15
}));