From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dijit/_editor/html.js | 106 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 includes/js/dijit/_editor/html.js (limited to 'includes/js/dijit/_editor/html.js') diff --git a/includes/js/dijit/_editor/html.js b/includes/js/dijit/_editor/html.js new file mode 100644 index 0000000..8b20592 --- /dev/null +++ b/includes/js/dijit/_editor/html.js @@ -0,0 +1,106 @@ +if(!dojo._hasResource["dijit._editor.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dijit._editor.html"] = true; +dojo.provide("dijit._editor.html"); + +dijit._editor.escapeXml=function(/*String*/str, /*Boolean*/noSingleQuotes){ + //summary: + // Adds escape sequences for special characters in XML: &<>"' + // Optionally skips escapes for single quotes + str = str.replace(/&/gm, "&").replace(//gm, ">").replace(/"/gm, """); + if(!noSingleQuotes){ + str = str.replace(/'/gm, "'"); + } + return str; // string +}; + +dijit._editor.getNodeHtml=function(/* DomNode */node){ + var output; + switch(node.nodeType){ + case 1: //element node + output = '<'+node.nodeName.toLowerCase(); + + //store the list of attributes and sort it to have the + //attributes appear in the dictionary order + var attrarray = []; + if(dojo.isIE && node.outerHTML){ + var s = node.outerHTML; + s = s.substr(0,s.indexOf('>')); + s = s.replace(/(['"])[^"']*\1/g, '');//to make the following regexp safe + var reg = /([^\s=]+)=/g; + var m, key; + while((m = reg.exec(s))){ + key=m[1]; + if(key.substr(0,3) != '_dj'){ + if(key == 'src' || key == 'href'){ + if(node.getAttribute('_djrealurl')){ + attrarray.push([key,node.getAttribute('_djrealurl')]); + continue; + } + } + if(key=='style'){ + attrarray.push([key, node.style.cssText.toLowerCase()]); + }else{ + attrarray.push([key, key=='class'?node.className:node.getAttribute(key)]); + } + } + } + }else{ + var attr, i=0, attrs = node.attributes; + while((attr=attrs[i++])){ + //ignore all attributes starting with _dj which are + //internal temporary attributes used by the editor + var n=attr.name; + if(n.substr(0,3) != '_dj' /*&& + (attr.specified == undefined || attr.specified)*/){ + var v = attr.value; + if(n == 'src' || n == 'href'){ + if(node.getAttribute('_djrealurl')){ + v = node.getAttribute('_djrealurl'); + } + } + attrarray.push([n,v]); + } + } + } + attrarray.sort(function(a,b){ + return a[0]'; + }else{ + output += ' />'; + } + break; + case 3: //text + // FIXME: + output = dijit._editor.escapeXml(node.nodeValue,true); + break; + case 8: //comment + // FIXME: + output = ''; + break; + default: + output = "Element not recognized - Type: " + node.nodeType + " Name: " + node.nodeName; + } + return output; +}; + +dijit._editor.getChildrenHtml = function(/* DomNode */dom){ + // summary: Returns the html content of a DomNode and children + var out = ""; + if(!dom){ return out; } + var nodes = dom["childNodes"]||dom; + var i=0; + var node; + while((node=nodes[i++])){ + out += dijit._editor.getNodeHtml(node); + } + return out; // String +} + +} -- cgit v1.2.3