[KSS-checkins] r49854 - kukit/kukit.js/branch/finish-closures/kukit

gotcha at codespeak.net gotcha at codespeak.net
Sun Dec 16 20:53:38 CET 2007


Author: gotcha
Date: Sun Dec 16 20:53:37 2007
New Revision: 49854

Modified:
   kukit/kukit.js/branch/finish-closures/kukit/commandreg.js
   kukit/kukit.js/branch/finish-closures/kukit/forms.js
   kukit/kukit.js/branch/finish-closures/kukit/kukit.js
Log:
class closures

Modified: kukit/kukit.js/branch/finish-closures/kukit/commandreg.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/commandreg.js	(original)
+++ kukit/kukit.js/branch/finish-closures/kukit/commandreg.js	Sun Dec 16 20:53:37 2007
@@ -142,22 +142,20 @@
 };
 
 cr.makeSelectorCommand = function(name, executeOnSingleNode) {
-    var commandClass = function() {};
-    commandClass.prototype = {
-        execute: _executeCommand,
-        executeOnScope: _executeCommandOnSelector,
-        executeOnSingleNode: executeOnSingleNode
-    };
+    var commandClass = function() {
+        this.execute = _executeCommand;
+        this.executeOnScope = _executeCommandOnSelector;
+        this.executeOnSingleNode = executeOnSingleNode;
+        };
     kukit.commandsGlobalRegistry.register(name, commandClass); 
 };
 
 cr.makeGlobalCommand = function(name, executeOnce) {
-    var commandClass = function() {};
-    commandClass.prototype = {
-        execute: _executeCommand,
-        executeOnScope: executeOnce,
-        executeOnSingleNode: executeOnce
-    };
+    var commandClass = function() {
+        this.execute = _executeCommand;
+        this.executeOnScope = executeOnce;
+        this.executeOnSingleNode = executeOnce;
+        };
     kukit.commandsGlobalRegistry.register(name, commandClass); 
 };
 

Modified: kukit/kukit.js/branch/finish-closures/kukit/forms.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/forms.js	(original)
+++ kukit/kukit.js/branch/finish-closures/kukit/forms.js	Sun Dec 16 20:53:37 2007
@@ -38,10 +38,11 @@
 var _FormQueryElem = function(name, value) {
     this.name = name;
     this.value = value;
-};
     
-_FormQueryElem.prototype.encode = function() {
-    return this.name+ "=" + encodeURIComponent(this.value);
+    this.encode = function() {
+        return this.name+ "=" + encodeURIComponent(this.value);
+    };
+    
 };
     
 /*
@@ -49,56 +50,56 @@
 */
 fo.FormQuery = function() {
     this.l = [];
-};
 
-fo.FormQuery.prototype.appendElem = function(name, value) {
-    if (value == null) {
-        // do not marshall nulls
-;;;     var msg = "Parameter '" + name + "' is null,";
-;;;     msg += " it is not marshalled.";
-;;;     kukit.logDebug(msg);
-        }
-    else if (typeof(value) == 'string') {
-        var elem = new _FormQueryElem(name, value);
-        this.l.push(elem);
-    }
-    // value.length is for detection of an Array.
-    // In addition we also check that value.pop is a function
-    else if (typeof(value) == 'object' && 
-        typeof(value.length) == 'number' &&
-        typeof(value.pop) == 'function') {
-        // Special marshalling of arrays
-        for (var i=0; i < value.length; i++) {
-            var elem = new _FormQueryElem(name, value[i]);
+    this.appendElem = function(name, value) {
+        if (value == null) {
+            // do not marshall nulls
+;;;         var msg = "Parameter '" + name + "' is null,";
+;;;         msg += " it is not marshalled.";
+;;;         kukit.logDebug(msg);
+            }
+        else if (typeof(value) == 'string') {
+            var elem = new _FormQueryElem(name, value);
             this.l.push(elem);
         }
-    }
-    else if (typeof(value) == 'object') {
-        // Special marshalling of dicts
-        for (var key in value) {
-            var qkey = _dictPrefix + name + _dictSeparator;
-            qkey += key + _dictPostfix;
-            var elem = new _FormQueryElem(qkey, value[key]);
-            this.l.push(elem);
+        // value.length is for detection of an Array.
+        // In addition we also check that value.pop is a function
+        else if (typeof(value) == 'object' && 
+            typeof(value.length) == 'number' &&
+            typeof(value.pop) == 'function') {
+            // Special marshalling of arrays
+            for (var i=0; i < value.length; i++) {
+                var elem = new _FormQueryElem(name, value[i]);
+                this.l.push(elem);
+            }
         }
-    }    
-};
+        else if (typeof(value) == 'object') {
+            // Special marshalling of dicts
+            for (var key in value) {
+                var qkey = _dictPrefix + name + _dictSeparator;
+                qkey += key + _dictPostfix;
+                var elem = new _FormQueryElem(qkey, value[key]);
+                this.l.push(elem);
+            }
+        }    
+    };
 
-fo.FormQuery.prototype.encode = function() {
-    var poster = [];
-      for (var i=0;i < this.l.length;i++) {
-        poster[poster.length] = this.l[i].encode();
-    }
-    return poster.join("&");
-};
+    this.encode = function() {
+        var poster = [];
+          for (var i=0;i < this.l.length;i++) {
+            poster[poster.length] = this.l[i].encode();
+        }
+        return poster.join("&");
+    };
 
-fo.FormQuery.prototype.toDict = function() {
-    var d = {};
-      for (var i=0;i < this.l.length;i++) {
-        var elem = this.l[i];
-        d[elem.name] = elem.value;
-    }
-    return d;
+    this.toDict = function() {
+        var d = {};
+          for (var i=0;i < this.l.length;i++) {
+            var elem = this.l[i];
+            d[elem.name] = elem.value;
+        }
+        return d;
+    };
 };
 
 /* Form data extraction, helpers */
@@ -122,29 +123,29 @@
 
 fo.CurrentFormLocator = function(target) {
     this.target = target;
-};
 
-fo.CurrentFormLocator.prototype.queryForm = function() {
-    // Find the form that contains the target node.
-    return findContainer(this.target, function(node) {
-        if (!node.nodeName) {
-            return false;
-        }
-        if (node.nodeName.toLowerCase() == "form") {
-            return true;
-        } else {
-            return false;
-        }
-    });
-};
+    this.queryForm = function() {
+        // Find the form that contains the target node.
+        return findContainer(this.target, function(node) {
+            if (!node.nodeName) {
+                return false;
+            }
+            if (node.nodeName.toLowerCase() == "form") {
+                return true;
+            } else {
+                return false;
+            }
+        });
+    };
 
-fo.CurrentFormLocator.prototype.getForm = function() {
-    var form = this.queryForm();
-    if (!form) {
-;;;     kukit.logWarning("No form found");
-        return null;
-    }
-    return form;
+    this.getForm = function() {
+        var form = this.queryForm();
+        if (!form) {
+;;;         kukit.logWarning("No form found");
+            return null;
+        }
+        return form;
+    };
 };
 
 /*
@@ -154,15 +155,14 @@
 
 fo.NamedFormLocator = function(formname) {
     this.formname = formname;
-};
 
-fo.NamedFormLocator.prototype.queryForm = function() {
-    // Find the form with the given name.
-    return document.forms[this.formname];
-};
+    this.getForm = fo.CurrentFormLocator.getForm;
 
-fo.NamedFormLocator.prototype.getForm = 
-    fo.CurrentFormLocator.prototype.getForm;
+    this.queryForm = function() {
+        // Find the form with the given name.
+        return document.forms[this.formname];
+    };
+};
 
 /* methods to take the desired value(s) from the form */
 
@@ -279,27 +279,27 @@
 */
 var _FieldUpdateRegistry = function() {
     this.editors = {};
-};
-
-_FieldUpdateRegistry.prototype.register = function(node, editor) {
-    var hash = kukit.rd.hashNode(node);
-    if (typeof(this.editors[hash]) != 'undefined') {
-;;;     kukit.E = 'Double registration of editor update on node.';
-        throw new Error(kukit.E);
-    }
-    this.editors[hash] = editor;
-    //kukit.logDebug('Registered '+node.name + ' hash=' + hash);
-    //Initialize the editor
-    editor.doInit();
-};
 
-_FieldUpdateRegistry.prototype.doUpdate = function(node) {
-    var hash = kukit.rd.hashNode(node);
-    var editor = this.editors[hash];
-    if (typeof(editor) != 'undefined') {
-        editor.doUpdate(node);
-        //kukit.logDebug('Updated '+node.name + ' hash=' + hash);
-    }
+    this.register = function(node, editor) {
+        var hash = kukit.rd.hashNode(node);
+        if (typeof(this.editors[hash]) != 'undefined') {
+;;;         kukit.E = 'Double registration of editor update on node.';
+            throw new Error(kukit.E);
+        }
+        this.editors[hash] = editor;
+        //kukit.logDebug('Registered '+node.name + ' hash=' + hash);
+        //Initialize the editor
+        editor.doInit();
+    };
+
+    this.doUpdate = function(node) {
+        var hash = kukit.rd.hashNode(node);
+        var editor = this.editors[hash];
+        if (typeof(editor) != 'undefined') {
+            editor.doUpdate(node);
+            //kukit.logDebug('Updated '+node.name + ' hash=' + hash);
+        }
+    };
 };
 
 // fieldUpdateRegistry is a public service, available to all components
@@ -321,20 +321,20 @@
 * class _FormValueProvider
 *
 */
-var _FormValueProvider = function() {};
-
-_FormValueProvider.prototype = {
-    check: function(args) {
+var _FormValueProvider = function() {
+    this.check = function(args) {
 ;;;     if (args.length != 1) {
 ;;;         throw new Error('form method needs 1 arguments (formname)');
 ;;;     }
-    },
-    eval: function(args, node) {
+    };
+
+    this.eval = function(args, node) {
         var locator = new fo.NamedFormLocator(args[0]);
         var collector = new kukit.ut.TupleCollector();
         return fo.getAllFormVars(locator, collector);
-    }
+    };
 };
+
 fo.pproviderFormRegistry.register('form', _FormValueProvider);
 
 /*
@@ -342,19 +342,20 @@
 * class _CurrentFormValueProvider
 *
 */
-var _CurrentFormValueProvider = function() {};
-_CurrentFormValueProvider.prototype = {
-    check: function(args) {
+var _CurrentFormValueProvider = function() {
+    this.check = function(args) {
 ;;;     if (args.length != 0) {
 ;;;         throw new Error('currentForm method needs no argument');
 ;;;     }
-    },
-    eval: function(args, node) {
+    };
+
+    this.eval = function(args, node) {
         var locator = new fo.CurrentFormLocator(node);
         var collector = new kukit.ut.TupleCollector();
         return fo.getAllFormVars(locator, collector);
-    }
+    };
 };
+
 fo.pproviderFormRegistry.register('currentForm', _CurrentFormValueProvider);
 
 // If a string is given, that will look like a form lookup,

Modified: kukit/kukit.js/branch/finish-closures/kukit/kukit.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/kukit.js	(original)
+++ kukit/kukit.js/branch/finish-closures/kukit/kukit.js	Sun Dec 16 20:53:37 2007
@@ -24,12 +24,26 @@
 ku.isDevelMode = false;
 ;;; ku.isDevelMode = true;
 
+var _isKineticStylesheet = function(node) {
+    var rel = node.rel;
+    if (rel=="kinetic-stylesheet") {
+        return true;
+    }
+    // BBB to be removed after 2008-02-17
+    if (rel=="kukit" || rel=="k-stylesheet") {
+;;;     var msg = node.href + ': rel "' + rel +'" is deprecated;';
+;;;     msg = msg + ' use "kinetic-stylesheet" instead.';
+;;;     kukit.logWarning(msg);
+        return true;
+    }
+    return false;
+};
+
 
 /*
 * class Engine
 */
 ku.Engine = function() {
-    this.baseUrl = this.calculateBase();
     this.documentRules = new kukit.rd.MethodTable();
     // table from res_type to rule processor
     this._ruleProcessorClasses = {};
@@ -49,243 +63,226 @@
     this.setupEventsQueue = [];
     this.setupEventsInProgress = false;
 
-};
-
-ku.Engine.prototype.calculateBase = function() {
-    var base = '';
-    try {
-        var _dummy = document;
-        _dummy = window;
-    } catch (e) {
-        // testing or what
-        return base;
-    }
-    var nodes = document.getElementsByTagName("link");
-    if (nodes.length > 0) {
-        for (var i=0; i<nodes.length; i++) {
-            var link = nodes[i];
-            if (link.rel == 'kss-base-url') {
-                return link.href;
+    this.calculateBase = function() {
+        var base = '';
+        try {
+            var _dummy = document;
+            _dummy = window;
+        } catch (e) {
+            // testing or what
+            return base;
+        }
+        var nodes = document.getElementsByTagName("link");
+        if (nodes.length > 0) {
+            for (var i=0; i<nodes.length; i++) {
+                var link = nodes[i];
+                if (link.rel == 'kss-base-url') {
+                    return link.href;
+                }
             }
         }
-    }
-    nodes = document.getElementsByTagName("base");
-    if (nodes.length == 0) {
-        var base = window.location.href;
-        var pieces = base.split('/');
-        pieces.pop();
-        base = pieces.join('/');
-    } else {
-        base = nodes[0].href;
-        // take off trailing slash
-        var baselen = base.length;
-        if (baselen > 0 && base.substring(baselen - 1) == '/') {
-            base = base.substring(0, baselen - 1);
+        nodes = document.getElementsByTagName("base");
+        if (nodes.length == 0) {
+            var base = window.location.href;
+            var pieces = base.split('/');
+            pieces.pop();
+            base = pieces.join('/');
+        } else {
+            base = nodes[0].href;
+            // take off trailing slash
+            var baselen = base.length;
+            if (baselen > 0 && base.substring(baselen - 1) == '/') {
+                base = base.substring(0, baselen - 1);
+            }
         }
-    }
-    return base;
-};
+        return base;
+    };
+    this.baseUrl = this.calculateBase();
 
-ku.Engine.prototype.getRuleSheetLinks = function() {
-    var nodes = document.getElementsByTagName("link");
-    var results = [];
-    for (var i=0; i<nodes.length; i++) {
-        if (_isKineticStylesheet(nodes[i])) {
-            var res_type = null;
-            // Resource syntax is decided on type attribute.
-            if((nodes[i].type == 'text/css') || (nodes[i].type == 'text/kss')) {
-                res_type = 'kss';
-;;;         } else {
-;;;             // Just show this, and go on with the processing.
-;;;             kukit.logError("rel type is not text/css or text/kss");
+    this.getRuleSheetLinks = function() {
+        var nodes = document.getElementsByTagName("link");
+        var results = [];
+        for (var i=0; i<nodes.length; i++) {
+            if (_isKineticStylesheet(nodes[i])) {
+                var res_type = null;
+                // Resource syntax is decided on type attribute.
+                if((nodes[i].type == 'text/css') || (nodes[i].type == 'text/kss')) {
+                    res_type = 'kss';
+;;;             } else {
+;;;                 // Just show this, and go on with the processing.
+;;;                 kukit.logError("rel type is not text/css or text/kss");
+                }
+                var newRuleLink = new _RuleSheetLink(nodes[i].href, res_type);
+                results[results.length] = newRuleLink;
             }
-            var newRuleLink = new _RuleSheetLink(nodes[i].href, res_type);
-            results[results.length] = newRuleLink;
         }
-    }
-    return results;
-};
-
-ku.Engine.prototype.createRuleProcessor = function(rulelink) {
-    var ruleProcessorClass = this._ruleProcessorClasses[rulelink.res_type];
-    if (ruleProcessorClass) {
-;;;     var msg = "Start loading and processing " + rulelink.href;
-;;;     msg = msg + " of type " + rulelink.res_type;
-;;;     kukit.log(msg);
-        var ruleprocessor = new ruleProcessorClass(rulelink.href);
-        this._ruleProcessors[this._ruleProcessors.length] = ruleprocessor;
-        return ruleprocessor;
-;;; } else {
-;;;     var msg = "Ignore rulesheet " + rulelink.href;
-;;;     msg = msg + " of type " + rulelink.res_type;
-;;;     kukit.log(msg);
-    }
-    return null;
-};
-
+        return results;
+    };
 
-ku.Engine.prototype.getRules = function() {
-    var rules = new Array();
-    var ruleProcessors = this._ruleProcessors
-    for (var j=0; j<ruleProcessors.length; j++) {
-        var ruleProcessor = ruleProcessors[j];
-        for (var i=0; i<ruleProcessor.rules.length; i++) {
-            rules.push(ruleProcessor.rules[i]);
+    this.createRuleProcessor = function(rulelink) {
+        var ruleProcessorClass = this._ruleProcessorClasses[rulelink.res_type];
+        if (ruleProcessorClass) {
+;;;         var msg = "Start loading and processing " + rulelink.href;
+;;;         msg = msg + " of type " + rulelink.res_type;
+;;;         kukit.log(msg);
+            var ruleprocessor = new ruleProcessorClass(rulelink.href);
+            this._ruleProcessors[this._ruleProcessors.length] = ruleprocessor;
+            return ruleprocessor;
+;;;     } else {
+;;;         var msg = "Ignore rulesheet " + rulelink.href;
+;;;         msg = msg + " of type " + rulelink.res_type;
+;;;         kukit.log(msg);
         }
-    }
-    return rules;
-}
+        return null;
+    };
 
-ku.Engine.prototype.getRuleProcessors = function() {
-    return this._ruleProcessors
-}
 
-var _isKineticStylesheet = function(node) {
-    var rel = node.rel;
-    if (rel=="kinetic-stylesheet") {
-        return true;
-    }
-    // BBB to be removed after 2008-02-17
-    if (rel=="kukit" || rel=="k-stylesheet") {
-;;;     var msg = node.href + ': rel "' + rel +'" is deprecated;';
-;;;     msg = msg + ' use "kinetic-stylesheet" instead.';
-;;;     kukit.logWarning(msg);
-        return true;
+    this.getRules = function() {
+        var rules = new Array();
+        var ruleProcessors = this._ruleProcessors
+        for (var j=0; j<ruleProcessors.length; j++) {
+            var ruleProcessor = ruleProcessors[j];
+            for (var i=0; i<ruleProcessor.rules.length; i++) {
+                rules.push(ruleProcessor.rules[i]);
+            }
+        }
+        return rules;
     }
-    return false;
-};
 
-ku.Engine.prototype.setupEvents = function(inNodes) {
-    if (this.setupEventsInProgress) {
-        // remember them
-        this.setupEventsQueue = this.setupEventsQueue.concat(inNodes);
-    } else {
-        // do it
-        this.doSetupEvents(inNodes);
+    this.getRuleProcessors = function() {
+        return this._ruleProcessors
     }
-};
 
-ku.Engine.prototype.beginSetupEventsCollection = function() {
-    this.setupEventsInProgress = true;
-};
+    this.setupEvents = function(inNodes) {
+        if (this.setupEventsInProgress) {
+            // remember them
+            this.setupEventsQueue = this.setupEventsQueue.concat(inNodes);
+        } else {
+            // do it
+            this.doSetupEvents(inNodes);
+        }
+    };
 
-ku.Engine.prototype.finishSetupEventsCollection = function() {
-    this.setupEventsInProgress = false;
-    var setupEventsQueue = this.setupEventsQueue;
-    this.setupEventsQueue = [];
-    this.doSetupEvents(setupEventsQueue);
-};
+    this.beginSetupEventsCollection = function() {
+        this.setupEventsInProgress = true;
+    };
 
-ku.Engine.prototype.doSetupEvents = function(inNodes) {
-    var self = this;
-    var deferredEventsSetup = function() {
-        self._setupEvents(inNodes);
+    this.finishSetupEventsCollection = function() {
+        this.setupEventsInProgress = false;
+        var setupEventsQueue = this.setupEventsQueue;
+        this.setupEventsQueue = [];
+        this.doSetupEvents(setupEventsQueue);
     };
-;;; var targetMsg;
-    var found = false;
-    if ( ! inNodes) {
-;;;     targetMsg = 'document';
-        found = true;
-    } else {
-;;;     targetMsg = 'nodes subtrees ';
-        for (var i=0; i<inNodes.length; i++) {
-            var node = inNodes[i];
-            if (node.nodeType == 1) {
-                if (! found) {
-                    found = true;
-;;;             } else {
-;;;                 targetMsg += ', '; 
+
+    this.doSetupEvents = function(inNodes) {
+        var self = this;
+        var deferredEventsSetup = function() {
+            self._setupEvents(inNodes);
+        };
+;;;     var targetMsg;
+        var found = false;
+        if ( ! inNodes) {
+;;;         targetMsg = 'document';
+            found = true;
+        } else {
+;;;         targetMsg = 'nodes subtrees ';
+            for (var i=0; i<inNodes.length; i++) {
+                var node = inNodes[i];
+                if (node.nodeType == 1) {
+                    if (! found) {
+                        found = true;
+;;;                 } else {
+;;;                     targetMsg += ', '; 
+                    }
+;;;                 targetMsg += '[' + node.tagName.toLowerCase() + ']';
                 }
-;;;             targetMsg += '[' + node.tagName.toLowerCase() + ']';
             }
         }
-    }
-    if (found) {
-        var remark = '';
-;;;     remark += 'Setup of events for ' + targetMsg;
-        this.bindScheduler.addPre(deferredEventsSetup, remark);
-    }
-};
-
-ku.Engine.prototype._setupEvents = function(inNodes) {
-    // Decide phase. 1=initial, 2=insertion.
-    var phase;
-    if (typeof(inNodes) == 'undefined') {
-        phase = 1;
-    } else {
-        phase = 2;
-    }
-    this.binderInfoRegistry.startBindingPhase();
-;;; kukit.log('Selection of HTML nodes starts.');
-    var rules = this.getRules();
-    var ruletable = new kukit.rd.RuleTable(this.loadScheduler);
-    for (var y=0; y < rules.length; y++) {
-        rules[y].mergeForSelectedNodes(ruletable, phase, inNodes);
-    }
-;;; kukit.log('Binding of document starts.');
-    if (phase == 1) {
-        this.documentRules.bindall(phase);
-    }
-    // finally bind the merged events
-;;; kukit.log('Binding of HTML nodes starts.');
-    ruletable.bindall(phase);
-
-    // ... and do the actual binding. 
-    this.binderInfoRegistry.processBindingEvents();
-};
-
+        if (found) {
+            var remark = '';
+;;;         remark += 'Setup of events for ' + targetMsg;
+            this.bindScheduler.addPre(deferredEventsSetup, remark);
+        }
+    };
 
+    this._setupEvents = function(inNodes) {
+        // Decide phase. 1=initial, 2=insertion.
+        var phase;
+        if (typeof(inNodes) == 'undefined') {
+            phase = 1;
+        } else {
+            phase = 2;
+        }
+        this.binderInfoRegistry.startBindingPhase();
+;;;     kukit.log('Selection of HTML nodes starts.');
+        var rules = this.getRules();
+        var ruletable = new kukit.rd.RuleTable(this.loadScheduler);
+        for (var y=0; y < rules.length; y++) {
+            rules[y].mergeForSelectedNodes(ruletable, phase, inNodes);
+        }
+;;;     kukit.log('Binding of document starts.');
+        if (phase == 1) {
+            this.documentRules.bindall(phase);
+        }
+        // finally bind the merged events
+;;;     kukit.log('Binding of HTML nodes starts.');
+        ruletable.bindall(phase);
 
+        // ... and do the actual binding. 
+        this.binderInfoRegistry.processBindingEvents();
+    };
 
-ku.Engine.prototype.initializeRules = function() {
-    if (window.kukitRulesInitializing || window.kukitRulesInitialized) {
-        // Refuse to initialize a second time.
-;;;     kukit.log('[initializeRules] is called twice.');
-        return;
-    }
-;;; kukit.log('Initializing kinetic stylesheets.');
-    // Succesful initialization. At the moment the engine is kept
-    // as a global variable, but this needs refinement in the future.
-    kukit.engine = this;
-    window.kukitRulesInitializing = true;
-    // load the rulesheets
-    var rulelinks = this.getRuleSheetLinks();
-;;; kukit.log("Count of kinetic stylesheet links: " + rulelinks.length);
-    for (var i=0; i<rulelinks.length; i++) {
-        var rulelink = rulelinks[i];
-        var ruleprocessor = this.createRuleProcessor(rulelink);
-        if (ruleprocessor) {
-;;;         var ts_start = (new Date()).valueOf();
-            ruleprocessor.load();
-;;;         var ts_loaded = (new Date()).valueOf();
-            ruleprocessor.parse();
-;;;         var ts_end = (new Date()).valueOf();
-;;;         var msg = "Finished loading and processing " + rulelink.href;
-;;;         msg += " resource type " + rulelink.res_type;
-;;;         msg += ' in ' + (ts_loaded - ts_start) + ' + ';
-;;;         msg += (ts_end - ts_loaded) + ' ms.';
-;;;         kukit.log(msg);
+    this.initializeRules = function() {
+        if (window.kukitRulesInitializing || window.kukitRulesInitialized) {
+            // Refuse to initialize a second time.
+;;;         kukit.log('[initializeRules] is called twice.');
+            return;
         }
-    }
-;;; try {
-        this.setupEvents();
-;;; } catch(e) {
-;;;     // Event setup errors are logged.
-;;;     if (e.name == 'RuleMergeError' || e.name == 'EventBindError') {
-;;;        var msg = 'Events setup - ' + e.toString();
-;;;         // Log the message
-;;;         kukit.logFatal(msg);
-;;;         // and throw it...
- ;;;         throw new Error(msg);
-;;;     } else {
-;;;         throw e;
+;;;     kukit.log('Initializing kinetic stylesheets.');
+        // Succesful initialization. At the moment the engine is kept
+        // as a global variable, but this needs refinement in the future.
+        kukit.engine = this;
+        window.kukitRulesInitializing = true;
+        // load the rulesheets
+        var rulelinks = this.getRuleSheetLinks();
+;;;     kukit.log("Count of kinetic stylesheet links: " + rulelinks.length);
+        for (var i=0; i<rulelinks.length; i++) {
+            var rulelink = rulelinks[i];
+            var ruleprocessor = this.createRuleProcessor(rulelink);
+            if (ruleprocessor) {
+;;;             var ts_start = (new Date()).valueOf();
+                ruleprocessor.load();
+;;;             var ts_loaded = (new Date()).valueOf();
+                ruleprocessor.parse();
+;;;             var ts_end = (new Date()).valueOf();
+;;;             var msg = "Finished loading and processing " + rulelink.href;
+;;;             msg += " resource type " + rulelink.res_type;
+;;;             msg += ' in ' + (ts_loaded - ts_start) + ' + ';
+;;;             msg += (ts_end - ts_loaded) + ' ms.';
+;;;             kukit.log(msg);
+            }
+        }
+;;;     try {
+            this.setupEvents();
+;;;     } catch(e) {
+;;;         // Event setup errors are logged.
+;;;         if (e.name == 'RuleMergeError' || e.name == 'EventBindError') {
+;;;            var msg = 'Events setup - ' + e.toString();
+;;;             // Log the message
+;;;             kukit.logFatal(msg);
+;;;             // and throw it...
+;;;             throw new Error(msg);
+;;;         } else {
+;;;             throw e;
+;;;         }
 ;;;     }
-;;; }
-    window.kukitRulesInitializing = false;
-    window.kukitRulesInitialized = true;
+        window.kukitRulesInitializing = false;
+        window.kukitRulesInitialized = true;
+    };
 };
 
 
+
 /* XXX deprecated methods, to be removed asap 
  * (this was used from the plone plugin only, 
  * to allow the event-registration.js hook)


More information about the Kukit-checkins mailing list