Author: jmorliaguet
Date: Sun Mar  5 12:55:16 2006
New Revision: 2528

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
Log:

- optimizations: we avoid manipulating the DOM when loading component
  definitions. remote definitions get loaded directly in RAM.



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sun Mar  5 
12:55:16 2006
@@ -48,6 +48,7 @@
   _handlers: $H({}),
 
   _initialized: $H({}),
+  _defs: $H({}),
 
   init: function() {
     CPSSkins._parse(document);
@@ -168,10 +169,8 @@
 
   /* Document parsing */
 
-  _jsonParse: function(el) {
-    var res = null;
-    var text = el.innerHTML;
-    if (!text) return;
+  _jsonParse: function(el, text) {
+    var res = {};
     try {
       res = JSON.parse(text.unescapeHTML());
     } catch(e) {
@@ -208,10 +207,10 @@
       if (url) {
         var options = {
           onComplete: function(req) {
-            el.innerHTML = req.responseText;
+            CPSSkins._eval(el, req.responseText);
             CPSSkins.notify('initialized', {'publisher': el});
           }
-        }
+        };
         var parts = url.split('?');
         if (parts.length == 2) {
           url = parts[0];
@@ -220,11 +219,23 @@
         new Ajax.Request(url, options);
       } else {
         /* the definition is written inline */
+        CPSSkins._eval(el, el.innerHTML);
+        el.innerHTML = '';
         CPSSkins.notify('initialized', {'publisher': el});
       }
     });
   },
 
+  _eval: function(el, text) {
+    var def = this._jsonParse(el, text);
+    var id = def.id;
+    if (!id) {
+      CPSSkins.warn("Component has no id: <pre>" + text + "</pre>", el);
+    }
+    el.id = id;
+    this._defs[[el.className,el.id]] = def;
+  },
+
   // second stage
   _load: function(node) {
     var elements = $A(node.getElementsByTagName("ins"));
@@ -238,17 +249,8 @@
   },
 
   _register: function(node, el, classid) {
-      // make the element identifiable
-      var def = this._jsonParse(el);
+      var def = this._defs[[classid,el.id]];
       var id = def.id;
-      if (!id) {
-        CPSSkins.warn("Component of type '" + classid + "' has no id: <pre>"
-                      + el.innerHTML + "</pre>", el);
-      }
-      // store the component's id on the node
-      el.id = id;
-      // remove the definition from the DOM
-      el.innerHTML = '';
 
       switch(classid) {
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to