]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dijit/_editor/html.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dijit / _editor / html.js
1 if(!dojo._hasResource["dijit._editor.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._editor.html"] = true;
3 dojo.provide("dijit._editor.html");
4
5 dijit._editor.escapeXml=function(/*String*/str, /*Boolean*/noSingleQuotes){
6         //summary:
7         //              Adds escape sequences for special characters in XML: &<>"'
8         //              Optionally skips escapes for single quotes
9         str = str.replace(/&/gm, "&amp;").replace(/</gm, "&lt;").replace(/>/gm, "&gt;").replace(/"/gm, "&quot;");
10         if(!noSingleQuotes){
11                 str = str.replace(/'/gm, "&#39;");
12         }
13         return str; // string
14 };
15
16 dijit._editor.getNodeHtml=function(/* DomNode */node){
17         var output;
18         switch(node.nodeType){
19                 case 1: //element node
20                         output = '<'+node.nodeName.toLowerCase();
21
22                         //store the list of attributes and sort it to have the
23                         //attributes appear in the dictionary order
24                         var attrarray = [];
25                         if(dojo.isIE && node.outerHTML){
26                                 var s = node.outerHTML;
27                                 s = s.substr(0,s.indexOf('>'));
28                                 s = s.replace(/(['"])[^"']*\1/g, '');//to make the following regexp safe
29                                 var reg = /([^\s=]+)=/g;
30                                 var m, key;
31                                 while((m = reg.exec(s))){
32                                         key=m[1];
33                                         if(key.substr(0,3) != '_dj'){
34                                                 if(key == 'src' || key == 'href'){
35                                                         if(node.getAttribute('_djrealurl')){
36                                                                 attrarray.push([key,node.getAttribute('_djrealurl')]);
37                                                                 continue;
38                                                         }
39                                                 }
40                                                 if(key=='style'){
41                                                         attrarray.push([key, node.style.cssText.toLowerCase()]);
42                                                 }else{
43                                                         attrarray.push([key, key=='class'?node.className:node.getAttribute(key)]);
44                                                 }
45                                         }
46                                 }
47                         }else{
48                                 var attr, i=0, attrs = node.attributes;
49                                 while((attr=attrs[i++])){
50                                         //ignore all attributes starting with _dj which are
51                                         //internal temporary attributes used by the editor
52                                         var n=attr.name;
53                                         if(n.substr(0,3) != '_dj' /*&&
54                                                 (attr.specified == undefined || attr.specified)*/){
55                                                 var v = attr.value;
56                                                 if(n == 'src' || n == 'href'){
57                                                         if(node.getAttribute('_djrealurl')){
58                                                                 v = node.getAttribute('_djrealurl');
59                                                         }
60                                                 }
61                                                 attrarray.push([n,v]);
62                                         }
63                                 }
64                         }
65                         attrarray.sort(function(a,b){
66                                 return a[0]<b[0]?-1:(a[0]==b[0]?0:1);
67                         });
68                         i=0;
69                         while((attr=attrarray[i++])){
70                                 output += ' '+attr[0]+'="'+
71                                         (dojo.isString(attr[1]) ? dijit._editor.escapeXml(attr[1],true) : attr[1])+'"';
72                         }
73                         if(node.childNodes.length){
74                                 output += '>' + dijit._editor.getChildrenHtml(node)+'</'+node.nodeName.toLowerCase()+'>';
75                         }else{
76                                 output += ' />';
77                         }
78                         break;
79                 case 3: //text
80                         // FIXME:
81                         output = dijit._editor.escapeXml(node.nodeValue,true);
82                         break;
83                 case 8: //comment
84                         // FIXME:
85                         output = '<!--'+dijit._editor.escapeXml(node.nodeValue,true)+'-->';
86                         break;
87                 default:
88                         output = "Element not recognized - Type: " + node.nodeType + " Name: " + node.nodeName;
89         }
90         return output;
91 };
92
93 dijit._editor.getChildrenHtml = function(/* DomNode */dom){
94         // summary: Returns the html content of a DomNode and children
95         var out = "";
96         if(!dom){ return out; }
97         var nodes = dom["childNodes"]||dom;
98         var i=0;
99         var node;
100         while((node=nodes[i++])){
101                 out += dijit._editor.getNodeHtml(node);
102         }
103         return out; // String
104 }
105
106 }