Author: pyaschenko
Date: 2007-06-26 10:03:43 -0400 (Tue, 26 Jun 2007)
New Revision: 1322
Modified:
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js
Log:
code improvement and optimisation
Modified:
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js
===================================================================
---
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js 2007-06-26
13:14:01 UTC (rev 1321)
+++
trunk/richfaces/common/src/main/resources/org/richfaces/renderkit/html/scripts/json/json-dom.js 2007-06-26
14:03:43 UTC (rev 1322)
@@ -8,230 +8,116 @@
//
// Modified by Alexander J. Smirnov to use as JSF AJAX-like components.
- JSDocument = function(js) {
-// AJAX_Log( " Response document "+Dump(js,1));
-// AJAX_Log( " Response document buildCache: "+typeof(js.buildCache));
- this.idsCache = {};
- js.buildCache(this.idsCache);
- this.documentElement = js;//this._parseJS(js);
- }
-
-// DOM document like class for parsing javaScript response.
- JSDocument.prototype = {
-// idsCache: {},
-
-
-// documentElement : null,
-
-
- getElementById: function( elementId ){
- return this.idsCache[elementId];
- },
-
- getElementsByTagName: function( tagname ){
- return [];
- },
- createElement: function(js){
- return new E(js.tag);
- },
-
-
- createTextNode: function(text){
- return new T(text);
- },
-
- createComment: function(text){
- return new C(text);
- },
-
- createCDATASection: function(text){
- return new D(text);
- }
-
-
- }
-
// DOM - like elements for JSRequest. JS serialiser encode
// XML sax events to creation of corresponding objects.
- JSNode = function(){
-// this.tag = null;
-// this.attrs = {};
-// this.childs = [];
-// this.value = "";
- };
-
- JSNode.prototype = {
- tag : null,
- attrs : {},
- childs : [],
- parentNode : null,
- value : "",
- _symbols : {
- '&':"&",
- '<':"<",
- '>':">",
- '"':""",
- '\'':"'",
- '\u00A0':" "
- },
- // Public functions
- getAttribute : function(aname) {
- return this.attrs[aname];
- },
- setAttribute : function(aname,avalue){
- this.attrs[aname]=avalue;
- },
- getInnerHTML : function(context){
- var html = "";
- for( var i = 0; i < this.childs.length; i++ ){
- html += this.childs[i].getOuterHTML(context);
- }
- return html;
- },
-// getOuterHTML : function(){return ""},
-
- appendChild : function(child){
- this.childs[this.childs.length]=child;
- child.parentNode = this;
- },
-
- buildCache : function(cache){
- if(this.attrs.id){
- cache[this.attrs.id]=this;
- }
- for( var i in this.childs ){
- this.childs[i].buildCache(cache);
- this.childs[i].parentNode = this;
- }
- },
-
- // TODO - make real clone ...
- cloneNode : function(withChildren){
- },
+JSNode = function() {
+};
+// Base node
+JSNode.prototype = {
+ tag : null,
+ attrs : {},
+ childs : [],
+ value : "",
+ _symbols : {
+ '&':"&",
+ '<':"<",
+ '>':">",
+ '"':""",
+ '\'':"'",
+ '\u00A0':" "
+ },
+ // Public functions
+ getInnerHTML : function(context) {
+ var html = "";
+ for (var i = 0; i < this.childs.length; i++)
+ html += this.childs[i].getContent(context);
+ return html;
+ },
// Escape XML symbols - < > & ' ...
- xmlescape : function(text){
- var t = text;
- if (t) {
- //handle non-strings
- t = t.toString();
- } else {
- t = "";
- }
-
- for( var i in this._symbols ){
-// text = text.replace(i,this._symbols[i]);
- t = t.split(i).join(this._symbols[i])
- }
- return t;
- },
-
- // Escape JavaScript function
- JSEscape : function(text){
-// for( var i in this._symbols ){
-// text = text.replace(i,this._symbols[i]);
-// text = text.split(i).join(this._symbols[i])
-// }
- return text;
- }
- }
- // Element node
- E = function(tagname,attributes,childnodes){
-
- this.tag = tagname;
- this.attrs = attributes;
- if(childnodes){
- this.childs = childnodes;
- } else {
- this.childs = [];
- }
- };
+ xmlEscape : function(value) {
+ var text = value ? value.toString() : "";
+ for(var i in this._symbols )
+ text = text.replace(i,this._symbols[i]);
+ return text;
+ }
+};
- E.prototype = new JSNode();
- E.prototype.getOuterHTML = function(context){
- // AJAX_Log("Get Outer HTML for object:"+Dump(this);
- var html = "<"+this.tag;
- var inner = this.getInnerHTML(context);
- for( var i in this.attrs ){
- if (!this.attrs.hasOwnProperty(i)) {
- continue ;
- }
-
- var attrValue = this.attrs[i];
-
- if (typeof attrValue == "function") {
- attrValue = attrValue(context);
- }
-
- if (attrValue) {
- html += "
"+(i=='className'?'class':i)+'="'+(i.substring(0,2)=="on"?this.JSEscape(attrValue):this.xmlescape(attrValue))+'"';
- // html+= "
"+i+'="'+this.xmlescape(this.attrs[i])+'"';
- }
- }
- if(inner == ""){
- html+= " />";
- } else {
- html+= " >"+inner+"</"+this.tag+">";
- }
- return html;
- };
+// Element node
+E = function(tagname,attributes,childnodes) {
+ this.tag = tagname;
+ if (attributes) this.attrs = attributes;
+ if(childnodes) this.childs = childnodes;
+};
+E.prototype = new JSNode();
+E.prototype.getContent = function(context) {
+ var html = "<"+this.tag;
+ var inner = this.getInnerHTML(context);
+ for(var i in this.attrs) {
- // Escaped Text node
- ET = function(text) {
- this.value = text;
- }
+ var attrValue = this.attrs[i];
+
+ if (typeof attrValue == "function")
+ attrValue = attrValue(context);
+
+ if (attrValue)
+ html += "
"+(i=='className'?'class':i)+'="'+this.xmlEscape(attrValue)+'"';
+ }
+ if(inner == "") html+= "/>";
+ else html+= ">"+inner+"</"+this.tag+">";
+ return html;
+};
- ET.prototype = new JSNode();
- ET.prototype.getOuterHTML = function(context){
- var value = this.value;
- if (typeof value == "function") {
- value = value(context);
- }
-
- if (value) {
- return value;
- }
+// Escaped Text node
+ET = function(text) {
+ this.value = text;
+};
+
+//ET.prototype = new JSNode();
+ET.prototype.getContent = function(context) {
+ var value = this.value;
+ if (typeof value == "function")
+ value = value(context);
+
+ if (value) return value;
- return "";
- }
+ return "";
+};
- // Text node
- T = function(text) {
- this.value = text;
- }
+// Text node
+T = function(text) {
+ this.value = text;
+};
- T.prototype = new JSNode();
- T.prototype.getOuterHTML = function(context){
- var value = this.value;
- if (typeof value == "function") {
- value = value(context);
- }
+T.prototype = new JSNode();
+T.prototype.getContent = function(context) {
+ var value = this.value;
+ if (typeof value == "function")
+ value = value(context);
- if (value) {
- return this.xmlescape(value);
- }
-
- return "";
- }
+ if (value) return this.xmlEscape(value);
- // Comment node
- C = function(text) {
- this.value = text;
- }
+ return "";
+};
- C.prototype = new JSNode();
- C.prototype.getOuterHTML = function(context){
- return "<!--"+this.value+"-->";
- }
+// Comment node
+C = function(text) {
+ this.value = text;
+};
+
+//C.prototype = new JSNode();
+C.prototype.getContent = function(context) {
+ return "<!--"+this.value+"-->";
+};
- // CDATA Section node.
- D = function(text) {
- this.value = text;
- }
+// CDATA Section node.
+D = function(text) {
+ this.value = text;
+};
- D.prototype = new JSNode();
- D.prototype.getOuterHTML = function(context){
- return "<![CDATA["+this.value+"]]>";
- }
+//D.prototype = new JSNode();
+D.prototype.getContent = function(context) {
+ return "<![CDATA["+this.value+"]]>";
+};