3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>qooxdoo » Demo</title>
5 <link type="text/css" rel="stylesheet" href="../../resource/css/layout.css"/>
7 <link type="text/css" rel="stylesheet" href="../../resource/css/layout_ie.css"/>
9 <script type="text/javascript" src="../../script/qx.js"></script>
12 <script type="text/javascript" src="../../script/layout.js"></script>
14 <div id="demoDescription">
17 <textarea id="resultjs" style="position:absolute;width:600px;height:400px;background:white;top:120px;left:20px;border:1px solid black;overflow:auto"></textarea>
18 <textarea id="resulthtml" style="position:absolute;width:600px;height:100px;background:white;top:530px;left:20px;border:1px solid black;overflow:auto"></textarea>
20 <script type="text/javascript">
21 jsout = document.getElementById("resultjs");
22 htmlout = document.getElementById("resulthtml");
34 HTMLElement.prototype.__defineGetter__("outerHTML", function () {
35 var attrs = this.attributes;
36 var str = "<" + this.tagName.toLowerCase();
37 for (var i = 0; i < attrs.length; i++)
38 str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
40 if (_emptyTags[this.tagName])
43 return str + ">" + this.innerHTML + "</" + this.tagName.toLowerCase() + ">";
53 qx.core.Init.getInstance().defineMain(function()
55 a1 = new qx.ui.form.Button("Hello World", "icon/32/penguin.png");
56 a1.setLocation(20, 50);
57 qx.ui.core.ClientDocument.getInstance().add(a1);
59 a2 = new qx.ui.form.Button("Hello World", "icon/32/appearance.png");
60 a2.setLocation(220, 50);
61 qx.ui.core.ClientDocument.getInstance().add(a2);
64 qx.core.Init.getInstance().defineFinalize(function()
66 var str = "qx.core.Init.getInstance().defineMain(function()\n{\n";
71 qx.core.Init.getInstance().debug("Updating HTML");
73 htmlout.value = a1.getElement().outerHTML + a2.getElement().outerHTML;
82 qx.core.Init.getInstance().debug("Serialize...");
83 var vBase1 = serializeMain(a1);
84 var vBase2 = serializeMain(a2);
86 qx.core.Init.getInstance().debug("Base1: " + vBase1);
87 qx.core.Init.getInstance().debug("Base2: " + vBase2);
88 qx.core.Init.getInstance().debug("Tree Size: " + vObjectCache.length);
89 qx.core.Init.getInstance().debug("Generating Code...");
91 for (var i=0, n, v, c, cv, l=vObjectCache.length; i<l; i++)
93 v = vObjectCache[i].value;
94 c = vObjectCache[i].compiled;
98 case qx.constant.Type.OBJECT:
101 str += "$" + i + " = null;\n";
103 else if (v instanceof qx.core.Object)
105 // qx.core.Init.getInstance().debug("QXOBJECT: " + i + "=" + vObjectCache[i].value);
107 if (typeof c == qx.constant.Type.STRING && c.indexOf("$OBJECTMAPPER-") == 0)
109 cv = c.replace("$OBJECTMAPPER-", "");
113 case "qx.ui.core.ClientDocument":
114 str += "$" + i + " = qx.core.Init.getComponent().getClientWindow()().getClientDocument();\n";
117 case "qx.manager.object.ImageManager":
118 str += "$" + i + " = new qx.manager.object.ImageManager;\n";
124 str += "var f = new Function();\n";
125 str += "f.prototype = " + v.classname + ".prototype;\n";
126 str += "$" + i + " = new f;\n";
127 str += "QxObjectDataBase[" + v._hashCode + "] = $" + i + ";\n";
130 // str += v.classname + ".call($" + i + ");\n";
132 if (v instanceof qx.ui.core.Widget && v.isCreated())
135 str += "$" + i + "._valueElement = cssQuery(\"[qxhashcode=" + v._hashCode + "]\")[0];\n";
136 str += "$" + i + "._element = $" + i + "._valueElement;\n";
137 str += "$" + i + "._style = $" + i + "._valueElement.style;\n";
139 // map qx_Widget attribute of node to widget
140 str += "$" + i + "._valueElement.qx_Widget = $" + i + ";\n";
142 if (v instanceof qx.ui.basic.Image)
145 str += "$" + i + "._image = $" + i + "._valueElement.getElementsByTagName(\"img\")[0];\n";
148 else if (v instanceof qx.io.image.ImagePreloader)
150 str += "$" + i + "._element = new Image;\n";
151 str += "$" + i + "._element.src = \"" + v.getSource() + "\";\n";
155 else if (v instanceof Array)
157 // qx.core.Init.getInstance().debug("JSARRAY: " + i + "=" + vObjectCache[i].value);
159 str += "$" + i + " = [];\n";
163 // qx.core.Init.getInstance().debug("JSHASHTABLE: " + i + "=" + vObjectCache[i].value);
165 str += "$" + i + " = {};\n";
170 case qx.constant.Type.STRING:
171 str += "$" + i + " = \"" + vObjectCache[i].value + "\";\n";
174 case qx.constant.Type.NUMBER:
175 case qx.constant.Type.BOOLEAN:
176 str += "$" + i + " = " + v + ";\n";
179 case qx.constant.Type.UNDEFINED:
180 // qx.core.Init.getInstance().debug("Undefined value found: " + v);
181 str += "$" + i + " = null;\n";
184 case qx.constant.Type.FUNCTION:
185 if (typeof c == qx.constant.Type.STRING && c.indexOf("$FUNCTIONMAPPER-") == 0)
187 cv = c.replace("$FUNCTIONMAPPER-", "").split("|");
188 str += "$" + i + "= QxObjectDataBase[" + cv[1] + "]." + cv[0] + ";\n";
193 qx.core.Init.getInstance().debug("Unsupported value: " + v);
194 str += "var $" + i + " = \"UNSUPPORTED VALUE\";\n";
205 for (var i=0, n, c, v, cv, l=vObjectCache.length; i<l; i++)
207 v = vObjectCache[i].value;
208 c = vObjectCache[i].compiled;
210 if (typeof v == qx.constant.Type.OBJECT && v != null)
212 if (v instanceof qx.core.Object)
214 if (typeof c == qx.constant.Type.STRING && c.indexOf("$OBJECTMAPPER-") == 0)
219 for (vKey in vObjectCache[i].compiled)
221 if (vObjectCache[i].compiled[vKey] != null)
223 str += "$" + i + "." + vKey + " = $" + vObjectCache[i].compiled[vKey] + ";\n";
227 else if (v instanceof Array)
229 for (var ia=0, la=vObjectCache[i].compiled.length; ia<la; ia++)
231 str += "$" + i + "[" + ia + "] = $" + vObjectCache[i].compiled[ia] + ";\n";
236 for (vKey in vObjectCache[i].compiled)
238 if (vObjectCache[i].compiled[vKey] != null)
240 str += "$" + i + "[\"" + vKey + "\"] = $" + vObjectCache[i].compiled[vKey] + ";\n";
255 qx.core.Init.getInstance().debug("Done");
261 var vObjectCache = [];
262 var vLastListenerContext = null;
264 function serializeMain(vValue)
266 var vValue, vIter, vLength;
268 // Completly ignore the window and document built-in object
269 if (vValue == window || vValue == document) {
273 // Completly ignore DOM nodes
274 if (qx.util.Validation.isValid(vValue) && typeof vValue.nodeType != qx.constant.Type.UNDEFINED) {
278 for (vIter=0, vLength=vObjectCache.length; vIter<vLength; vIter++)
280 if (vObjectCache[vIter].value === vValue)
286 //QxDebug("Serializer", "Known: " + vObjectCache);
287 //QxDebug("Serializer", "Serialize: " + vValue + "(" + typeof vValue + ")");
289 var vPos = vObjectCache.length;
291 vObjectCache[vPos] = { value : vValue };
292 vObjectCache[vPos].compiled = serializeWrapper(vValue);
297 function serializeWrapper(vInput)
299 switch(typeof vInput)
301 case qx.constant.Type.STRING:
302 case qx.constant.Type.NUMBER:
303 case qx.constant.Type.BOOLEAN:
304 return serializeSimple(vInput);
306 case qx.constant.Type.OBJECT:
309 return serializeSimple(vInput);
311 else if (vInput instanceof Array)
313 return serializeArray(vInput);
317 return serializeObject(vInput);
320 case qx.constant.Type.FUNCTION:
321 //QxDebug("Serializer", "FUNCTION: " + vInput);
328 function serializeSimple(vSimple) {
332 function serializeObject(vObject)
334 if (vObject instanceof qx.ui.core.ClientDocument) {
335 return "$OBJECTMAPPER-qx.ui.core.ClientDocument";
337 else if (vObject instanceof qx.manager.object.ImageManager) {
338 return "$OBJECTMAPPER-qx.manager.object.ImageManager";
344 for (vKey in vObject)
346 // ignore css reference
353 // QxDebug("Serializer", "Found Listeners: " + vKey + "::" + vObject);
354 vLastListenerContext = vObject;
358 if (typeof vObject[vKey] == qx.constant.Type.FUNCTION)
360 if (!(vObject instanceof qx.core.Object) && vLastListenerContext)
362 var to = new vLastListenerContext.constructor;
367 if (to[vSubKey] === vObject[vKey])
376 qx.core.Init.getInstance().debug("Serializer", "Function Mapped: " + tm);
377 var ts = { value : vObject[vKey], compiled : "$FUNCTIONMAPPER-" + tm + "|" + vLastListenerContext._hashCode };
378 vObjectCache.push(ts);
379 vOut[vKey] = vObjectCache.length-1;
384 qx.core.Init.getInstance().debug("Serializer", "Could not map function: " + vKey + "[" + vLastListenerContext + "]");
395 vOut[vKey] = serializeMain(vObject[vKey]);
401 function serializeArray(vArray)
406 for (var vIter=0, vLength=vArray.length; vIter<vLength; vIter++) {
407 vOut.push(serializeMain(vArray[vIter]));