1 // AJAX-JSF AJAX-like library, for communicate with view Tree on server side.
  2 // In case of XMLHttpRequest don't worked, use :
  3 // JSHttpRequest v1.12. (C) Dmitry Koterov, 2005-01-27. 
  4 // http://forum.dklab.ru/users/DmitryKoterov/
  5 //
  6 // Do not remove this comment if you want to use script!
  7 // ?? ???????? ?????? ???????????, ???? ?? ?????? ???????????? ??????!
  8 //
  9 // Modified by Alexander J. Smirnov to use as JSF AJAX-like components. 
 10 
 11 // DOM - like elements for JSRequest. JS serialiser encode
 12 // XML sax events to creation of corresponding objects.  
 13 JSNode =  function() {
 14 };
 15 
 16 // Base node  
 17 JSNode.prototype = {
 18 	tag : null,
 19 	attrs : {},
 20 	childs : [],
 21 	value : "",
 22 	_symbols : {
 23 			'&':"&",
 24 			'<':"<",
 25 			'>':">",
 26 			'"':""",
 27 			'\'':"'",
 28 			'\u00A0':" "
 29 	},
 30 
 31 	// Public functions
 32 	getInnerHTML : function(context) {
 33 		var children = [];
 34 		for (var i = 0; i < this.childs.length; i++)
 35 		{
 36 			children.push(this.childs[i].getContent(context)); 
 37 		}
 38 		return children.join('');
 39 	},
 40 	// Escape XML symbols - < > & ' ...
 41 	xmlEscape : function(value) {
 42 		return RichFaces.jQuery("<div></div>").text(value).html();
 43 	}
 44 };
 45 
 46 // Element node
 47 E = function(tagname,attributes,childnodes) {
 48 	this.tag = tagname;
 49 	if (attributes) this.attrs = attributes;
 50 	if(childnodes) this.childs = childnodes;
 51 };
 52 
 53 E.prototype = new JSNode();
 54 E.prototype.getContent = function(context) {
 55 	var html = "<"+this.tag;
 56 	var inner = this.getInnerHTML(context);
 57 	if (inner=='') this.isEmpty = true; else this.isEmpty=false;
 58 	for(var i in this.attrs) {
 59 		if (!this.attrs.hasOwnProperty(i)) {
 60 			continue ;
 61 		}
 62 
 63 		var attrValue = this.attrs[i];
 64 		
 65 		if (typeof attrValue == "function")
 66 			attrValue = attrValue.call(this, context);
 67 		
 68 		if (attrValue) 
 69 			html += " "+(i=='className'?'class':i)+'="'+this.xmlEscape(attrValue)+'"';
 70 	}
 71 	html+= ">"+inner+"</"+this.tag+">";
 72 	return html;
 73 };
 74 
 75 // Escaped Text node
 76 ET = function(text) {
 77 	this.value = text;
 78 };
 79 
 80 
 81 //ET.prototype = new JSNode();
 82 ET.prototype.getContent = function(context) {
 83   	var value = this.value;
 84   	if (typeof value=="function") value=value(context);
 85   	if (value && value.getContent) {
 86 		value = value.getContent(context);
 87 	}
 88 	
 89 	if (value) return value;
 90   
 91 	return "";
 92 };
 93 
 94 // Text node
 95 T = function(text) {
 96 	this.value = text;
 97 };
 98 
 99 T.prototype = new JSNode();
100 T.prototype.getContent = function(context) {
101   	var value = this.value;
102   	if (typeof value=="function") value=value(context);
103   		
104 	if (value) return this.xmlEscape(value);
105 
106 	return "";
107 };
108 
109 // Comment node
110 C = function(text) {
111 	this.value = text;
112 };
113 
114 //C.prototype = new JSNode();
115 C.prototype.getContent = function(context) {
116 	return "<!--"+this.value+"-->";
117 };
118   
119 // CDATA Section node.
120 D = function(text) {
121 	this.value = text;
122 };
123   
124 //D.prototype = new JSNode();
125 D.prototype.getContent = function(context) {
126 	return "<![CDATA["+this.value+"]]>";
127 };
128 
129 
130