[KSS-checkins] r46856 - kukit/kukit.js/trunk/kukit

gotcha at codespeak.net gotcha at codespeak.net
Tue Sep 25 09:05:20 CEST 2007


Author: gotcha
Date: Tue Sep 25 09:05:19 2007
New Revision: 46856

Modified:
   kukit/kukit.js/trunk/kukit/errors.js
   kukit/kukit.js/trunk/kukit/eventreg.js
   kukit/kukit.js/trunk/kukit/forms.js
Log:
more closures

Modified: kukit/kukit.js/trunk/kukit/errors.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/errors.js	(original)
+++ kukit/kukit.js/trunk/kukit/errors.js	Tue Sep 25 09:05:19 2007
@@ -19,6 +19,8 @@
 
 kukit.err = new function () {        /// MODULE START
 
+var err = this;
+
 /* 
 * Exception factory 
 *
@@ -104,27 +106,27 @@
 
 /* Protects a function */
 
-;;; this.explicitError = function(errorcommand){
+;;; err.explicitError = function(errorcommand){
 ;;;    var kw = {'errorcommand':errorcommand};
 ;;;    var message = 'Explicit error';
 ;;;    return setErrorInfo(null, 'ExplicitError', message, kw);
 ;;; };
 
 
-;;; this.responseParsingError = function(message){
+;;; err.responseParsingError = function(message){
 ;;;    return setErrorInfo(null, 'ResponseParsingError', message);
 ;;; };
 
-;;; this.ruleMergeError = function(message){
+;;; err.ruleMergeError = function(message){
 ;;;    return setErrorInfo(null, 'RuleMergeError', message);
 ;;; };
 
-;;; this.kssSelectorError = function(message){
+;;; err.kssSelectorError = function(message){
 ;;;    return setErrorInfo(null, 'RuleMergeError', message);
 ;;; };
 
 
-;;; this.parsingError = function(message, cursor){
+;;; err.parsingError = function(message, cursor){
 ;;;    var kw = {}
 ;;;    if (cursor) {
 ;;;         kw.errpos = cursor.pos;
@@ -142,13 +144,13 @@
 
 /* Exceptions that re-throw (annotate) an already caught error */
 
-;;; this.commandExecutionError = function(e, command){
+;;; err.commandExecutionError = function(e, command){
 ;;;    var message = 'Command [' + command.name + '] failed';
 ;;;    return setErrorInfo(e, 'CommandExecutionError', message);
 ;;; };
 
 
-;;; this.eventBindError = function(e, eventNames, eventNamespaces){
+;;; err.eventBindError = function(e, eventNames, eventNamespaces){
 ;;;    var kw = {};
 ;;;    kw.eventNames = eventNames;
 ;;;    kw.eventNamespaces = eventNamespaces;
@@ -158,19 +160,19 @@
 ;;; };
 
 
-;;; this.undefinedEventError = function(e, message){
+;;; err.undefinedEventError = function(e, message){
 ;;;    return setErrorInfo(e, 'UndefinedEventError', message);
 ;;; };
 
 
-;;; this.kssParsingError = function(e, url){
+;;; err.kssParsingError = function(e, url){
 ;;;    var kw = {url: url}
 ;;;    var message = 'Error parsing KSS at ' + url;
 ;;;    return setErrorInfo(e, 'KssParsingError', message, kw);
 ;;; };
 
 
-;;; this.eventSetupError = function(e, message){
+;;; err.eventSetupError = function(e, message){
 ;;;    var message = 'Error setting up events';
 ;;;    return setErrorInfo(e, 'EventSetupError', message);
 ;;; };

Modified: kukit/kukit.js/trunk/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/eventreg.js	(original)
+++ kukit/kukit.js/trunk/kukit/eventreg.js	Tue Sep 25 09:05:19 2007
@@ -17,14 +17,15 @@
 * 02111-1307, USA.
 */
 
-kukit.er = {};
+kukit.er = new function() {   /// MODULE START
 
+var er = this;
 
-kukit.er.eventClassCounter = 0;
+var _eventClassCounter = 0;
 
 /*
 *
-* class EventRegistry
+* class _EventRegistry
 *
 * available for plugin registration
 *
@@ -38,7 +39,7 @@
 *     func must be a class (constructor) function, this is the class that
 *           implements the binder.
 */
-kukit.er.EventRegistry = function () {
+var _EventRegistry = function () {
     this.content = {};
     this.classes = {};
     this.eventSets = [];
@@ -46,10 +47,10 @@
 
 /* binder registration */
 
-kukit.er.EventRegistry.prototype.registerBinder = function(className, func) {
+_EventRegistry.prototype.registerBinder = function(className, func) {
     if (typeof(func) == 'undefined') {
 ;;;     kukit.E = 'func argument is mandatory when registering an event';
-;;;     kukit.E += ' binder (EventRegistry.registerBinder).';
+;;;     kukit.E += ' binder (_EventRegistry.registerBinder).';
         throw new Error(kukit.E);
     }
     if (this.classes[className]) {
@@ -60,16 +61,16 @@
     
     }
     // Decorate and store the class
-    kukit.er.decorateEventBinderClass(func);
+    decorateEventBinderClass(func);
     this.classes[className] = func;
 };
 
-kukit.er.EventRegistry.prototype.existsBinder = function(className) {
+_EventRegistry.prototype.existsBinder = function(className) {
     var func = this.classes[className];
     return (typeof(func) != 'undefined');
 };
 
-kukit.er.EventRegistry.prototype.getBinder = function(className) {
+_EventRegistry.prototype.getBinder = function(className) {
     var func = this.classes[className];
     if (! func) {
         // not found
@@ -81,25 +82,25 @@
 
 /* events (methods) registration  helpers (not to be called directly) */
 
-kukit.er.EventRegistry.prototype._register = 
+_EventRegistry.prototype._register = 
     function(namespace, eventName, klass,
         bindMethodName, defaultActionMethodName, iterName) {
     if (typeof(defaultActionMethodName) == 'undefined') {
-;;;     kukit.E = 'Missing arguments when calling [EventRegistry.register].';
+;;;     kukit.E = 'Missing arguments when calling [_EventRegistry.register].';
         throw new Error(kukit.E);
     }
     // Find out the class name. (Not specified now.)
     var className = klass.prototype.__className__;
     if (typeof(className) == 'undefined') {
         // Create a className, and register it too.
-        className = '' + kukit.er.eventClassCounter;
-        kukit.er.eventClassCounter += 1;
+        className = '' + _eventClassCounter;
+        _eventClassCounter += 1;
         this.registerBinder(className, klass);
         klass.prototype.__className__ = className;
     }
     if (!eventName) {
 ;;;     kukit.E = '[eventName] argument cannot be empty when registering';
-;;;     kukit.E += ' an event with [EventRegistry.register].';
+;;;     kukit.E += ' an event with [_EventRegistry.register].';
         throw new Error(kukit.E);
     }
     var key = this._getKey(namespace, eventName);
@@ -110,25 +111,25 @@
         }
 ;;;     kukit.E = 'Attempt to register key [' + key;
 ;;;     kukit.E += '] twice when registering';
-;;;     kukit.E += ' an event with [EventRegistry.register].';
+;;;     kukit.E += ' an event with [_EventRegistry.register].';
         throw new Error(kukit.E);
     }
     // check bindMethodName and defaultActionMethodName
     if (bindMethodName && ! klass.prototype[bindMethodName]) {
-;;;     kukit.E = 'In EventRegistry.register bind method [' + bindMethodName;
+;;;     kukit.E = 'In _EventRegistry.register bind method [' + bindMethodName;
 ;;;     kukit.E += '] is undefined for event [' + eventName;
 ;;;     kukit.E += '] namespace [' + namespace + '].';
         throw new Error(kukit.E);
     }
     if (defaultActionMethodName && ! klass.prototype[defaultActionMethodName]) {
-;;;     kukit.E = 'In EventRegistry.register default action method [';
+;;;     kukit.E = 'In _EventRegistry.register default action method [';
 ;;;     kukit.E += defaultActionMethodName + '] is undefined for event [';
 ;;;     kukit.E += eventName + '] namespace [' + namespace + '].';
         throw new Error(kukit.E);
     }
     // check the iterator.
-    if  (! kukit.er.getBindIterator(iterName)) {
-;;;     kukit.E = 'In EventRegistry.register unknown bind iterator [';
+    if  (! er.getBindIterator(iterName)) {
+;;;     kukit.E = 'In _EventRegistry.register unknown bind iterator [';
 ;;;     kukit.E += iterName + '].';
         throw new Error(kukit.E);
     }
@@ -143,7 +144,7 @@
 
 /* events (methods) binding [ForAll] registration */
 
-kukit.er.EventRegistry.prototype._registerEventSet =
+_EventRegistry.prototype._registerEventSet =
     function(namespace, names, iterName, bindMethodName) {
     // At this name the values should be checked already. so this should
     // be called _after_ _register.
@@ -157,7 +158,7 @@
 
 /* there are the actual registration methods, to be called from plugins */
 
-kukit.er.EventRegistry.prototype.register =
+_EventRegistry.prototype.register =
     function(namespace, eventName, klass, bindMethodName,
         defaultActionMethodName) {
     this._register(namespace, eventName, klass, bindMethodName,
@@ -166,7 +167,7 @@
         bindMethodName);
 };
 
-kukit.er.EventRegistry.prototype.registerForAllEvents =
+_EventRegistry.prototype.registerForAllEvents =
     function(namespace, eventNames, klass,
         bindMethodName, defaultActionMethodName, iterName) {
     if (typeof(eventNames) == 'string') {
@@ -180,24 +181,24 @@
     this._registerEventSet(namespace, eventNames, iterName, bindMethodName);
 };
 
-kukit.er.EventRegistry.prototype._getKey = function(namespace, eventName) {
+_EventRegistry.prototype._getKey = function(namespace, eventName) {
     if (namespace == null) {
         namespace = '';
     } else if (namespace.split('-') > 1) {
-;;;     kukit.E = 'In [EventRegistry.register], [namespace] cannot have';
+;;;     kukit.E = 'In [_EventRegistry.register], [namespace] cannot have';
 ;;;     kukit.E += 'dashes.';
         throw new Error(kukit.E);
     }
     return namespace + '-' + eventName;
 };
 
-kukit.er.EventRegistry.prototype.exists = function(namespace, eventName) {
+_EventRegistry.prototype.exists = function(namespace, eventName) {
     var key = this._getKey(namespace, eventName);
     var entry = this.content[key];
     return (typeof(entry) != 'undefined');
 };
 
-kukit.er.EventRegistry.prototype.get = function(namespace, eventName) {
+_EventRegistry.prototype.get = function(namespace, eventName) {
     var key = this._getKey(namespace, eventName);
     var entry = this.content[key];
     if (typeof(entry) == 'undefined') {
@@ -213,15 +214,14 @@
     return entry;
 };
 
-kukit.eventsGlobalRegistry = new kukit.er.EventRegistry();
-
+kukit.eventsGlobalRegistry = new _EventRegistry();
 
 /* XXX deprecated methods, to be removed asap */
 
-kukit.er.eventRegistry = {};
-kukit.er.eventRegistry.register = function(namespace, eventName, klass,
+var _eventRegistry = {};
+_eventRegistry.register = function(namespace, eventName, klass,
         bindMethodName, defaultActionMethodName) {
-;;; var msg = 'Deprecated kukit.er.eventRegistry.register,';
+;;; var msg = 'Deprecated _eventRegistry.register,';
 ;;; msg += ' use kukit.eventsGlobalRegistry.register instead ! [';
 ;;; msg += namespace + '-' + eventName + '].';
 ;;; kukit.logWarning(msg);
@@ -297,7 +297,7 @@
 * so we create a new oper below
 */
 
-kukit.er.EventBinder__continueEvent__ =
+var _EventBinder__continueEvent__ =
     function(name, node, defaultParameters) {
     // Trigger a continuation event bound to a given state instance, given node
     // (or on document, if node = null)
@@ -346,7 +346,7 @@
 ;;; kukit.logDebug('Continuation event [' + name + '] executed on same node.');
 };
 
-kukit.er.EventBinder__continueEvent_allNodes__ =
+var _EventBinder__continueEvent_allNodes__ =
     function(name, defaultParameters) {
     // Trigger an event bound to a given state instance, on all nodes.
     // (or on document, if node = null)
@@ -372,21 +372,28 @@
 ;;; kukit.logDebug('Event [' + name + '] executed on ' + executed + ' nodes.');
 };
 
-kukit.er.EventBinder_makeFuncToBind = function(name, node) {
-   var executor = new kukit.er.LateBinder(this, name, node);
+var _EventBinder_makeFuncToBind = function(name, node) {
+   var executor = new er._LateBinder(this, name, node);
    return function() {
        executor.executeActions();
    };
 };
 
-kukit.er.LateBinder = function(binderInstance, name, node) {
+/*
+*
+* class _LateBinder
+*
+* postpone binding of actions until called first time
+*
+*/
+var _LateBinder = function(binderInstance, name, node) {
     this.binderInstance = binderInstance;
     this.name = name;
     this.node = node;
     this.bound = null;
 };
 
-kukit.er.LateBinder.prototype.executeActions = function() {
+_LateBinder.prototype.executeActions = function() {
     if (! this.bound) {
 ;;;        var msg = 'Attempt of late binding for event [' + this.name;
 ;;;        msg += '], node [' + this.node.nodeName + '].';
@@ -413,7 +420,7 @@
     this.bound();
 };        
 
-kukit.er.EventBinder_triggerEvent = function(name, oper) {
+var _EventBinder_triggerEvent = function(name, oper) {
     // Private. Called from __continueEvent__ or from main event execution.
     oper.binderInstance = this;
     if (oper.eventRule) {
@@ -441,7 +448,7 @@
 
 /* (default) method call handling */
 
-kukit.er.EventBinder_callMethod = function(namespace, name, oper, methodName) {
+var _EventBinder_callMethod = function(namespace, name, oper, methodName) {
     // hidden method for calling just a method and checking that is exists.
     // (called from oper)
     var method = this[methodName];
@@ -456,13 +463,13 @@
     method.call(this, name, oper);
 };
 
-kukit.er.decorateEventBinderClass = function(cls) {
-    cls.prototype.__continueEvent__ = kukit.er.EventBinder__continueEvent__;
+var decorateEventBinderClass = function(cls) {
+    cls.prototype.__continueEvent__ = _EventBinder__continueEvent__;
     cls.prototype.__continueEvent_allNodes__ =
-        kukit.er.EventBinder__continueEvent_allNodes__;
-    cls.prototype._EventBinder_triggerEvent = kukit.er.EventBinder_triggerEvent;
-    cls.prototype._EventBinder_callMethod = kukit.er.EventBinder_callMethod;
-    cls.prototype.__makeFuncToBind__ = kukit.er.EventBinder_makeFuncToBind;
+        _EventBinder__continueEvent_allNodes__;
+    cls.prototype._EventBinder_triggerEvent = _EventBinder_triggerEvent;
+    cls.prototype._EventBinder_callMethod = _EventBinder_callMethod;
+    cls.prototype.__makeFuncToBind__ = _EventBinder_makeFuncToBind;
 };
 
 /* Event instance registry 
@@ -473,11 +480,11 @@
 *
 */
 
-kukit.er.BinderInfoRegistry = function () {
+er.BinderInfoRegistry = function () {
     this.info = {};
 };
 
-kukit.er.BinderInfoRegistry.prototype.getOrCreateBinderInfo =
+er.BinderInfoRegistry.prototype.getOrCreateBinderInfo =
     function (id, className, namespace) {
     // Get or create the event.
     var binderInfo = this.info[id];
@@ -489,7 +496,7 @@
         var binder = kukit.eventsGlobalRegistry.getBinder(className);
         var binderInstance = new binder();
         
-        binderInfo = this.info[id] = new kukit.er.BinderInfo(binderInstance);
+        binderInfo = this.info[id] = new _BinderInfo(binderInstance);
 
         // decorate it with id and class
         binderInstance.__binderId__ = id;
@@ -508,7 +515,7 @@
     return binderInfo;
 };
 
-kukit.er.BinderInfoRegistry.prototype.getBinderInfoById = function (id) {
+er.BinderInfoRegistry.prototype.getBinderInfoById = function (id) {
     // Get an event.
     var binderInfo = this.info[id];
     if (typeof(binderInfo) == 'undefined') {
@@ -518,7 +525,7 @@
     return binderInfo;
 };
 
-kukit.er.BinderInfoRegistry.prototype.getSingletonBinderInfoByName =
+er.BinderInfoRegistry.prototype.getSingletonBinderInfoByName =
     function (namespace, name) {
     //Get className
     var className = kukit.eventsGlobalRegistry.get(namespace, name).className;
@@ -533,7 +540,7 @@
     return binderInfo;
 };
 
-kukit.er.BinderInfoRegistry.prototype.startBindingPhase = function () {
+er.BinderInfoRegistry.prototype.startBindingPhase = function () {
     // At the end of the binding phase, we want to process our events. This
     // must include all the binder instances we bound in this phase.
     for (var id in this.info) {
@@ -543,7 +550,7 @@
     }
 };
 
-kukit.er.BinderInfoRegistry.prototype.processBindingEvents = function () {
+er.BinderInfoRegistry.prototype.processBindingEvents = function () {
     // At the end of the binding phase, we want to process our events. This
     // must include all the binder instances we bound in this phase.
     for (var id in this.info) {
@@ -554,30 +561,30 @@
 };
 
 /*
-* class BinderInfo
+* class _BinderInfo
 *
 * Information about the given binder instance. This contains the instance and
 * various binding info. Follows the workflow of the binding in different stages.
 *
 */
 
-kukit.er.BinderInfo = function (binderInstance) {
+var _BinderInfo = function (binderInstance) {
     this.binderInstance = binderInstance;
-    this.bound = new kukit.er.OperRegistry();
+    this.bound = new _OperRegistry();
     this.startBindingPhase();
 };
 
-kukit.er.BinderInfo.prototype.getBinderInstance = function () {
+_BinderInfo.prototype.getBinderInstance = function () {
     return this.binderInstance;
 };
 
-kukit.er.BinderInfo.prototype.startBindingPhase = function () {
+_BinderInfo.prototype.startBindingPhase = function () {
     // The binding phase starts and it has the information for
     // the currently on-bound events.
-    this.binding = new kukit.er.OperRegistry();
+    this.binding = new _OperRegistry();
 };
 
-kukit.er.BinderInfo.prototype.bindOper = function (oper) {
+_BinderInfo.prototype.bindOper = function (oper) {
     // We mark a given oper. This means a binding on the binderInstance 
     // for given event, node and eventRule (containing event namespace,
     // name, and evt- parms.)
@@ -588,7 +595,7 @@
     this.binding.bindOper(oper);
 };
 
-kukit.er.BinderInfo.prototype.processBindingEvents = function () {
+_BinderInfo.prototype.processBindingEvents = function () {
     // We came to the end of the binding phase. Now we process all our binding
     // events, This will do the actual binding on the browser side.
     this.binding.processBindingEvents(this.binderInstance);
@@ -600,7 +607,7 @@
 
 
 /*
-*  class OperRegistry
+*  class _OperRegistry
 *
 *  OperRegistry is associated with a binder instance in the 
 *  BinderInfoRegistry, and remembers bounding information.
@@ -609,13 +616,13 @@
 *  a given event setup phase.
 */
 
-kukit.er.OperRegistry = function () {
+var _OperRegistry = function () {
     this.infoPerName = {};
     this.infoPerNode = {};
 };
 
-// XXX XXX XXX we can do this without full cloning, more efficiently.
-kukit.er.OperRegistry.prototype.propagateTo = function (newreg) {
+// XXX we can do this without full cloning, more efficiently.
+_OperRegistry.prototype.propagateTo = function (newreg) {
     for (var key in this.infoPerName) {
         var rulesPerName = this.infoPerName[key];
         for (var name in rulesPerName) {
@@ -625,7 +632,7 @@
     }
 };
 
-kukit.er.OperRegistry.prototype.checkOperBindable =
+_OperRegistry.prototype.checkOperBindable =
     function (oper, name, nodeHash) {
     // Check if the binding with this oper could be done.
     // Throw exception otherwise.
@@ -652,7 +659,7 @@
     return rulesPerName;
 };
     
-kukit.er.OperRegistry.prototype.bindOper = function (oper) {
+_OperRegistry.prototype.bindOper = function (oper) {
     // Marks binding between binderInstance, eventName, node.
     var name = oper.eventRule.kssSelector.name;
     var nodeHash = kukit.rd.hashNode(oper.node);
@@ -669,7 +676,7 @@
 
 // XXX This will need refactoring.
 /// We would only want to lookup from our registry and not the other way around.
-kukit.er.OperRegistry.prototype.processBindingEvents = 
+_OperRegistry.prototype.processBindingEvents = 
     function (binderInstance) {
     var eventRegistry = kukit.eventsGlobalRegistry;
     for (var i=0; i < eventRegistry.eventSets.length; i++) {
@@ -680,7 +687,7 @@
                 // Process the binding event set.
                 // This will call the actual bindmethods
                 // according to the specified iterator.
-                var iterator = kukit.er.getBindIterator(eventSet.iterName);
+                var iterator = er.getBindIterator(eventSet.iterName);
                 iterator.call(this, eventSet, binderInstance);
             }
         }
@@ -690,7 +697,7 @@
 // XXX The following methods will probably disappear as iterators 
 // replace their functionality.
 
-kukit.er.OperRegistry.prototype.getBoundOperForNode = function (name, node) {
+_OperRegistry.prototype.getBoundOperForNode = function (name, node) {
     // Get the oper that is bound to a given eventName
     // to a node in this binderInstance
     // returns null, if there is no such oper.
@@ -707,7 +714,7 @@
     return oper;
 };
 
-kukit.er.OperRegistry.prototype.getBoundOpers = function (name) {
+_OperRegistry.prototype.getBoundOpers = function (name) {
     // Get the opers bound to a given eventName (to any node)
     // in this binderInstance
     var opers = [];
@@ -732,7 +739,7 @@
 // given iteration specifies.
 //
 
-kukit.er.getBindIterator = function(iterName) {
+er.getBindIterator = function(iterName) {
     // attempt to find canonical version of string
     // and shout if it does not match.
     // String must start uppercase.
@@ -752,10 +759,10 @@
 ;;;     kukit.logWarning(msg);
         iterName = canonical;
         }
-    return kukit.er.OperRegistry.prototype['_iterate' + iterName];
+    return _OperRegistry.prototype['_iterate' + iterName];
 };
 
-kukit.er.OperRegistry.prototype.callBindMethod = 
+_OperRegistry.prototype.callBindMethod = 
     function (eventSet, binderInstance, p1, p2, p3, p4, p5, p6) {
     var method = binderInstance[eventSet.bindMethodName];
     // Protect the binding for better logging
@@ -772,7 +779,7 @@
 // This calls the bind method by each bound oper one by one.
 // Eventname and funcToBind are passed too.
 // this is the legacy ([EachLegacy]) way
-kukit.er.OperRegistry.prototype._iterateEachLegacy =
+_OperRegistry.prototype._iterateEachLegacy =
     function (eventSet, binderInstance) {
     for (var i=0; i<eventSet.names.length; i++) {
         var rulesPerName = this.infoPerName[eventSet.names[i]];
@@ -792,7 +799,7 @@
 // This calls the bind method by each bound oper one by one.
 // Eventname and funcToBind are passed too.
 // this is the preferred ([Each]) way. Parameters are different from EachLegacy.
-kukit.er.OperRegistry.prototype._iterateEach =
+_OperRegistry.prototype._iterateEach =
     function (eventSet, binderInstance) {
     for (var i=0; i<eventSet.names.length; i++) {
         var rulesPerName = this.infoPerName[eventSet.names[i]];
@@ -806,7 +813,7 @@
 };
 
 // This calls the bind method by the list of bound opers
-kukit.er.OperRegistry.prototype._iterateOpers =
+_OperRegistry.prototype._iterateOpers =
     function (eventSet, binderInstance) {
     var opers = [];
     for (var i=0; i<eventSet.names.length; i++) {
@@ -822,7 +829,7 @@
 
 // This calls the bind method by a mapping eventName:oper
 // per each bound node individually
-kukit.er.OperRegistry.prototype._iterateNode =
+_OperRegistry.prototype._iterateNode =
     function (eventSet, binderInstance) {
     for (var nodeHash in this.infoPerNode) {
         var rulesPerNode = this.infoPerNode[nodeHash];
@@ -851,7 +858,7 @@
 // This calls the bind method once per instance, by a list of
 // items, where item.node is the node and item.opersByEventName nodeHash:item
 // in item there is item.node and item.opersByEventName
-kukit.er.OperRegistry.prototype._iterateAllNodes = 
+_OperRegistry.prototype._iterateAllNodes = 
     function (eventSet, binderInstance) {
     var items = [];
     var hasResult = false;
@@ -881,3 +888,4 @@
     }
 };
 
+}();                              /// MODULE END

Modified: kukit/kukit.js/trunk/kukit/forms.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/forms.js	(original)
+++ kukit/kukit.js/trunk/kukit/forms.js	Tue Sep 25 09:05:19 2007
@@ -19,37 +19,39 @@
 
 /* Form handling utilities */
 
-kukit.fo = {};
+kukit.fo = new function() {   /// MODULE START
+
+var fo = this;
 
 /* form query assembler */
 
 // Prefix constants for dict marshalling, 
-//     pattern: %s(dictprefix)%(name)s%(dictseparator)s%(key)s%(dictpostfix)s
+//     pattern: %s(_dictPrefix)%(name)s%(_dictSeparator)s%(key)s%(_dictPostfix)s
 // XXX this should be settable
-kukit.fo.dictprefix = '';
-kukit.fo.dictseparator = '.';
-kukit.fo.dictpostfix = ':record';
+var _dictPrefix = '';
+var _dictSeparator = '.';
+var _dictPostfix = ':record';
 
 /*
-* class FormQueryElem
+* class _FormQueryElem
 */
-kukit.fo.FormQueryElem = function(name, value) {
+var _FormQueryElem = function(name, value) {
     this.name = name;
     this.value = value;
 };
     
-kukit.fo.FormQueryElem.prototype.encode = function() {
+_FormQueryElem.prototype.encode = function() {
     return this.name+ "=" + encodeURIComponent(this.value);
 };
     
 /*
 * class FormQuery
 */
-kukit.fo.FormQuery = function() {
+fo.FormQuery = function() {
     this.l = [];
 };
 
-kukit.fo.FormQuery.prototype.appendElem = function(name, value) {
+fo.FormQuery.prototype.appendElem = function(name, value) {
     if (value == null) {
         // do not marshall nulls
 ;;;     var msg = "Parameter '" + name + "' is null,";
@@ -57,29 +59,29 @@
 ;;;     kukit.logDebug(msg);
         }
     else if (typeof(value) == 'string') {
-        var elem = new kukit.fo.FormQueryElem(name, value);
+        var elem = new _FormQueryElem(name, value);
         this.l.push(elem);
     }
     else if (typeof(value) == 'object' && 
         value.constructor.toString().indexOf('Array') != -1) {
         // Special marshalling of arrays
         for (var i=0; i < value.length; i++) {
-            var elem = new kukit.fo.FormQueryElem(name, value[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 = kukit.fo.dictprefix + name + kukit.fo.dictseparator;
-            qkey += key + kukit.fo.dictpostfix;
-            var elem = new kukit.fo.FormQueryElem(qkey, value[key]);
+            var qkey = _dictPrefix + name + _dictSeparator;
+            qkey += key + _dictPostfix;
+            var elem = new _FormQueryElem(qkey, value[key]);
             this.l.push(elem);
         }
     }    
 };
 
-kukit.fo.FormQuery.prototype.encode = function() {
+fo.FormQuery.prototype.encode = function() {
     var poster = [];
       for (var i=0;i < this.l.length;i++) {
         poster[poster.length] = this.l[i].encode();
@@ -87,7 +89,7 @@
     return poster.join("&");
 };
 
-kukit.fo.FormQuery.prototype.toDict = function() {
+fo.FormQuery.prototype.toDict = function() {
     var d = {};
       for (var i=0;i < this.l.length;i++) {
         var elem = this.l[i];
@@ -98,7 +100,7 @@
 
 /* Form data extraction, helpers */
 
-kukit.fo.findContainer = function(node, func) {
+var findContainer = function(node, func) {
     // Starting with the given node, find the nearest containing element
     // for which the given function returns true.
     while (node != null) {
@@ -115,13 +117,13 @@
  *
  */
 
-kukit.fo.CurrentFormLocator = function(target) {
+fo.CurrentFormLocator = function(target) {
     this.target = target;
 };
 
-kukit.fo.CurrentFormLocator.prototype.queryForm = function() {
+fo.CurrentFormLocator.prototype.queryForm = function() {
     // Find the form that contains the target node.
-    return kukit.fo.findContainer(this.target, function(node) {
+    return findContainer(this.target, function(node) {
         if (!node.nodeName) {
             return false;
         }
@@ -133,7 +135,7 @@
     });
 };
 
-kukit.fo.CurrentFormLocator.prototype.getForm = function() {
+fo.CurrentFormLocator.prototype.getForm = function() {
     var form = this.queryForm();
     if (!form) {
 ;;;     kukit.logWarning("No form found");
@@ -147,25 +149,25 @@
  *
  */
 
-kukit.fo.NamedFormLocator = function(formname) {
+fo.NamedFormLocator = function(formname) {
     this.formname = formname;
 };
 
-kukit.fo.NamedFormLocator.prototype.queryForm = function() {
+fo.NamedFormLocator.prototype.queryForm = function() {
     // Find the form with the given name.
     return document.forms[this.formname];
 };
 
-kukit.fo.NamedFormLocator.prototype.getForm = 
-    kukit.fo.CurrentFormLocator.prototype.getForm;
+fo.NamedFormLocator.prototype.getForm = 
+    fo.CurrentFormLocator.prototype.getForm;
 
 /* methods to take the desired value(s) from the form */
 
-kukit.fo.getValueOfFormElement = function(element) {
+fo.getValueOfFormElement = function(element) {
     // Returns the value of the form element / or null
     // First: update the field in case an editor is lurking
     // in the background
-    kukit.fo.fieldUpdateRegistry.doUpdate(element);
+    _fieldUpdateRegistry.doUpdate(element);
     // Collect the data
     if (element.selectedIndex != undefined) {
         // handle single selects first
@@ -217,7 +219,7 @@
     return value;
 };
 
-kukit.fo.getFormVar = function(locator, name) {
+fo.getFormVar = function(locator, name) {
     var form = locator.getForm();
     if (! form)
         return null;
@@ -225,7 +227,7 @@
     var value = null;
     var element = form[name];
     if (element) {
-        var value = kukit.fo.getValueOfFormElement(element);
+        var value = fo.getValueOfFormElement(element);
 ;;;     if (value != null) {
 ;;;         var msg = "Form element [" + element.tagName + "] : name = ";
 ;;;         msg += element.name + ", value = " + value + '.';
@@ -237,7 +239,7 @@
     return value;
 };
 
-kukit.fo.getAllFormVars = function(locator, collector) {
+fo.getAllFormVars = function(locator, collector) {
     var form = locator.getForm();
     if (! form)
         return collector.result;
@@ -246,7 +248,7 @@
     var elements = form.elements;
     for (var y=0; y<elements.length; y++) {
         var element = elements[y];
-        var value = kukit.fo.getValueOfFormElement(element);
+        var value = fo.getValueOfFormElement(element);
         if (value != null) {
 ;;;         var msg = "Form element [" + element.tagName + "] : name = ";
 ;;;         msg += element.name + ", value = " + value + '.';
@@ -269,13 +271,13 @@
 */
 
 /*
-* class FieldUpdateRegistry
+* class _FieldUpdateRegistry
 */
-kukit.fo.FieldUpdateRegistry = function() {
+var _FieldUpdateRegistry = function() {
     this.editors = {};
 };
 
-kukit.fo.FieldUpdateRegistry.prototype.register = function(node, editor) {
+_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.';
@@ -287,7 +289,7 @@
     editor.doInit();
 };
 
-kukit.fo.FieldUpdateRegistry.prototype.doUpdate = function(node) {
+_FieldUpdateRegistry.prototype.doUpdate = function(node) {
     var hash = kukit.rd.hashNode(node);
     var editor = this.editors[hash];
     if (typeof(editor) != 'undefined') {
@@ -296,93 +298,105 @@
     }
 };
 
-kukit.fo.fieldUpdateRegistry = new kukit.fo.FieldUpdateRegistry();
+var _fieldUpdateRegistry = new _FieldUpdateRegistry();
 
 
 // Registry of the pprovider functions for kssSubmitForm
 
-kukit.fo.pproviderFormRegistry = new kukit.pr.ValueProviderRegistry();
+fo.pproviderFormRegistry = new kukit.pr.ValueProviderRegistry();
 
 // form, currentForm will provide identical functions to those 
 // in normal parameters
 // except they return a tuple list, not a dictionary.
 // This is needed because duplications and order must be preserved.
 
-kukit.fo.FormPP = function() {};
-kukit.fo.FormPP.prototype = {
+/*
+*
+* class _FormValueProvider
+*
+*/
+var _FormValueProvider = function() {};
+
+_FormValueProvider.prototype = {
     check: function(args) {
 ;;;     if (args.length != 1) {
 ;;;         throw new Error('form method needs 1 arguments (formname)');
 ;;;     }
     },
     eval: function(args, node) {
-        var locator = new kukit.fo.NamedFormLocator(args[0]);
+        var locator = new fo.NamedFormLocator(args[0]);
         var collector = new kukit.ut.TupleCollector();
-        return kukit.fo.getAllFormVars(locator, collector);
+        return fo.getAllFormVars(locator, collector);
     }
 };
-kukit.fo.pproviderFormRegistry.register('form', kukit.fo.FormPP);
+fo.pproviderFormRegistry.register('form', _FormValueProvider);
 
-kukit.fo.CurrentFormPP = function() {};
-kukit.fo.CurrentFormPP.prototype = {
+/*
+*
+* class _CurrentFormValueProvider
+*
+*/
+var _CurrentFormValueProvider = function() {};
+_CurrentFormValueProvider.prototype = {
     check: function(args) {
 ;;;     if (args.length != 0) {
 ;;;         throw new Error('currentForm method needs no argument');
 ;;;     }
     },
     eval: function(args, node) {
-        var locator = new kukit.fo.CurrentFormLocator(node);
+        var locator = new fo.CurrentFormLocator(node);
         var collector = new kukit.ut.TupleCollector();
-        return kukit.fo.getAllFormVars(locator, collector);
+        return fo.getAllFormVars(locator, collector);
     }
 };
-kukit.fo.pproviderFormRegistry.register('currentForm', kukit.fo.CurrentFormPP);
+fo.pproviderFormRegistry.register('currentForm', _CurrentFormValueProvider);
 
 // If a string is given, that will look like a form lookup,
 // ie. identical to form
-kukit.fo.pproviderFormRegistry.register('', kukit.fo.FormPP);
+fo.pproviderFormRegistry.register('', _FormValueProvider);
 
 
 /* BBB. To be deprecated on 2008-06-15 */
 
-kukit.fo.getCurrentForm = function(target) {
+fo.getCurrentForm = function(target) {
 ;;; var msg = 'Deprecated kukit.fo.getCurrentForm(target), use new ';
 ;;; msg += 'kukit.fo.CurrentFormLocator(target).getForm() instead!';
 ;;; kukit.logWarning(msg);
-    return new kukit.fo.CurrentFormLocator(target).getForm();
+    return new fo.CurrentFormLocator(target).getForm();
 };
 
-kukit.fo.getFormVarFromCurrentForm = function(target, name) {
+fo.getFormVarFromCurrentForm = function(target, name) {
 ;;; var msg = 'Deprecated kukit.fo.getFormVarFromCurrentForm(target, name),';
 ;;; msg += ' use kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(target),';
 ;;; msg += ' name) instead!';
 ;;; kukit.logWarning(msg);
-    return kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(target), name);
+    return fo.getFormVar(new fo.CurrentFormLocator(target), name);
 };
 
-kukit.fo.getFormVarFromNamedForm = function(formname, name) {
+fo.getFormVarFromNamedForm = function(formname, name) {
 ;;; var msg = 'Deprecated kukit.fo.getFormVarFromNamedForm(formname, name),';
 ;;; msg += ' use kukit.fo.getFormVar(new kukit.fo.NamedFormLocator(formname),';
 ;;; msg += ' name) instead!';
 ;;; kukit.logWarning(msg);
-    return kukit.fo.getFormVar(new kukit.fo.NamedFormLocator(formname), name);
+    return fo.getFormVar(new fo.NamedFormLocator(formname), name);
 };
 
-kukit.fo.getAllFormVarsFromCurrentForm = function(target) {
+fo.getAllFormVarsFromCurrentForm = function(target) {
 ;;; var msg = 'Deprecated kukit.fo.getAllFormVarsFromCurrentForm(target),';
 ;;; msg += ' use kukit.fo.getAllFormVars(new kukit.fo.CurrentFormLocator';
 ;;; msg += '(target), new kukit.ut.DictCollector()) instead!';
 ;;; kukit.logWarning(msg);
-    return kukit.fo.getAllFormVars(new kukit.fo.CurrentFormLocator(target),
+    return fo.getAllFormVars(new fo.CurrentFormLocator(target),
         new kukit.ut.DictCollector());
 };
 
-kukit.fo.getAllFormVarsFromNamedForm = function(formname) {
+fo.getAllFormVarsFromNamedForm = function(formname) {
 ;;; var msg = 'Deprecated kukit.fo.getAllFormVarsFromNamedtForm(formname), ';
 ;;; msg += 'use kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator';
 ;;; msg += '(formname), new kukit.ut.DictCollector()) instead!';
 ;;; kukit.logWarning(msg);
-    return kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator(formname),
+    return fo.getAllFormVars(new fo.NamedFormLocator(formname),
         new kukit.ut.DictCollector());
 };
 
+}();                              /// MODULE END


More information about the Kukit-checkins mailing list