]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/html.js
add dijit/dojo stuff; initial ui mockup
[tt-rss.git] / lib / dojo / html.js
CommitLineData
2f01fe57
AD
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
8if(!dojo._hasResource["dojo.html"]){
9dojo._hasResource["dojo.html"]=true;
10dojo.provide("dojo.html");
11dojo.require("dojo.parser");
12(function(){
13var _1=0,d=dojo;
14dojo.html._secureForInnerHtml=function(_2){
15return _2.replace(/(?:\s*<!DOCTYPE\s[^>]+>|<title[^>]*>[\s\S]*?<\/title>)/ig,"");
16};
17dojo.html._emptyNode=dojo.empty;
18dojo.html._setNodeContent=function(_3,_4){
19d.empty(_3);
20if(_4){
21if(typeof _4=="string"){
22_4=d._toDom(_4,_3.ownerDocument);
23}
24if(!_4.nodeType&&d.isArrayLike(_4)){
25for(var _5=_4.length,i=0;i<_4.length;i=_5==_4.length?i+1:0){
26d.place(_4[i],_3,"last");
27}
28}else{
29d.place(_4,_3,"last");
30}
31}
32return _3;
33};
34dojo.declare("dojo.html._ContentSetter",null,{node:"",content:"",id:"",cleanContent:false,extractContent:false,parseContent:false,constructor:function(_6,_7){
35dojo.mixin(this,_6||{});
36_7=this.node=dojo.byId(this.node||_7);
37if(!this.id){
38this.id=["Setter",(_7)?_7.id||_7.tagName:"",_1++].join("_");
39}
40},set:function(_8,_9){
41if(undefined!==_8){
42this.content=_8;
43}
44if(_9){
45this._mixin(_9);
46}
47this.onBegin();
48this.setContent();
49this.onEnd();
50return this.node;
51},setContent:function(){
52var _a=this.node;
53if(!_a){
54throw new Error(this.declaredClass+": setContent given no node");
55}
56try{
57_a=dojo.html._setNodeContent(_a,this.content);
58}
59catch(e){
60var _b=this.onContentError(e);
61try{
62_a.innerHTML=_b;
63}
64catch(e){
65console.error("Fatal "+this.declaredClass+".setContent could not change content due to "+e.message,e);
66}
67}
68this.node=_a;
69},empty:function(){
70if(this.parseResults&&this.parseResults.length){
71dojo.forEach(this.parseResults,function(w){
72if(w.destroy){
73w.destroy();
74}
75});
76delete this.parseResults;
77}
78dojo.html._emptyNode(this.node);
79},onBegin:function(){
80var _c=this.content;
81if(dojo.isString(_c)){
82if(this.cleanContent){
83_c=dojo.html._secureForInnerHtml(_c);
84}
85if(this.extractContent){
86var _d=_c.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
87if(_d){
88_c=_d[1];
89}
90}
91}
92this.empty();
93this.content=_c;
94return this.node;
95},onEnd:function(){
96if(this.parseContent){
97this._parse();
98}
99return this.node;
100},tearDown:function(){
101delete this.parseResults;
102delete this.node;
103delete this.content;
104},onContentError:function(_e){
105return "Error occured setting content: "+_e;
106},_mixin:function(_f){
107var _10={},key;
108for(key in _f){
109if(key in _10){
110continue;
111}
112this[key]=_f[key];
113}
114},_parse:function(){
115var _11=this.node;
116try{
117this.parseResults=dojo.parser.parse({rootNode:_11,dir:this.dir,lang:this.lang});
118}
119catch(e){
120this._onError("Content",e,"Error parsing in _ContentSetter#"+this.id);
121}
122},_onError:function(_12,err,_13){
123var _14=this["on"+_12+"Error"].call(this,err);
124if(_13){
125console.error(_13,err);
126}else{
127if(_14){
128dojo.html._setNodeContent(this.node,_14,true);
129}
130}
131}});
132dojo.html.set=function(_15,_16,_17){
133if(undefined==_16){
134console.warn("dojo.html.set: no cont argument provided, using empty string");
135_16="";
136}
137if(!_17){
138return dojo.html._setNodeContent(_15,_16,true);
139}else{
140var op=new dojo.html._ContentSetter(dojo.mixin(_17,{content:_16,node:_15}));
141return op.set();
142}
143};
144})();
145}