root / trunk / web / dojo / dijit / _editor / html.js
History | View | Annotate | Download (2.58 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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["dijit._editor.html"]){ |
||
9 | dojo._hasResource["dijit._editor.html"]=true; |
||
10 | dojo.provide("dijit._editor.html");
|
||
11 | dijit._editor.escapeXml=function(_1,_2){ |
||
12 | _1=_1.replace(/&/gm,"&").replace(/</gm,"<").replace(/>/gm,">").replace(/"/gm,"""); |
||
13 | if(!_2){
|
||
14 | _1=_1.replace(/'/gm,"'"); |
||
15 | } |
||
16 | return _1;
|
||
17 | }; |
||
18 | dijit._editor.getNodeHtml=function(_3){ |
||
19 | var _4;
|
||
20 | switch(_3.nodeType){
|
||
21 | case 1: |
||
22 | var _5=_3.nodeName.toLowerCase();
|
||
23 | if(!_5||_5.charAt(0)=="/"){ |
||
24 | return ""; |
||
25 | } |
||
26 | _4="<"+_5;
|
||
27 | var _6=[];
|
||
28 | var _7;
|
||
29 | if(dojo.isIE&&_3.outerHTML){
|
||
30 | var s=_3.outerHTML;
|
||
31 | s=s.substr(0,s.indexOf(">")).replace(/(['"])[^"']*\1/g,""); |
||
32 | var _8=/(\b\w+)\s?=/g; |
||
33 | var m,_9;
|
||
34 | while((m=_8.exec(s))){
|
||
35 | _9=m[1];
|
||
36 | if(_9.substr(0,3)!="_dj"){ |
||
37 | if(_9=="src"||_9=="href"){ |
||
38 | if(_3.getAttribute("_djrealurl")){ |
||
39 | _6.push([_9,_3.getAttribute("_djrealurl")]);
|
||
40 | continue;
|
||
41 | } |
||
42 | } |
||
43 | var _a,_b;
|
||
44 | switch(_9){
|
||
45 | case "style": |
||
46 | _a=_3.style.cssText.toLowerCase(); |
||
47 | break;
|
||
48 | case "class": |
||
49 | _a=_3.className; |
||
50 | break;
|
||
51 | case "width": |
||
52 | if(_5==="img"){ |
||
53 | _b=/width=(\S+)/i.exec(s);
|
||
54 | if(_b){
|
||
55 | _a=_b[1];
|
||
56 | } |
||
57 | break;
|
||
58 | } |
||
59 | case "height": |
||
60 | if(_5==="img"){ |
||
61 | _b=/height=(\S+)/i.exec(s);
|
||
62 | if(_b){
|
||
63 | _a=_b[1];
|
||
64 | } |
||
65 | break;
|
||
66 | } |
||
67 | default:
|
||
68 | _a=_3.getAttribute(_9); |
||
69 | } |
||
70 | if(_a!=null){ |
||
71 | _6.push([_9,_a.toString()]); |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | }else{
|
||
76 | var i=0; |
||
77 | while((_7=_3.attributes[i++])){
|
||
78 | var n=_7.name;
|
||
79 | if(n.substr(0,3)!="_dj"){ |
||
80 | var v=_7.value;
|
||
81 | if(n=="src"||n=="href"){ |
||
82 | if(_3.getAttribute("_djrealurl")){ |
||
83 | v=_3.getAttribute("_djrealurl");
|
||
84 | } |
||
85 | } |
||
86 | _6.push([n,v]); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | _6.sort(function(a,b){
|
||
91 | return a[0]<b[0]?-1:(a[0]==b[0]?0:1); |
||
92 | }); |
||
93 | var j=0; |
||
94 | while((_7=_6[j++])){
|
||
95 | _4+=" "+_7[0]+"=\""+(dojo.isString(_7[1])?dijit._editor.escapeXml(_7[1],true):_7[1])+"\""; |
||
96 | } |
||
97 | if(_5==="script"){ |
||
98 | _4+=">"+_3.innerHTML+"</"+_5+">"; |
||
99 | }else{
|
||
100 | if(_3.childNodes.length){
|
||
101 | _4+=">"+dijit._editor.getChildrenHtml(_3)+"</"+_5+">"; |
||
102 | }else{
|
||
103 | switch(_5){
|
||
104 | case "br": |
||
105 | case "hr": |
||
106 | case "img": |
||
107 | case "input": |
||
108 | case "base": |
||
109 | case "meta": |
||
110 | case "area": |
||
111 | case "basefont": |
||
112 | _4+=" />";
|
||
113 | break;
|
||
114 | default:
|
||
115 | _4+="></"+_5+">"; |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | break;
|
||
120 | case 4: |
||
121 | case 3: |
||
122 | _4=dijit._editor.escapeXml(_3.nodeValue,true);
|
||
123 | break;
|
||
124 | case 8: |
||
125 | _4="<!--"+dijit._editor.escapeXml(_3.nodeValue,true)+"-->"; |
||
126 | break;
|
||
127 | default:
|
||
128 | _4="<!-- Element not recognized - Type: "+_3.nodeType+" Name: "+_3.nodeName+"-->"; |
||
129 | } |
||
130 | return _4;
|
||
131 | }; |
||
132 | dijit._editor.getChildrenHtml=function(_c){ |
||
133 | var _d=""; |
||
134 | if(!_c){
|
||
135 | return _d;
|
||
136 | } |
||
137 | var _e=_c["childNodes"]||_c; |
||
138 | var _f=!dojo.isIE||_e!==_c;
|
||
139 | var _10,i=0; |
||
140 | while((_10=_e[i++])){
|
||
141 | if(!_f||_10.parentNode==_c){
|
||
142 | _d+=dijit._editor.getNodeHtml(_10); |
||
143 | } |
||
144 | } |
||
145 | return _d;
|
||
146 | }; |
||
147 | } |