Author: gotcha
Date: Thu Nov 22 23:12:38 2007
New Revision: 48957

Modified:
   kukit/kukit.js/branch/finish-closures/kukit/kukit.js
   kukit/kukit.js/branch/finish-closures/kukit/utils.js
Log:
closures for kukit and kukit.ut namespaces

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        Thu Nov 22 
23:12:38 2007
@@ -17,14 +17,18 @@
 * 02111-1307, USA.
 */
 
-kukit.isDevelMode = false;
-;;; kukit.isDevelMode = true;
+kukit = new function() {   /// MODULE START
+
+var ku = this;
+
+ku.isDevelMode = false;
+;;; ku.isDevelMode = true;
 
 
 /*
 * class Engine
 */
-kukit.Engine = function() {
+ku.Engine = function() {
     this.baseUrl = this.calculateBase();
     this.documentRules = new kukit.rd.MethodTable();
     // table from res_type to rule processor
@@ -47,7 +51,7 @@
 
 };
 
-kukit.Engine.prototype.calculateBase = function() {
+ku.Engine.prototype.calculateBase = function() {
     var base = '';
     try {
         var _dummy = document;
@@ -82,11 +86,11 @@
     return base;
 };
 
-kukit.Engine.prototype.getRuleSheetLinks = function() {
+ku.Engine.prototype.getRuleSheetLinks = function() {
     var nodes = document.getElementsByTagName("link");
     var results = [];
     for (var i=0; i<nodes.length; i++) {
-        if (kukit.isKineticStylesheet(nodes[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')) 
{
@@ -94,14 +98,14 @@
 ;;;         } else {
 ;;;         throw kukit.err.explicitError("rel type is not text/css or 
text/kss");
             }
-            var newRuleLink = new kukit.RuleSheetLink(nodes[i].href, res_type);
+            var newRuleLink = new _RuleSheetLink(nodes[i].href, res_type);
             results[results.length] = newRuleLink;
         }
     }
     return results;
 };
 
-kukit.Engine.prototype.createRuleProcessor = function(rulelink) {
+ku.Engine.prototype.createRuleProcessor = function(rulelink) {
     var ruleProcessorClass = this._ruleProcessorClasses[rulelink.res_type];
     if (ruleProcessorClass) {
 ;;;     var msg = "Start loading and processing " + rulelink.href;
@@ -119,7 +123,7 @@
 };
 
 
-kukit.Engine.prototype.getRules = function() {
+ku.Engine.prototype.getRules = function() {
     var rules = new Array();
     var ruleProcessors = this._ruleProcessors
     for (var j=0; j<ruleProcessors.length; j++) {
@@ -131,11 +135,11 @@
     return rules;
 }
 
-kukit.Engine.prototype.getRuleProcessors = function() {
+ku.Engine.prototype.getRuleProcessors = function() {
     return this._ruleProcessors
 }
 
-kukit.isKineticStylesheet = function(node) {
+var _isKineticStylesheet = function(node) {
     var rel = node.rel;
     if (rel=="kinetic-stylesheet") {
         return true;
@@ -150,7 +154,7 @@
     return false;
 };
 
-kukit.Engine.prototype.setupEvents = function(inNodes) {
+ku.Engine.prototype.setupEvents = function(inNodes) {
     if (this.setupEventsInProgress) {
         // remember them
         this.setupEventsQueue = this.setupEventsQueue.concat(inNodes);
@@ -160,18 +164,18 @@
     }
 };
 
-kukit.Engine.prototype.beginSetupEventsCollection = function() {
+ku.Engine.prototype.beginSetupEventsCollection = function() {
     this.setupEventsInProgress = true;
 };
 
-kukit.Engine.prototype.finishSetupEventsCollection = function() {
+ku.Engine.prototype.finishSetupEventsCollection = function() {
     this.setupEventsInProgress = false;
     var setupEventsQueue = this.setupEventsQueue;
     this.setupEventsQueue = [];
     this.doSetupEvents(setupEventsQueue);
 };
 
-kukit.Engine.prototype.doSetupEvents = function(inNodes) {
+ku.Engine.prototype.doSetupEvents = function(inNodes) {
     var self = this;
     var deferredEventsSetup = function() {
         self._setupEvents(inNodes);
@@ -202,7 +206,7 @@
     }
 };
 
-kukit.Engine.prototype._setupEvents = function(inNodes) {
+ku.Engine.prototype._setupEvents = function(inNodes) {
     // Decide phase. 1=initial, 2=insertion.
     var phase;
     if (typeof(inNodes) == 'undefined') {
@@ -232,7 +236,7 @@
 
 
 
-kukit.Engine.prototype.initializeRules = function() {
+ku.Engine.prototype.initializeRules = function() {
     if (window.kukitRulesInitializing || window.kukitRulesInitialized) {
         // Refuse to initialize a second time.
 ;;;     kukit.log('[initializeRules] is called twice.');
@@ -286,7 +290,7 @@
  * to allow the event-registration.js hook)
  */
 
-kukit.initializeRules = function() {
+ku.initializeRules = function() {
 ;;; var msg = '[kukit.initializeRules] is deprecated,';
 ;;; msg += 'use [kukit.bootstrap] instead !';
 ;;; kukit.logWarning(msg);
@@ -294,16 +298,17 @@
 };
 
 /*
-* class RuleSheetLink
+* class _RuleSheetLink
 */
-kukit.RuleSheetLink = function(href, res_type) {
+var _RuleSheetLink = function(href, res_type) {
     this.href = href;
     this.res_type = res_type;
 };
 
-kukit.bootstrap = function() {
-;;; kukit.log('Engine instantiated.');
+ku.bootstrap = function() {
+;;; kukit.log('Instantiate engine.');
     var engine = new kukit.Engine();
+;;; kukit.log('Engine instantiated.');
     // Successful initializeRules will store the engine as kukit.engine. 
     // Subsequent activations will not delete the already set up engine.
     // Subsequent activations may happen, if more event handlers are set up,
@@ -311,7 +316,7 @@
     engine.initializeRules();
 };
 
-kukit.bootstrapFromDOMLoad = function() {
+ku.bootstrapFromDOMLoad = function() {
 ;;; kukit.log('Engine instantiated in [DOMLoad].');
     var engine = new kukit.Engine();
     // Successful initializeRules will store the engine as kukit.engine. 
@@ -322,7 +327,5 @@
     engine.initializeRules();
 };
 
-if (typeof(window) != 'undefined') {
-    kukit.ut.registerEventListener(window, "load", kukit.bootstrap);
-}
+}();                              /// MODULE END
 

Modified: kukit/kukit.js/branch/finish-closures/kukit/utils.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/utils.js        (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/utils.js        Thu Nov 22 
23:12:38 2007
@@ -146,44 +146,46 @@
 
 /* utilities */
 
-kukit.ut = {};
+kukit.ut = new function() {   /// MODULE START
+
+var ut = this;
 
 
 /* 
 * class FifoQueue
 */
-kukit.ut.FifoQueue = function () {
+ut.FifoQueue = function () {
     this.reset();
 };
 
-kukit.ut.FifoQueue.prototype.reset = function() {
+ut.FifoQueue.prototype.reset = function() {
     this.elements = new Array();
 };
 
-kukit.ut.FifoQueue.prototype.push = function(obj) {
+ut.FifoQueue.prototype.push = function(obj) {
     this.elements.push(obj);
 };
 
-kukit.ut.FifoQueue.prototype.pop = function() {
+ut.FifoQueue.prototype.pop = function() {
     return this.elements.shift();
 };
 
-kukit.ut.FifoQueue.prototype.empty = function() {
+ut.FifoQueue.prototype.empty = function() {
     return ! this.elements.length;
 };
 
-kukit.ut.FifoQueue.prototype.size = function() {
+ut.FifoQueue.prototype.size = function() {
     return this.elements.length;
 };
 
-kukit.ut.FifoQueue.prototype.front = function() {
+ut.FifoQueue.prototype.front = function() {
     return this.elements[0];
 };
 
 /*
 * class SortedQueue
 */
-kukit.ut.SortedQueue = function (comparefunc) {
+ut.SortedQueue = function (comparefunc) {
     // comparefunc(left, right) determines the order by returning 
     // -1 if left should occur before right,
     // +1 if left should occur after right or 
@@ -196,7 +198,7 @@
     this.reset();
 };
 
-kukit.ut.SortedQueue.prototype.comparefunc = function(a, b) {
+ut.SortedQueue.prototype.comparefunc = function(a, b) {
     if (a < b) {
         return -1;
     } else if (a > b) {
@@ -206,11 +208,11 @@
     }
 };
 
-kukit.ut.SortedQueue.prototype.reset = function() {
+ut.SortedQueue.prototype.reset = function() {
     this.elements = new Array();
 };
 
-kukit.ut.SortedQueue.prototype.push = function(obj) {
+ut.SortedQueue.prototype.push = function(obj) {
     // Find the position of the object.
     var i = 0;
     var length = this.elements.length;
@@ -221,33 +223,33 @@
     this.elements.splice(i, 0, obj);
 };
 
-kukit.ut.SortedQueue.prototype.pop = function() {
+ut.SortedQueue.prototype.pop = function() {
     // takes minimal element
     return this.elements.shift();
 };
 
-kukit.ut.SortedQueue.prototype.popn = function(n) {
+ut.SortedQueue.prototype.popn = function(n) {
     // takes first n minimal element
     return this.elements.splice(0, n);
 };
 
-kukit.ut.SortedQueue.prototype.empty = function() {
+ut.SortedQueue.prototype.empty = function() {
     return ! this.elements.length;
 };
 
-kukit.ut.SortedQueue.prototype.size = function() {
+ut.SortedQueue.prototype.size = function() {
     return this.elements.length;
 };
 
-kukit.ut.SortedQueue.prototype.get = function(n) {
+ut.SortedQueue.prototype.get = function(n) {
     return this.elements[n];
 };
 
-kukit.ut.SortedQueue.prototype.front = function() {
+ut.SortedQueue.prototype.front = function() {
     return this.elements[0];
 };
 
-kukit.ut.evalBool = function(value, errname) {
+ut.evalBool = function(value, errname) {
     if (value == 'true' || value == 'True' || value == '1') {
         value = true;
     } else if (value == 'false' || value == 'False' || value == '0'
@@ -259,7 +261,7 @@
     return value;
 };
 
-kukit.ut.evalInt = function(value, errname) {
+ut.evalInt = function(value, errname) {
 ;;;     try {
         value = parseInt(value);
 ;;;     } catch(e) {
@@ -268,7 +270,7 @@
     return value;
 };
 
-kukit.ut.evalList = function(value, errname) {
+ut.evalList = function(value, errname) {
 ;;; try {
         // remove whitespace from beginning, end
         value = value.replace(/^ +/, '');
@@ -293,7 +295,7 @@
 *
 * for repeating or one time timing
 */
-kukit.ut.TimerCounter = function(delay, func, restart) {
+ut.TimerCounter = function(delay, func, restart) {
     this.delay = delay;
     this.func = func;
     if (typeof(restart) == 'undefined') {
@@ -303,7 +305,7 @@
     this.timer = null;
 };
 
-kukit.ut.TimerCounter.prototype.start = function() {
+ut.TimerCounter.prototype.start = function() {
     if (this.timer) {
 ;;;     kukit.E = 'Timer already started.';
 
@@ -316,7 +318,7 @@
     this.timer = setTimeout(func, this.delay);
 };
 
-kukit.ut.TimerCounter.prototype.timeout = function() {
+ut.TimerCounter.prototype.timeout = function() {
     // Call the event action
     this.func();
     // Restart the timer
@@ -326,7 +328,7 @@
     }
 };
 
-kukit.ut.TimerCounter.prototype.clear = function() {
+ut.TimerCounter.prototype.clear = function() {
     if (this.timer) {
         window.clearTimeout(this.timer);
         this.timer = null;
@@ -337,13 +339,13 @@
 /*
 * class Scheduler
 */
-kukit.ut.Scheduler = function(func) {
+ut.Scheduler = function(func) {
     this.func = func;
     this.timer = null;
     this.nextWake = null;
 };
 
-kukit.ut.Scheduler.prototype.setNextWake = function(ts) {
+ut.Scheduler.prototype.setNextWake = function(ts) {
     // Sets wakeup time, null clears
     if (this.nextWake) {
         this.clear();
@@ -365,7 +367,7 @@
     }
 };
 
-kukit.ut.Scheduler.prototype.setNextWakeAtLeast = function(ts) {
+ut.Scheduler.prototype.setNextWakeAtLeast = function(ts) {
     // Sets wakeup time, unless it would wake up later than the
     // currently set timeout. Null clears the timer.
     if (! ts || ! this.nextWake || ts < this.nextWake) {
@@ -376,7 +378,7 @@
     }
 };
 
-kukit.ut.Scheduler.prototype.timeout = function() {
+ut.Scheduler.prototype.timeout = function() {
     // clear the timer
     this.timer = null;
     this.nextWake = null;
@@ -385,7 +387,7 @@
 };
 
 
-kukit.ut.Scheduler.prototype.clear = function() {
+ut.Scheduler.prototype.clear = function() {
     if (this.nextWake) {
         window.clearTimeout(this.timer);
         this.timer = null;
@@ -398,22 +400,22 @@
 *
 * Scheduler for serializing bind and load procedures
 */
-kukit.ut.SerializeScheduler = function() {
+ut.SerializeScheduler = function() {
     this.items = [];
     this.lock = false;
 };
 
-kukit.ut.SerializeScheduler.prototype.addPre = function(func, remark) {
+ut.SerializeScheduler.prototype.addPre = function(func, remark) {
     this.items.push({func: func, remark: remark});
     this.execute();
 };
 
-kukit.ut.SerializeScheduler.prototype.addPost = function(func, remark) {
+ut.SerializeScheduler.prototype.addPost = function(func, remark) {
     this.items.unshift({func: func, remark: remark});
     this.execute();
 };
 
-kukit.ut.SerializeScheduler.prototype.execute = function() {
+ut.SerializeScheduler.prototype.execute = function() {
     if (! this.lock) {
         this.lock = true;
         while (true) {
@@ -442,7 +444,7 @@
 
 /* extracted from Plone */
 // cross browser function for registering event handlers
-kukit.ut.registerEventListener = function(elem, event, func) {
+ut.registerEventListener = function(elem, event, func) {
     if (elem.addEventListener) {
         elem.addEventListener(event, func, false);
         return true;
@@ -454,22 +456,27 @@
     return false;
 };
 
+if (typeof(window) != 'undefined') {
+    ut.registerEventListener(window, "load", kukit.bootstrap);
+}
 
 /* collecting keys-values into a dict or into a tuple list */
 
-kukit.ut.DictCollector = function() {
+ut.DictCollector = function() {
     this.result = {};
 };
 
-kukit.ut.DictCollector.prototype.add = function(key, value) {
+ut.DictCollector.prototype.add = function(key, value) {
     this.result[key] = value;
 };
 
-kukit.ut.TupleCollector = function() {
+ut.TupleCollector = function() {
     this.result = [];
 };
 
-kukit.ut.TupleCollector.prototype.add = function(key, value) {
+ut.TupleCollector.prototype.add = function(key, value) {
     this.result.push([key, value]);
 };
 
+}();                              /// MODULE END
+
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to