[KSS-checkins] r50486 - in kukit/kukit.js/trunk: doc kukit tests
gotcha at codespeak.net
gotcha at codespeak.net
Thu Jan 10 13:53:51 CET 2008
Author: gotcha
Date: Thu Jan 10 13:53:49 2008
New Revision: 50486
Modified:
kukit/kukit.js/trunk/doc/HISTORY.txt
kukit/kukit.js/trunk/kukit/actionreg.js
kukit/kukit.js/trunk/kukit/commandprocessor.js
kukit/kukit.js/trunk/kukit/commandreg.js
kukit/kukit.js/trunk/kukit/dom.js
kukit/kukit.js/trunk/kukit/errors.js
kukit/kukit.js/trunk/kukit/eventreg.js
kukit/kukit.js/trunk/kukit/forms.js
kukit/kukit.js/trunk/kukit/kssparser.js
kukit/kukit.js/trunk/kukit/kukit.js
kukit/kukit.js/trunk/kukit/oper.js
kukit/kukit.js/trunk/kukit/plugin.js
kukit/kukit.js/trunk/kukit/providerreg.js
kukit/kukit.js/trunk/kukit/requestmanager.js
kukit/kukit.js/trunk/kukit/resourcedata.js
kukit/kukit.js/trunk/kukit/selectorreg.js
kukit/kukit.js/trunk/kukit/serveraction.js
kukit/kukit.js/trunk/kukit/tokenizer.js
kukit/kukit.js/trunk/kukit/utils.js
kukit/kukit.js/trunk/tests/test_requestmanager.js
kukit/kukit.js/trunk/tests/test_tokenizer.js
kukit/kukit.js/trunk/tests/unittestUtilities.js
Log:
merge finish-closures branch; see HISTORY.txt for details
Modified: kukit/kukit.js/trunk/doc/HISTORY.txt
==============================================================================
--- kukit/kukit.js/trunk/doc/HISTORY.txt (original)
+++ kukit/kukit.js/trunk/doc/HISTORY.txt Thu Jan 10 13:53:49 2008
@@ -3,13 +3,18 @@
(name of developer listed in brackets)
kukit.js - 1.4dev Unreleased
-
+
- ...
- - Fix multiple selection form fields
- marshalling on Safari
- (fixes #22 in kssproject)
- and on IE.
+ - Use functions in token table instead of code strings
+ that were evaluated. 'eval' is very slow.
+ [gotcha]
+
+ - Refactor code towards module and class closures.
+ [gotcha]
+
+ - Fix multiple selection form fields marshalling on Safari
+ (fixes #22 in kssproject) and on IE.
[ree]
- Fix error fallback handling
Modified: kukit/kukit.js/trunk/kukit/actionreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/actionreg.js (original)
+++ kukit/kukit.js/trunk/kukit/actionreg.js Thu Jan 10 13:53:49 2008
@@ -22,53 +22,58 @@
var ar = this;
/*
-* class ActionRegistry
+* class actionregistry
*
-* The local event actions need to be registered here.
+* the local event actions need to be registered here.
*/
-var ActionRegistry = function () {
+var _ActionRegistry = function () {
+this.initialize = function() {
this.content = {};
};
-ActionRegistry.prototype.register = function(name, func) {
-;;;if (typeof(func) == 'undefined') {
-;;; kukit.E = '[func] argument is mandatory when registering an action';
-;;; kukit.E += ' [ActionRegistry.register].';
-;;; throw new Error(kukit.E);
-;;;}
+this.register = function(name, func) {
+;;; if (typeof(func) == 'undefined') {
+;;; kukit.e = '[func] argument is mandatory when registering an action';
+;;; kukit.e += ' [actionregistry.register].';
+;;; throw new error(kukit.e);
+;;; }
if (this.content[name]) {
- // Do not allow redefinition
-;;; kukit.logError('Error : action [' + name + '] already registered.');
+ // do not allow redefinition
+;;; kukit.logerror('error : action [' + name + '] already registered.');
return;
}
this.content[name] = func;
};
-ActionRegistry.prototype.exists = function(name) {
+this.exists = function(name) {
var entry = this.content[name];
return (typeof(entry) != 'undefined');
};
-ActionRegistry.prototype.get = function(name) {
+this.get = function(name) {
var func = this.content[name];
if (! func) {
// not found
-;;; kukit.E = 'Error : undefined local action [' + name + '].';
+;;; kukit.E = 'Error : undefined local action [' + name + '].';
throw Error(kukit.E);
}
return func;
};
+this.initialize.apply(this, arguments);
+};
+
-kukit.actionsGlobalRegistry = new ActionRegistry();
+kukit.actionsGlobalRegistry = new _ActionRegistry();
/* XXX deprecated methods, to be removed asap */
-ar.actionRegistry = {};
-ar.actionRegistry.register = function(name, func) {
-;;;var msg='Deprecated kukit.ar.actionRegistry.register, use ';
-;;;msg += 'kukit.actionsGlobalRegistry.register instead !';
-;;;kukit.logWarning(msg);
- kukit.actionsGlobalRegistry.register(name, func);
+ar.actionRegistry = function() {
+ this.register = function(name, func) {
+;;; var msg='Deprecated kukit.ar.actionRegistry.register, use ';
+;;; msg += 'kukit.actionsGlobalRegistry.register instead !';
+;;; kukit.logWarning(msg);
+ kukit.actionsGlobalRegistry.register(name, func);
+ };
};
}(); /// MODULE END
Modified: kukit/kukit.js/trunk/kukit/commandprocessor.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/commandprocessor.js (original)
+++ kukit/kukit.js/trunk/kukit/commandprocessor.js Thu Jan 10 13:53:49 2008
@@ -25,13 +25,14 @@
* class CommandProcessor
*/
cp.CommandProcessor = function() {
- this.commands = new Array();
+
+this.initialize = function() {
+ this.commands = new Array();
};
-cp.CommandProcessor.prototype.parseCommands =
- function(commands, transport) {
-;;;kukit.log('Parsing commands.');
-;;;kukit.logDebug('Number of commands : ' + commands.length + '.');
+this.parseCommands = function(commands, transport) {
+;;; kukit.log('Parsing commands.');
+;;; kukit.logDebug('Number of commands : ' + commands.length + '.');
for (var y=0;y < commands.length;y++) {
var command = commands[y];
this.parseCommand(command, transport);
@@ -48,8 +49,7 @@
}
};
-cp.CommandProcessor.prototype.parseCommand =
- function(command, transport) {
+this.parseCommand = function(command, transport) {
var selector = "";
var params = {};
var name = "";
@@ -86,12 +86,12 @@
// we have a single text node
// OR
// we have a single CDATA node (HTML parameter CDATA-style)
-;;; var isTextNode = childNode.firstChild.nodeType == 3;
-;;; var isCData = childNode.firstChild.nodeType == 4;
-;;; if (! (childCount == 1 && (isTextNode || isCData))) {
-;;; kukit.E = 'Bad payload, expected a text or a CDATA node';
-;;; throw new Error(kukit.E);
-;;; }
+;;; var isTextNode = childNode.firstChild.nodeType == 3;
+;;; var isCData = childNode.firstChild.nodeType == 4;
+;;; if (! (childCount == 1 && (isTextNode || isCData))) {
+;;; kukit.E = 'Bad payload, expected a text or a CDATA node';
+;;; throw new Error(kukit.E);
+;;; }
// we consider this as html payload
// The result is always a string from here.
result = childNode.firstChild.nodeValue;
@@ -106,12 +106,11 @@
this.addCommand(command);
};
-cp.CommandProcessor.prototype.addCommand = function(command) {
+this.addCommand = function(command) {
this.commands[this.commands.length] = command;
};
-cp.CommandProcessor.prototype.executeCommands = function(oper) {
- kukit.engine.beginSetupEventsCollection();
+this.executeCommands = function(oper) {
// node, eventRule, binder are given on oper, in case
// the command was called up from an event
if (typeof(oper) == 'undefined' || oper == null) {
@@ -120,18 +119,19 @@
var commands = this.commands;
for (var y=0;y < commands.length;y++) {
var command = commands[y];
-;;; try {
+;;; try {
command.execute(oper);
-;;; } catch (e) {
-;;; if (e.name == 'RuleMergeError' || e.name == 'EventBindError') {
-;;; throw(e);
-;;; } else {
-;;; // augment the error message
-;;; throw kukit.err.commandExecutionError(e, command);
-;;; }
-;;; }
+;;; } catch (e) {
+;;; if (e.name == 'RuleMergeError' || e.name == 'EventBindError') {
+;;; throw(e);
+;;; } else {
+;;; // augment the error message
+;;; throw kukit.err.commandExecutionError(e, command);
+;;; }
+;;; }
}
- kukit.engine.finishSetupEventsCollection();
+};
+this.initialize.apply(this, arguments);
};
}(); /// MODULE END
Modified: kukit/kukit.js/trunk/kukit/commandreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/commandreg.js (original)
+++ kukit/kukit.js/trunk/kukit/commandreg.js Thu Jan 10 13:53:49 2008
@@ -27,24 +27,12 @@
* class _CommandRegistry
*/
var _CommandRegistry = function () {
+
+this.initialize = function() {
this.commands = {};
};
-/*
-* This is the proposed way of registration, as we like all commands to be
-* client actions first.
-*
-* Examples:
-*
-* kukit.actionsGlobalRegistry.register('log', f1);
-* kukit.commandsGlobalRegistry.registerFromAction('log',
-* kukit.cr.makeGlobalCommand);
-*
-* kukit.actionsGlobalRegistry.register('replaceInnerHTML', f2);
-* kukit.commandsGlobalRegistry.registerFromAction('replaceInnerHTML',
-* kukit.cr.makeSelectorCommand);
-*/
-_CommandRegistry.prototype.registerFromAction =
+this.registerFromAction =
function(srcname, factory, name) {
if (typeof(name) == 'undefined') {
// allows to set a different name as the action name,
@@ -57,26 +45,42 @@
factory(name, f);
};
-_CommandRegistry.prototype.register = function(name, klass) {
+this.register = function(name, klass) {
if (this.commands[name]) {
// Do not allow redefinition
-;;; var msg = 'ValueError : command [' + name + '] is already registered.';
-;;; kukit.logError(msg);
+;;; var msg = 'ValueError : command [' + name + '] is already registered.';
+;;; kukit.logError(msg);
return;
}
this.commands[name] = klass;
};
-_CommandRegistry.prototype.get = function(name) {
+this.get = function(name) {
var klass = this.commands[name];
-;;;if (! klass) {
-;;; // not found
-;;; var msg = 'ValueError : no command registered under [' + name + '].';
-;;; kukit.logError(msg);
-;;; }
+;;; if (! klass) {
+;;; // not found
+;;; var msg = 'ValueError : no command registered under [' + name + '].';
+;;; kukit.logError(msg);
+;;; }
return klass;
};
+this.initialize.apply(this, arguments);
+};
+/*
+* This is the proposed way of registration, as we like all commands to be
+* client actions first.
+*
+* Examples:
+*
+* kukit.actionsGlobalRegistry.register('log', f1);
+* kukit.commandsGlobalRegistry.registerFromAction('log',
+* kukit.cr.makeGlobalCommand);
+*
+* kukit.actionsGlobalRegistry.register('replaceInnerHTML', f2);
+* kukit.commandsGlobalRegistry.registerFromAction('replaceInnerHTML',
+* kukit.cr.makeSelectorCommand);
+*/
kukit.commandsGlobalRegistry = new _CommandRegistry();
@@ -141,22 +145,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/trunk/kukit/dom.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/dom.js (original)
+++ kukit/kukit.js/trunk/kukit/dom.js Thu Jan 10 13:53:49 2008
@@ -299,12 +299,27 @@
};
/*
+* From http://xkr.us/articles/dom/iframe-document/
+* Note it's not necessary for the iframe to have the name
+* attribute since we don't access it from window.frames by name.
+*/
+var _getIframeDocument = function(framename) {
+ var iframe = document.getElementById(framename);
+ var doc = iframe.contentWindow || iframe.contentDocument;
+ if (doc.document) {
+ doc = doc.document;
+ }
+ return doc;
+};
+
+/*
* class EmbeddedContentLoadedScheduler
*
* Scheduler for embedded window content loaded
*/
-dom.EmbeddedContentLoadedScheduler =
- function(framename, func, autodetect) {
+dom.EmbeddedContentLoadedScheduler = function() {
+
+this.initialize = function(framename, func, autodetect) {
this.framename = framename;
this.func = func;
this.autodetect = autodetect;
@@ -319,23 +334,9 @@
this.counter.start();
};
-/*
-* From http://xkr.us/articles/dom/iframe-document/
-* Note it's not necessary for the iframe to have the name
-* attribute since we don't access it from window.frames by name.
-*/
-var _getIframeDocument = function(framename) {
- var iframe = document.getElementById(framename);
- var doc = iframe.contentWindow || iframe.contentDocument;
- if (doc.document) {
- doc = doc.document;
- }
- return doc;
-};
-
-dom.EmbeddedContentLoadedScheduler.prototype.check = function() {
+this.check = function() {
-;;;kukit.logDebug('Is iframe loaded ?');
+;;; kukit.logDebug('Is iframe loaded ?');
var doc = _getIframeDocument(this.framename);
@@ -345,9 +346,9 @@
// even in strings
//if (doc._embeddedContentLoadedInitDone) {
if (doc['_' + 'embeddedContentLoadedInitDone']) {
-;;; var msg = 'Iframe already initialized, but we execute the action';
-;;; msg += ' anyway, as requested.';
-;;; kukit.logWarning(msg);
+;;; var msg = 'Iframe already initialized, but we execute the action';
+;;; msg += ' anyway, as requested.';
+;;; kukit.logWarning(msg);
this.counter.restart = false;
}
@@ -391,7 +392,7 @@
}
if ( ! this.counter.restart) {
-;;; kukit.logDebug('Yes, iframe is loaded.');
+;;; kukit.logDebug('Yes, iframe is loaded.');
// XXX attribute access starting with _ breaks full compression,
// even in strings
// doc._embeddedContentLoadedInitDone = true;
@@ -399,6 +400,8 @@
this.func();
}
};
+this.initialize.apply(this, arguments);
+};
dom.getNsTags = function(dom_obj, tagName) {
// Now, all the document is in the kukit namespace,
Modified: kukit/kukit.js/trunk/kukit/errors.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/errors.js (original)
+++ kukit/kukit.js/trunk/kukit/errors.js Thu Jan 10 13:53:49 2008
@@ -54,6 +54,9 @@
*
*/
+/*
+* class ErrorAnnotation
+*/
var ErrorAnnotation = function() {
Modified: kukit/kukit.js/trunk/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/eventreg.js (original)
+++ kukit/kukit.js/trunk/kukit/eventreg.js Thu Jan 10 13:53:49 2008
@@ -31,15 +31,18 @@
*
* usage:
*
-* kukit.eventsGlobalRegistry.register(namespace, eventName, func,
+* kukit.eventsGlobalRegistry.register(namespace, eventName, func,
* bindMethodName, defaultActionMethodName);
-*
-* namespace = null: means global namespace
-* defaultActionMethodName = null: if there is no default action implemented
-* func must be a class (constructor) function, this is the class that
-* implements the binder.
+*
+* namespace = null: means global namespace
+* defaultActionMethodName = null: if there is no default action implemented
+* klass must be a class (constructor) function, this is the class that
+* implements the binder.
+*
*/
-var _EventRegistry = function () {
+var _EventRegistry = function() {
+
+this.initialize = function() {
this.content = {};
this.classes = {};
this.eventSets = [];
@@ -47,57 +50,67 @@
/* binder registration */
-_EventRegistry.prototype.registerBinder = function(className, func) {
- if (typeof(func) == 'undefined') {
-;;; kukit.E = 'func argument is mandatory when registering an event';
+this.registerBinder = function(klass) {
+ if (typeof(klass) == 'undefined') {
+;;; kukit.E = 'klass argument is mandatory when registering an event';
;;; kukit.E += ' binder (_EventRegistry.registerBinder).';
throw new Error(kukit.E);
}
- if (this.classes[className]) {
- // Do not allow redefinition
-;;; var msg = 'Error : event class [' + className + '] already registered.';
-;;; kukit.logError(msg);
+ // See if we are set up already?
+ // We make a mark not on the class prototype,
+ // but on the class itself. This will make
+ // sure inherited classes get a distinct class name.
+ if (klass.__decorated_for_kss__) {
return;
-
}
- // Decorate and store the class
- decorateEventBinderClass(func);
- this.classes[className] = func;
-};
-
-_EventRegistry.prototype.existsBinder = function(className) {
- var func = this.classes[className];
- return (typeof(func) != 'undefined');
-};
-
-_EventRegistry.prototype.getBinderClass = function(className) {
- var func = this.classes[className];
- if (! func) {
+ // We do _not_ overwrite the class's prototype, since
+ // that destroys any inheritance it has. Our purpose
+ // is to allow any javascript class to function, so
+ // we copy the class's attributes to the prototype.
+ var binder_prototype = new _EventBinder();
+ for (var key in binder_prototype) {
+ klass.prototype[key] = binder_prototype[key];
+ }
+ // Create a className, and register it too.
+ //
+ // The reason to create a __className__ is to provide a
+ // way to lookup the class by a string. This is needed
+ // because dict keys in javascript can only be strings.
+ className = '' + _eventClassCounter;
+ _eventClassCounter += 1;
+ klass.prototype.__className__ = className;
+ this.classes[className] = klass;
+ // mark decorated. We store the class there
+ // so we can decide if this class has been
+ // decorated or not.
+ klass.__decorated_for_kss__ = true;
+};
+
+this.existsBinder = function(className) {
+ var klass = this.classes[className];
+ return (typeof(klass) != 'undefined');
+};
+
+this.getBinderClass = function(className) {
+ var klass = this.classes[className];
+ if (! klass) {
// not found
;;; kukit.E = 'Error : undefined event setup type [' + className + '].';
throw new Error(kukit.E);
}
- return func;
+ return klass;
};
/* events (methods) registration helpers (not to be called directly) */
-_EventRegistry.prototype._register =
- function(namespace, eventName, klass,
+this._register = function(namespace, eventName, klass,
bindMethodName, defaultActionMethodName, iterName) {
if (typeof(defaultActionMethodName) == 'undefined') {
;;; 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 = '' + _eventClassCounter;
- _eventClassCounter += 1;
- this.registerBinder(className, klass);
- klass.prototype.__className__ = className;
- }
+ // Register and decorate the binder's class.
+ this.registerBinder(klass);
if (!eventName) {
;;; kukit.E = '[eventName] argument cannot be empty when registering';
;;; kukit.E += ' an event with [_EventRegistry.register].';
@@ -114,19 +127,9 @@
;;; 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 += '] 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 += defaultActionMethodName + '] is undefined for event [';
-;;; kukit.E += eventName + '] namespace [' + namespace + '].';
- throw new Error(kukit.E);
- }
+ // XXX We do not check bindMethodName and defaltActionMethodName
+ // here, because at this point they may be hidden by closure.
+ //
// check the iterator.
if (! er.getBindIterator(iterName)) {
;;; kukit.E = 'In _EventRegistry.register unknown bind iterator [';
@@ -144,7 +147,7 @@
/* events (methods) binding [ForAll] registration */
-_EventRegistry.prototype._registerEventSet =
+this._registerEventSet =
function(namespace, names, iterName, bindMethodName) {
// At this name the values should be checked already. so this should
// be called _after_ _register.
@@ -158,7 +161,7 @@
/* there are the actual registration methods, to be called from plugins */
-_EventRegistry.prototype.register =
+this.register =
function(namespace, eventName, klass, bindMethodName,
defaultActionMethodName) {
this._register(namespace, eventName, klass, bindMethodName,
@@ -167,7 +170,7 @@
bindMethodName);
};
-_EventRegistry.prototype.unregister =
+this.unregister =
function(namespace, eventName) {
var key = this._getKey(namespace, eventName);
delete this.content[key];
@@ -184,7 +187,7 @@
}
};
-_EventRegistry.prototype.registerForAllEvents =
+this.registerForAllEvents =
function(namespace, eventNames, klass,
bindMethodName, defaultActionMethodName, iterName) {
if (typeof(eventNames) == 'string') {
@@ -198,7 +201,7 @@
this._registerEventSet(namespace, eventNames, iterName, bindMethodName);
};
-_EventRegistry.prototype._getKey = function(namespace, eventName) {
+this._getKey = function(namespace, eventName) {
if (namespace == null) {
namespace = '';
} else if (namespace.split('-') > 1) {
@@ -209,13 +212,13 @@
return namespace + '-' + eventName;
};
-_EventRegistry.prototype.exists = function(namespace, eventName) {
+this.exists = function(namespace, eventName) {
var key = this._getKey(namespace, eventName);
var entry = this.content[key];
return (typeof(entry) != 'undefined');
};
-_EventRegistry.prototype.get = function(namespace, eventName) {
+this.get = function(namespace, eventName) {
var key = this._getKey(namespace, eventName);
var entry = this.content[key];
if (typeof(entry) == 'undefined') {
@@ -231,30 +234,79 @@
return entry;
};
+this.getBinderClassByEventNamespace = function(namespace, eventName) {
+ return this.getBinderClass(this.get(namespace, eventName).className);
+};
+this.initialize.apply(this, arguments);
+};
+
+
kukit.eventsGlobalRegistry = new _EventRegistry();
/* XXX deprecated methods, to be removed asap */
-var _eventRegistry = {};
-_eventRegistry.register = function(namespace, eventName, klass,
- bindMethodName, defaultActionMethodName) {
-;;; var msg = 'Deprecated _eventRegistry.register,';
-;;; msg += ' use kukit.eventsGlobalRegistry.register instead ! [';
-;;; msg += namespace + '-' + eventName + '].';
-;;; kukit.logWarning(msg);
- kukit.eventsGlobalRegistry.register(namespace, eventName, klass,
- bindMethodName, defaultActionMethodName);
+var _eventRegistry = function() {
+ this.register = function(namespace, eventName, klass,
+ bindMethodName, defaultActionMethodName) {
+;;; var msg = 'Deprecated _eventRegistry.register,';
+;;; msg += ' use kukit.eventsGlobalRegistry.register instead ! [';
+;;; msg += namespace + '-' + eventName + '].';
+;;; kukit.logWarning(msg);
+ kukit.eventsGlobalRegistry.register(namespace, eventName, klass,
+ bindMethodName, defaultActionMethodName);
+ };
};
-/* Event class decoration
+/*
*
-* poor man's subclassing
-* This is called automatically on registration, to dress
-* up the event class with the necessary methods
+* class _LateBinder
+*
+* postpone binding of actions until called first time
*
*/
+var _LateBinder = function() {
+
+this.initialize = function(binder, name, node) {
+ this.binder = binder;
+ this.name = name;
+ this.node = node;
+ this.boundEvent = null;
+};
+
+this.executeActions = function() {
+ if (! this.boundEvent) {
+;;; var msg = 'Attempt of late binding for event [' + this.name;
+;;; msg += '], node [' + this.node.nodeName + '].';
+;;; kukit.log(msg);
+ if (kukit.hasFirebug) {
+ kukit.log(this.node);
+ }
+ var info = kukit.engine.binderInfoRegistry.getBinderInfoById(
+ this.binder.__binderId__);
+ var oper = info.bound.getBoundOperForNode(this.name, this.node);
+ if (oper) {
+ // (if eventRule is null here, we could still have the default
+ // method, so go on.)
+ oper.parms = {};
+ this.boundEvent = function() {
+ this.binder.triggerEvent(this.name, oper);
+ };
+;;; kukit.log('Node bound.');
+ } else {
+;;; kukit.logWarning('No node bound.');
+ this.boundEvent = function() {};
+ }
+ }
+ this.boundEvent();
+};
+this.initialize.apply(this, arguments);
+};
-/* Provide callins on the state instance that execute a given
+/*
+*
+* class _EventBinder
+*
+* Provide callins on the state instance that execute a given
* continuation event.
* Parameters will be the ones specified in the call +
* those defined in the rule will be added too. (Parameters can
@@ -264,7 +316,7 @@
*
* trigger an event bound to a given state instance, same node
*
-* binder.__continueEvent__('doit', oper.node, {'extravalue': '5'});
+* binder.continueEvent('doit', oper.node, {'extravalue': '5'});
*
* with kss rule:
*
@@ -283,7 +335,7 @@
* trigger an event bound to a given state instance, and the document
* (different from current scope)
*
-* binder.__continueEvent__('doit', null, {'extravalue': '5'});
+* binder.continueEvent('doit', null, {'extravalue': '5'});
*
* with kss rule:
*
@@ -301,7 +353,7 @@
*
* trigger an event on all the nodes + document bound to a given state instance
*
-* binder.__continueEvent_allNodes__('doit', {'extravalue': '5'});
+* binder.continueEventAllNodes('doit', {'extravalue': '5'});
*
* with kss rule:
*
@@ -314,8 +366,9 @@
* so we create a new oper below
*/
-var _EventBinder__continueEvent__ =
- function(name, node, defaultParameters) {
+var _EventBinder = function() {
+
+this.continueEvent = function(name, node, defaultParameters) {
// Trigger a continuation event bound to a given state instance, given node
// (or on document, if node = null)
//
@@ -359,12 +412,18 @@
oper.defaultParameters = {};
}
// if eventRule is null here, we can yet have the default method, so go on.
- this._EventBinder_triggerEvent(name, oper);
+ this.triggerEvent(name, oper);
;;; kukit.logDebug('Continuation event [' + name + '] executed on same node.');
};
-var _EventBinder__continueEvent_allNodes__ =
- function(name, defaultParameters) {
+this.__continueEvent__ = function(name, node, defaultParameters) {
+;;; var msg = 'Deprecated [__continueEvent__],';
+;;; msg += 'use [continueEvent] instead !';
+;;; kukit.logWarning(msg);
+ this.continueEvent(name, node, defaultParameters);
+};
+
+this.continueEventAllNodes = function(name, defaultParameters) {
// Trigger an event bound to a given state instance, on all nodes.
// (or on document, if node = null)
// if no other nodes execute.
@@ -383,62 +442,35 @@
} else {
newOper.defaultParameters = {};
}
- this._EventBinder_triggerEvent(name, newOper);
+ this.triggerEvent(name, newOper);
executed += 1;
}
;;; kukit.logDebug('Event [' + name + '] executed on ' + executed + ' nodes.');
};
-var _EventBinder_makeFuncToBind = function(name, node) {
+this.__continueEvent_allNodes__ = function(name, defaultParameters) {
+;;; var msg = 'Deprecated [__continueEvent_allNodes__],';
+;;; msg += 'use [continueEventAllNodes] instead !';
+;;; kukit.logWarning(msg);
+ this.continueEventAllNodes(name, defaultParameters);
+};
+
+this.makeFuncToBind = function(name, node) {
var executor = new er._LateBinder(this, name, node);
return function() {
executor.executeActions();
};
};
-/*
-*
-* class _LateBinder
-*
-* postpone binding of actions until called first time
-*
-*/
-var _LateBinder = function(binder, name, node) {
- this.binder = binder;
- this.name = name;
- this.node = node;
- this.boundEvent = null;
+this.__makeFuncToBind__ = function(name, node) {
+;;; var msg = 'Deprecated [__makeFuncToBind__],';
+;;; msg += 'use [makeFuncToBind] instead !';
+;;; kukit.logWarning(msg);
+ this.makeFuncToBind(name, node);
};
-_LateBinder.prototype.executeActions = function() {
- if (! this.boundEvent) {
-;;; var msg = 'Attempt of late binding for event [' + this.name;
-;;; msg += '], node [' + this.node.nodeName + '].';
-;;; kukit.log(msg);
- if (kukit.hasFirebug) {
- kukit.log(this.node);
- }
- var info = kukit.engine.binderInfoRegistry.getBinderInfoById(
- this.binder.__binderId__);
- var oper = info.bound.getBoundOperForNode(this.name, this.node);
- if (oper) {
- // (if eventRule is null here, we could still have the default
- // method, so go on.)
- oper.parms = {};
- this.boundEvent = function() {
- this.binder._EventBinder_triggerEvent(this.name, oper);
- };
-;;; kukit.log('Node bound.');
- } else {
-;;; kukit.logWarning('No node bound.');
- this.boundEvent = function() {};
- }
- }
- this.boundEvent();
-};
-
-var _EventBinder_triggerEvent = function(name, oper) {
- // Private. Called from __continueEvent__ or from main event execution.
+this.triggerEvent = function(name, oper) {
+ // Private. Called from continueEvent or from main event execution.
oper.binder = this;
if (oper.eventRule) {
// Call the actions, if we had an event rule.
@@ -463,9 +495,16 @@
}
};
+this._EventBinder_triggerEvent = function(name, oper) {
+;;; var msg = 'Deprecated [_EventBinder_triggerEvent],';
+;;; msg += 'use [triggerEvent] instead !';
+;;; kukit.logWarning(msg);
+ this.triggerEvent(name, oper);
+};
+
/* (default) method call handling */
-var _EventBinder_callMethod = function(namespace, name, oper, methodName) {
+this.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];
@@ -480,13 +519,13 @@
method.call(this, name, oper);
};
-var decorateEventBinderClass = function(cls) {
- cls.prototype.__continueEvent__ = _EventBinder__continueEvent__;
- cls.prototype.__continueEvent_allNodes__ =
- _EventBinder__continueEvent_allNodes__;
- cls.prototype._EventBinder_triggerEvent = _EventBinder_triggerEvent;
- cls.prototype._EventBinder_callMethod = _EventBinder_callMethod;
- cls.prototype.__makeFuncToBind__ = _EventBinder_makeFuncToBind;
+this._EventBinder_callMethod = function(namespace, name, oper, methodName) {
+;;; var msg = 'Deprecated [_EventBinder_callMethod],';
+;;; msg += 'use [callMethod] instead !';
+;;; kukit.logWarning(msg);
+ this.callMethod(namespace, name, oper, methodName);
+};
+
};
/* Event instance registry
@@ -496,12 +535,13 @@
* used in run-time to keep track of the event instances
*
*/
+er.BinderInfoRegistry = function() {
-er.BinderInfoRegistry = function () {
+this.initialize = function() {
this.info = {};
};
-er.BinderInfoRegistry.prototype.getOrCreateBinderInfo =
+this.getOrCreateBinderInfo =
function (id, className, namespace) {
// Get or create the event.
var binderInfo = this.info[id];
@@ -532,7 +572,7 @@
return binderInfo;
};
-er.BinderInfoRegistry.prototype.getBinderInfoById = function (id) {
+this.getBinderInfoById = function (id) {
// Get an event.
var binderInfo = this.info[id];
if (typeof(binderInfo) == 'undefined') {
@@ -542,7 +582,7 @@
return binderInfo;
};
-er.BinderInfoRegistry.prototype.getSingletonBinderInfoByName =
+this.getSingletonBinderInfoByName =
function (namespace, name) {
//Get className
var className = kukit.eventsGlobalRegistry.get(namespace, name).className;
@@ -557,7 +597,7 @@
return binderInfo;
};
-er.BinderInfoRegistry.prototype.startBindingPhase = function () {
+this.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) {
@@ -567,7 +607,7 @@
}
};
-er.BinderInfoRegistry.prototype.processBindingEvents = function () {
+this.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) {
@@ -576,6 +616,8 @@
binderInfo.processBindingEvents();
}
};
+this.initialize.apply(this, arguments);
+};
/*
* class _BinderInfo
@@ -584,24 +626,25 @@
* various binding info. Follows the workflow of the binding in different stages.
*
*/
+var _BinderInfo = function() {
-var _BinderInfo = function (binder) {
+this.initialize = function(binder) {
this.binder = binder;
this.bound = new _OperRegistry();
this.startBindingPhase();
};
-_BinderInfo.prototype.getBinder = function () {
+this.getBinder = function () {
return this.binder;
};
-_BinderInfo.prototype.startBindingPhase = function () {
+this.startBindingPhase = function () {
// The binding phase starts and it has the information for
// the currently on-bound events.
this.binding = new _OperRegistry();
};
-_BinderInfo.prototype.bindOper = function (oper) {
+this.bindOper = function (oper) {
// We mark a given oper. This means a binding on the binder
// for given event, node and eventRule (containing event namespace,
// name, and evt- parms.)
@@ -612,7 +655,7 @@
this.binding.bindOper(oper);
};
-_BinderInfo.prototype.processBindingEvents = function () {
+this.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.binder);
@@ -621,25 +664,174 @@
// Delete them from the registry, to protect against accidents.
this.binding = null;
};
+this.initialize.apply(this, arguments);
+};
+
+var _iterators = {};
+
+ // This calls the bind method by each bound oper one by one.
+ // Eventname and funcToBind are passed too.
+ // this is the legacy ([EachLegacy]) way
+ _iterators['EachLegacy'] =
+ function (eventSet, binder) {
+ for (var i=0; i<eventSet.names.length; i++) {
+ var rulesPerName = this.infoPerName[eventSet.names[i]];
+ if (typeof(rulesPerName) != 'undefined') {
+ for (var nodeHash in rulesPerName) {
+ var oper = rulesPerName[nodeHash];
+ var eventName = oper.getEventName();
+ var funcToBind = oper.makeExecuteActionsHook();
+ this.callBindMethod(eventSet, binder, eventName,
+ funcToBind, oper);
+ }
+ }
+ }
+ };
+
+ // 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.
+ _iterators['Each'] =
+ function (eventSet, binder) {
+ for (var i=0; i<eventSet.names.length; i++) {
+ var rulesPerName = this.infoPerName[eventSet.names[i]];
+ if (typeof(rulesPerName) != 'undefined') {
+ for (var nodeHash in rulesPerName) {
+ var oper = rulesPerName[nodeHash];
+ this.callBindMethod(eventSet, binder, oper);
+ }
+ }
+ }
+ };
+
+ // This calls the bind method by the list of bound opers
+ _iterators['Opers'] =
+ function (eventSet, binder) {
+ var opers = [];
+ for (var i=0; i<eventSet.names.length; i++) {
+ var rulesPerName = this.infoPerName[eventSet.names[i]];
+ if (typeof(rulesPerName) != 'undefined') {
+ for (var nodeHash in rulesPerName) {
+ opers.push(rulesPerName[nodeHash]);
+ }
+ }
+ }
+ this.callBindMethod(eventSet, binder, opers);
+ };
+
+ // This calls the bind method by a mapping eventName:oper
+ // per each bound node individually
+ _iterators['Node'] =
+ function (eventSet, binder) {
+ for (var nodeHash in this.infoPerNode) {
+ var rulesPerNode = this.infoPerNode[nodeHash];
+ // filter only the events we are interested in
+ var filteredRules = {};
+ var operFound = false;
+ for (var i=0; i<eventSet.names.length; i++) {
+ var name = eventSet.names[i];
+ var oper = rulesPerNode[name];
+ if (typeof(oper) != 'undefined') {
+ filteredRules[name] = oper;
+ operFound = oper;
+ }
+ }
+ // call it
+ // All opers have the same node, the last one is yet in operFound, so
+ // we use it as a second parameter to the call.
+ // The method may or may not want to use this.
+ if (operFound) {
+ this.callBindMethod(eventSet, binder, filteredRules,
+ operFound.node);
+ }
+ }
+ };
+
+ // 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
+ _iterators['AllNodes'] =
+ function (eventSet, binder) {
+ var items = [];
+ var hasResult = false;
+ for (var nodeHash in this.infoPerNode) {
+ var rulesPerNode = this.infoPerNode[nodeHash];
+ // filter only the events we are interested in
+ var filteredRules = {};
+ var operFound = false;
+ for (var i=0; i<eventSet.names.length; i++) {
+ var name = eventSet.names[i];
+ var oper = rulesPerNode[name];
+ if (typeof(oper) != 'undefined') {
+ filteredRules[name] = oper;
+ operFound = oper;
+ }
+ }
+ if (operFound) {
+ var item = {node: operFound.node,
+ opersByEventName: filteredRules};
+ items.push(item);
+ hasResult = true;
+ }
+ }
+ // call the binder method
+ if (hasResult) {
+ this.callBindMethod(eventSet, binder, items);
+ }
+ };
+
+// Iterators
+// The getBindIterator returns a function that gets executed on
+// the oper registry.
+//
+// Iterators receive the eventSet as a parameter
+// plus a binder and a method. They need to iterate by calling this
+// as method.call(binder, ...); where ... can be any parms this
+// given iteration specifies.
+//
+er.getBindIterator = function(iterName) {
+ // attempt to find canonical version of string
+ // and shout if it does not match.
+ // String must start uppercase.
+ var canonical = iterName.substring(0, 1).toUpperCase() +
+ iterName.substring(1);
+ // Special case: allnodes -> AllNodes, not handled by
+ // the previous line
+ if (canonical == 'Allnodes') {
+ canonical = 'AllNodes';
+ }
+ if (iterName != canonical) {
+ // BBB 2007.12.31, this will turn into an exception.
+;;; var msg = 'Deprecated the lowercase iterator names in last ';
+;;; msg += 'parameters of ';
+;;; msg += 'kukit.eventsGlobalRegistry.registerForAllEvents, use [';
+;;; msg += canonical + '] instead of [' + iterName + '] (2007-12-31)';
+;;; kukit.logWarning(msg);
+ iterName = canonical;
+ }
+ return _iterators[iterName];
+};
/*
-* class _OperRegistry
+* class _OperRegistry
+*
+* OperRegistry is associated with a binder instance in the
+* BinderInfoRegistry, and remembers bounding information.
+* This is used both to remember all the bindings for a given
+* instance, but also just to remember the bindings done during
+* a given event setup phase.
*
-* OperRegistry is associated with a binder instance in the
-* BinderInfoRegistry, and remembers bounding information.
-* This is used both to remember all the bindings for a given
-* instance, but also just to remember the bindings done during
-* a given event setup phase.
*/
+var _OperRegistry = function() {
-var _OperRegistry = function () {
+this.initialize = function() {
this.infoPerName = {};
this.infoPerNode = {};
};
// XXX we can do this without full cloning, more efficiently.
-_OperRegistry.prototype.propagateTo = function (newreg) {
+this.propagateTo = function (newreg) {
for (var key in this.infoPerName) {
var rulesPerName = this.infoPerName[key];
for (var name in rulesPerName) {
@@ -649,7 +841,7 @@
}
};
-_OperRegistry.prototype.checkOperBindable =
+this.checkOperBindable =
function (oper, name, nodeHash) {
// Check if the binding with this oper could be done.
// Throw exception otherwise.
@@ -676,7 +868,7 @@
return rulesPerName;
};
-_OperRegistry.prototype.bindOper = function (oper) {
+this.bindOper = function (oper) {
// Marks binding between binder, eventName, node.
var name = oper.eventRule.kssSelector.name;
var nodeHash = kukit.rd.hashNode(oper.node);
@@ -693,7 +885,7 @@
// XXX This will need refactoring.
/// We would only want to lookup from our registry and not the other way around.
-_OperRegistry.prototype.processBindingEvents =
+this.processBindingEvents =
function (binder) {
var eventRegistry = kukit.eventsGlobalRegistry;
for (var i=0; i < eventRegistry.eventSets.length; i++) {
@@ -714,7 +906,7 @@
// XXX The following methods will probably disappear as iterators
// replace their functionality.
-_OperRegistry.prototype.getBoundOperForNode = function (name, node) {
+this.getBoundOperForNode = function (name, node) {
// Get the oper that is bound to a given eventName
// to a node in this binder
// returns null, if there is no such oper.
@@ -731,7 +923,7 @@
return oper;
};
-_OperRegistry.prototype.getBoundOpers = function (name) {
+this.getBoundOpers = function (name) {
// Get the opers bound to a given eventName (to any node)
// in this binder
var opers = [];
@@ -746,40 +938,7 @@
return opers;
};
-// Iterators
-// The getBindIterator returns a function that gets executed on
-// the oper registry.
-//
-// Iterators receive the eventSet as a parameter
-// plus a binder and a method. They need to iterate by calling this
-// as method.call(binder, ...); where ... can be any parms this
-// given iteration specifies.
-//
-
-er.getBindIterator = function(iterName) {
- // attempt to find canonical version of string
- // and shout if it does not match.
- // String must start uppercase.
- var canonical = iterName.substring(0, 1).toUpperCase() +
- iterName.substring(1);
- // Special case: allnodes -> AllNodes, not handled by
- // the previous line
- if (canonical == 'Allnodes') {
- canonical = 'AllNodes';
- }
- if (iterName != canonical) {
- // BBB 2007.12.31, this will turn into an exception.
-;;; var msg = 'Deprecated the lowercase iterator names in last ';
-;;; msg += 'parameters of ';
-;;; msg += 'kukit.eventsGlobalRegistry.registerForAllEvents, use [';
-;;; msg += canonical + '] instead of [' + iterName + '] (2007-12-31)';
-;;; kukit.logWarning(msg);
- iterName = canonical;
- }
- return _OperRegistry.prototype['_iterate' + iterName];
-};
-
-_OperRegistry.prototype.callBindMethod =
+this.callBindMethod =
function (eventSet, binder, p1, p2, p3, p4, p5, p6) {
var method = binder[eventSet.bindMethodName];
// Protect the binding for better logging
@@ -792,117 +951,7 @@
;;; throw new Error(kukit.E);
;;; }
};
-
-// This calls the bind method by each bound oper one by one.
-// Eventname and funcToBind are passed too.
-// this is the legacy ([EachLegacy]) way
-_OperRegistry.prototype._iterateEachLegacy =
- function (eventSet, binder) {
- for (var i=0; i<eventSet.names.length; i++) {
- var rulesPerName = this.infoPerName[eventSet.names[i]];
- if (typeof(rulesPerName) != 'undefined') {
- for (var nodeHash in rulesPerName) {
- var oper = rulesPerName[nodeHash];
- var eventName = oper.getEventName();
- var funcToBind = oper.makeExecuteActionsHook();
- this.callBindMethod(eventSet, binder, eventName,
- funcToBind, oper);
- }
- }
- }
-};
-
-
-// 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.
-_OperRegistry.prototype._iterateEach =
- function (eventSet, binder) {
- for (var i=0; i<eventSet.names.length; i++) {
- var rulesPerName = this.infoPerName[eventSet.names[i]];
- if (typeof(rulesPerName) != 'undefined') {
- for (var nodeHash in rulesPerName) {
- var oper = rulesPerName[nodeHash];
- this.callBindMethod(eventSet, binder, oper);
- }
- }
- }
-};
-
-// This calls the bind method by the list of bound opers
-_OperRegistry.prototype._iterateOpers =
- function (eventSet, binder) {
- var opers = [];
- for (var i=0; i<eventSet.names.length; i++) {
- var rulesPerName = this.infoPerName[eventSet.names[i]];
- if (typeof(rulesPerName) != 'undefined') {
- for (var nodeHash in rulesPerName) {
- opers.push(rulesPerName[nodeHash]);
- }
- }
- }
- this.callBindMethod(eventSet, binder, opers);
-};
-
-// This calls the bind method by a mapping eventName:oper
-// per each bound node individually
-_OperRegistry.prototype._iterateNode =
- function (eventSet, binder) {
- for (var nodeHash in this.infoPerNode) {
- var rulesPerNode = this.infoPerNode[nodeHash];
- // filter only the events we are interested in
- var filteredRules = {};
- var operFound = false;
- for (var i=0; i<eventSet.names.length; i++) {
- var name = eventSet.names[i];
- var oper = rulesPerNode[name];
- if (typeof(oper) != 'undefined') {
- filteredRules[name] = oper;
- operFound = oper;
- }
- }
- // call it
- // All opers have the same node, the last one is yet in operFound, so
- // we use it as a second parameter to the call.
- // The method may or may not want to use this.
- if (operFound) {
- this.callBindMethod(eventSet, binder, filteredRules,
- operFound.node);
- }
- }
-};
-
-// 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
-_OperRegistry.prototype._iterateAllNodes =
- function (eventSet, binder) {
- var items = [];
- var hasResult = false;
- for (var nodeHash in this.infoPerNode) {
- var rulesPerNode = this.infoPerNode[nodeHash];
- // filter only the events we are interested in
- var filteredRules = {};
- var operFound = false;
- for (var i=0; i<eventSet.names.length; i++) {
- var name = eventSet.names[i];
- var oper = rulesPerNode[name];
- if (typeof(oper) != 'undefined') {
- filteredRules[name] = oper;
- operFound = oper;
- }
- }
- if (operFound) {
- var item = {node: operFound.node,
- opersByEventName: filteredRules};
- items.push(item);
- hasResult = true;
- }
- }
- // call the binder method
- if (hasResult) {
- this.callBindMethod(eventSet, binder, items);
- }
+this.initialize.apply(this, arguments);
};
er.makeId = function(namespace, name) {
Modified: kukit/kukit.js/trunk/kukit/forms.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/forms.js (original)
+++ kukit/kukit.js/trunk/kukit/forms.js Thu Jan 10 13:53:49 2008
@@ -35,23 +35,29 @@
/*
* class _FormQueryElem
*/
-var _FormQueryElem = function(name, value) {
+var _FormQueryElem = function() {
+
+this.initialize = function(name, value) {
this.name = name;
this.value = value;
};
-_FormQueryElem.prototype.encode = function() {
+this.encode = function() {
return this.name+ "=" + encodeURIComponent(this.value);
};
+this.initialize.apply(this, arguments);
+};
/*
* class FormQuery
*/
fo.FormQuery = function() {
+
+this.initialize = function() {
this.l = [];
};
-fo.FormQuery.prototype.appendElem = function(name, value) {
+this.appendElem = function(name, value) {
if (value == null) {
// do not marshall nulls
;;; var msg = "Parameter '" + name + "' is null,";
@@ -84,7 +90,7 @@
}
};
-fo.FormQuery.prototype.encode = function() {
+this.encode = function() {
var poster = [];
for (var i=0;i < this.l.length;i++) {
poster[poster.length] = this.l[i].encode();
@@ -92,7 +98,7 @@
return poster.join("&");
};
-fo.FormQuery.prototype.toDict = function() {
+this.toDict = function() {
var d = {};
for (var i=0;i < this.l.length;i++) {
var elem = this.l[i];
@@ -100,6 +106,8 @@
}
return d;
};
+this.initialize.apply(this, arguments);
+};
/* Form data extraction, helpers */
@@ -120,11 +128,13 @@
*
*/
-fo.CurrentFormLocator = function(target) {
+fo.CurrentFormLocator = function() {
+
+this.initialize = function(target) {
this.target = target;
-};
+}
-fo.CurrentFormLocator.prototype.queryForm = function() {
+this.queryForm = function() {
// Find the form that contains the target node.
return findContainer(this.target, function(node) {
if (!node.nodeName) {
@@ -138,7 +148,7 @@
});
};
-fo.CurrentFormLocator.prototype.getForm = function() {
+this.getForm = function() {
var form = this.queryForm();
if (!form) {
;;; kukit.logWarning("No form found");
@@ -146,23 +156,28 @@
}
return form;
};
+this.initialize.apply(this, arguments);
+};
/*
* class NamedFormLocator: gets the form with a given name
*
*/
-fo.NamedFormLocator = function(formname) {
+fo.NamedFormLocator = function() {
+
+this.initialize = function(formname) {
this.formname = formname;
};
-fo.NamedFormLocator.prototype.queryForm = function() {
+this.getForm = fo.CurrentFormLocator.getForm;
+
+this.queryForm = function() {
// Find the form with the given name.
return document.forms[this.formname];
};
-fo.NamedFormLocator.prototype.getForm =
- fo.CurrentFormLocator.prototype.getForm;
+};
/* methods to take the desired value(s) from the form */
@@ -278,10 +293,12 @@
* class _FieldUpdateRegistry
*/
var _FieldUpdateRegistry = function() {
+
+this.initialize = function() {
this.editors = {};
};
-_FieldUpdateRegistry.prototype.register = function(node, editor) {
+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.';
@@ -293,7 +310,7 @@
editor.doInit();
};
-_FieldUpdateRegistry.prototype.doUpdate = function(node) {
+this.doUpdate = function(node) {
var hash = kukit.rd.hashNode(node);
var editor = this.editors[hash];
if (typeof(editor) != 'undefined') {
@@ -301,6 +318,8 @@
//kukit.logDebug('Updated '+node.name + ' hash=' + hash);
}
};
+this.initialize.apply(this, arguments);
+};
// fieldUpdateRegistry is a public service, available to all components
// that want to be notified when kss wants to use a field value.
@@ -321,20 +340,22 @@
* class _FormValueProvider
*
*/
-var _FormValueProvider = function() {};
+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 fo.NamedFormLocator(args[0]);
- var collector = new kukit.ut.TupleCollector();
- return fo.getAllFormVars(locator, collector);
- }
+this.check = function(args) {
+;;; if (args.length != 1) {
+;;; throw new Error('form method needs 1 arguments (formname)');
+;;; }
};
+
+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 +363,22 @@
* 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 fo.CurrentFormLocator(node);
- var collector = new kukit.ut.TupleCollector();
- return fo.getAllFormVars(locator, collector);
- }
+var _CurrentFormValueProvider = function() {
+
+this.check = function(args) {
+;;; if (args.length != 0) {
+;;; throw new Error('currentForm method needs no argument');
+;;; }
+};
+
+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/trunk/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kssparser.js (original)
+++ kukit/kukit.js/trunk/kukit/kssparser.js Thu Jan 10 13:53:49 2008
@@ -19,46 +19,85 @@
/* Tokens of the KSS parser */
-kukit.kssp = {};
+kukit.kssp = new function() { /// MODULE START
+
+var kssp = this;
/* Tokens */
-kukit.kssp.openComment = kukit.tk.mkToken('openComment', "\/\*");
-kukit.kssp.closeComment = kukit.tk.mkToken('closeComment', "\*\/");
-kukit.kssp.openBrace = kukit.tk.mkToken('openBrace', "{");
-kukit.kssp.closeBrace = kukit.tk.mkToken('closeBrace', "}");
-kukit.kssp.openBracket = kukit.tk.mkToken('openBracket', "[");
-kukit.kssp.closeBracket = kukit.tk.mkToken('closeBracket', "]");
-kukit.kssp.openParent = kukit.tk.mkToken('openParent', "(");
-kukit.kssp.closeParent = kukit.tk.mkToken('closeParent', ")");
-kukit.kssp.semicolon = kukit.tk.mkToken('semicolon', ";");
-kukit.kssp.colon = kukit.tk.mkToken('colon', ":");
-kukit.kssp.quote = kukit.tk.mkToken('quote', "'");
-kukit.kssp.dquote = kukit.tk.mkToken('dquote', '"');
-kukit.kssp.backslash = kukit.tk.mkToken('backslash', '\x5c');
-kukit.kssp.comma = kukit.tk.mkToken('comma', ",");
-kukit.kssp.equals = kukit.tk.mkToken('equals', "=");
+kssp.openComment = kukit.tk.mkToken('openComment', "\/\*");
+kssp.closeComment = kukit.tk.mkToken('closeComment', "\*\/");
+kssp.openBrace = kukit.tk.mkToken('openBrace', "{");
+kssp.closeBrace = kukit.tk.mkToken('closeBrace', "}");
+kssp.openBracket = kukit.tk.mkToken('openBracket', "[");
+kssp.closeBracket = kukit.tk.mkToken('closeBracket', "]");
+kssp.openParent = kukit.tk.mkToken('openParent', "(");
+kssp.closeParent = kukit.tk.mkToken('closeParent', ")");
+kssp.semicolon = kukit.tk.mkToken('semicolon', ";");
+kssp.colon = kukit.tk.mkToken('colon', ":");
+kssp.quote = kukit.tk.mkToken('quote', "'");
+kssp.dquote = kukit.tk.mkToken('dquote', '"');
+kssp.backslash = kukit.tk.mkToken('backslash', '\x5c');
+kssp.comma = kukit.tk.mkToken('comma', ",");
+kssp.equals = kukit.tk.mkToken('equals', "=");
/* Parsers */
+/* Helpers */
+
+var _emitAndReturn = function() {
+ return this.emitAndReturn();
+};
+
+var _mkEmitAndReturnToken = function(klass) {
+ return function() {
+ var token = new klass(this.cursor);
+ return this.emitAndReturn(token);
+ };
+};
+
+var _mkReturnToken = function(klass) {
+ return function() {
+ return new klass(this.cursor);
+ };
+};
+
+var _returnComment = function() {
+ return new kssp.Comment(this.cursor, kssp.openComment)
+};
+
+var _returnString = function() {
+ return new kssp.String(this.cursor, kssp.quote)
+};
+
+var _returnString2 = function() {
+ return new kssp.String2(this.cursor, kssp.dquote)
+};
+
+var _returnMethodArgs = function() {
+ return new kssp.MethodArgs(this.cursor, kssp.openParent)
+};
+
+var _returnBackslashed = function() {
+ return new kssp.Backslashed(this.cursor, kssp.backslash)
+};
+
/*
* class Document
*/
-kukit.kssp.Document = kukit.tk.mkParser('document', {
- "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
- "{": 'new kukit.kssp.Block(this.cursor, kukit.kssp.openBrace)'
- });
-kukit.kssp.Document.prototype.process = function() {
+var _Document = function() {
+
+this.process = function() {
this.eventRules = [];
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
while (context.nextTokenIndex < this.result.length) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
var key = context.txt;
if (! key) {
break;
}
- this.expectToken(context, kukit.kssp.Block);
+ this.expectToken(context, kssp.Block);
var block = context.token;
var rules = block.parseSelectors(key);
this.addRules(rules);
@@ -67,60 +106,73 @@
this.txt = '';
};
-kukit.kssp.Document.prototype.addRules = function(rules) {
+this.addRules = function(rules) {
// Create the event rules.
for(var i=0; i<rules.length; i++) {
this.eventRules.push(rules[i]);
};
};
+};
+kssp.Document = kukit.tk.mkParser('document', {
+ "\/\*": _returnComment,
+ "{": function() {
+ return new kssp.Block(this.cursor, kssp.openBrace)
+ }
+ },
+ _Document
+ );
+
/*
* class Comment
*/
-kukit.kssp.Comment = kukit.tk.mkParser('comment', {
- // it's not 100% good, but will do
- "\*\/": 'this.emitAndReturn(new kukit.kssp.closeComment(this.cursor))'
- });
-kukit.kssp.Comment.prototype.process = function() {
+var _Comment = function() {
+
+this.process = function() {
this.result = [];
this.txt = ' ';
};
+};
+kssp.Comment = kukit.tk.mkParser('comment', {
+ // it's not 100% good, but will do
+ "\*\/": _mkEmitAndReturnToken(kssp.closeComment)
+ },
+ _Comment
+ );
+
/*
* class Block
*/
-kukit.kssp.Block = kukit.tk.mkParser('block', {
- ";": 'new kukit.kssp.semicolon(this.cursor)',
- ":": '[new kukit.kssp.colon(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
- "}": 'this.emitAndReturn(new kukit.kssp.closeBrace(this.cursor))'
- });
-kukit.kssp.Block.prototype.process = function() {
+var _Block = function() {
+
+this.process = function() {
//this.parms = {};
this.eventFullNames = {};
this.actions = new kukit.rd.ActionSet();
// Parse all tokens (except first and last)
var context = {'nextTokenIndex': 1};
while (context.nextTokenIndex < this.result.length-1) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
var key = context.txt;
if (! key) {
break;
}
- this.expectToken(context, kukit.kssp.colon);
- this.expectToken(context, kukit.kssp.PropValue);
+ this.expectToken(context, kssp.colon);
+ this.expectToken(context, kssp.PropValue);
// store the wrapped prop
this.addDeclaration(key, context.token.value);
if (context.nextTokenIndex == this.result.length-1) break;
- this.expectToken(context, kukit.kssp.semicolon);
+ this.expectToken(context, kssp.semicolon);
}
this.result = [];
this.txt = '';
};
-kukit.kssp.Block.prototype.parseSelectors = function(key) {
+this.parseSelectors = function(key) {
// Parse the part in an embedded parser
var cursor = new kukit.tk.Cursor(key + ' ');
- var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ var parser = new kssp.KssSelectors(cursor, null, true);
var results = [];
var hasFullNames = false;
for(var eventFullName in this.eventFullNames) {
@@ -163,9 +215,9 @@
}
}
return results;
-}
+};
-kukit.kssp.Block.prototype.addEventDeclaration = function(key, splitkey, value) {
+this.addEventDeclaration = function(key, splitkey, value) {
// evt-<EVTNAME>-<PARAMETER>: <VALUE>
// evt-<NAMESPACE>-<EVTNAME>-<PARAMETER>: <VALUE>
@@ -206,9 +258,9 @@
eventParameters = this.eventFullNames[eventFullName];
}
eventParameters[eventKey] = value.txt;
-}
+};
-kukit.kssp.Block.prototype.addActionDeclaration = function(key, splitkey, value) {
+this.addActionDeclaration = function(key, splitkey, value) {
// action-server: <ACTIONNAME>
// action-client: <ACTIONNAME>
// action-client: <NAMESPACE>-<ACTIONNAME>
@@ -218,13 +270,13 @@
;;; kukit.E = 'Wrong key [' + key + '] : ';
;;; kukit.E += 'action-<QUALIFIER> keys can have only one dash.';
;;; this.emitError(kukit.E);
-;;; }
+;;; }
;;; if (value.isMethod != false) {
;;; kukit.E = 'Wrong value for key [' + key + '] : ';
;;; kukit.E += 'value providers are not ';
;;; kukit.E += 'allowed for action-<QUALIFIER> keys.';
;;; this.emitError(kukit.E);
-;;; }
+;;; }
var atab = {'server': 'S', 'client': 'C', 'cancel': 'X'};
var actionType = atab[splitkey[1]];
;;; if (! actionType) {
@@ -232,7 +284,7 @@
;;; kukit.E += 'qualifier in action-<QUALIFIER> keys must be ';
;;; kukit.E += '"server" or "client" or "cancel".';
;;; this.emitError(kukit.E);
-;;; }
+;;; }
;;; // force value to be <ACTIONNAME> or <NAMESPACE>-<ACTIONNAME>
;;; var splitvalue = value.txt.split('-');
;;; if (splitvalue.length > 2) {
@@ -240,7 +292,7 @@
;;; kukit.E += 'value must be <ACTIONNAME> or <NAMESPACE>';
;;; kukit.E += '-<ACTIONNAME> for action-<QUALIFIER> keys.';
;;; this.emitError(kukit.E);
-;;; }
+;;; }
// set it
var action = this.actions.getOrCreateAction(value.txt);
if (actionType != 'X' || action.type == null) {
@@ -248,9 +300,9 @@
} else {
this.actions.deleteAction(value.txt);
}
-}
+};
-kukit.kssp.Block.prototype.addActionError = function(action, key, value) {
+this.addActionError = function(action, key, value) {
// <ACTIONNAME>-error: <VALUE>
// default-error: <VALUE>
;;; if (value.isMethod == true) {
@@ -263,9 +315,9 @@
// also create the action for the error itself.
var err_action = this.actions.getOrCreateAction(value.txt);
err_action.setType('E');
-}
+};
-kukit.kssp.Block.prototype.addActionParameter = function(action, key, value) {
+this.addActionParameter = function(action, key, value) {
var ppRegistries = {
'': kukit.pprovidersGlobalRegistry,
'kssSelector': kukit.sr.pproviderSelRegistry,
@@ -297,9 +349,9 @@
this.emitError(kukit.E);
}
action.parms[key] = value;
-}
+};
-kukit.kssp.Block.prototype.addDeclaration = function(key, value) {
+this.addDeclaration = function(key, value) {
// p.s. value is here a KssXxParm. In most cases we check and unwrap it.
// the keys look like this:
//
@@ -365,26 +417,30 @@
}
};
+};
+kssp.Block = kukit.tk.mkParser('block', {
+ ";": _mkReturnToken(kssp.semicolon),
+ ":": function() {
+ return [new kssp.colon(this.cursor),
+ new kssp.PropValue(this.cursor)]
+ },
+ "}": _mkEmitAndReturnToken(kssp.closeBrace)
+ },
+ _Block
+ );
+
/*
* class PropValue
*/
-kukit.kssp.PropValue = kukit.tk.mkParser('propValue', {
- ";": 'this.emitAndReturn()',
- "}": 'this.emitAndReturn()',
- ")": 'this.emitAndReturn()',
- ",": 'this.emitAndReturn()',
- "'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
- '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
- "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
- "(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)'
- });
-kukit.kssp.PropValue.prototype.process = function() {
+var _PropValue = function() {
+
+this.process = function() {
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
this.txt = '';
var txt = context.txt;
- if (this.notInTokens(context, kukit.kssp.String)) {
+ if (this.notInTokens(context, kssp.String)) {
// The previous txt must be all whitespace.
if (txt) {
;;; kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
@@ -392,9 +448,9 @@
this.emitError(kukit.E);
}
// the next one must be a string.
- this.expectToken(context, kukit.kssp.String);
+ this.expectToken(context, kssp.String);
this.produceTxt(context.token.txt);
- } else if (this.notInTokens(context, kukit.kssp.MethodArgs)) {
+ } else if (this.notInTokens(context, kssp.MethodArgs)) {
// see if not empty and has no spaces in it
if (! txt || txt.indexOf(' ') != -1) {
;;; kukit.E = 'Wrong value : method name [' + txt + '] cannot ';
@@ -402,7 +458,7 @@
this.emitError(kukit.E);
}
// the next one must be the rules
- this.expectToken(context, kukit.kssp.MethodArgs);
+ this.expectToken(context, kssp.MethodArgs);
this.value = new this.valueClass(txt, context.token.args);
} else {
// not a string or method: check if we allowed multiword.
@@ -414,7 +470,7 @@
}
// see what's after
if (context.nextTokenIndex < this.result.length) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
// we have to be at the end and have no text after
if (context.nextTokenIndex < this.result.length || context.txt) {
;;; kukit.E = 'Wrong value : unallowed characters after ';
@@ -424,60 +480,80 @@
}
this.result = [];
};
-kukit.kssp.PropValue.prototype.multiword_allowed = true;
-kukit.kssp.PropValue.prototype.valueClass = kukit.rd.KssMethodValue;
-kukit.kssp.PropValue.prototype.produceTxt = function(txt) {
+
+this.initialize = function() {
+ this.multiword_allowed = true;
+ this.valueClass = kukit.rd.KssMethodValue;
+};
+
+this.produceTxt = function(txt) {
// txt parms are returned embedded
this.value = new kukit.rd.KssTextValue(txt);
};
+this.initialize.apply(this, arguments);
+};
+kssp.PropValue = kukit.tk.mkParser('propValue', {
+ ";": _emitAndReturn,
+ "}": _emitAndReturn,
+ ")": _emitAndReturn,
+ ",": _emitAndReturn,
+ "'": _returnString,
+ '"': _returnString2,
+ "\/\*": _returnComment,
+ "(": _returnMethodArgs
+ },
+ _PropValue
+ );
/*
* class PropValueInMethod
*
* PropValue in method cannot have method-style vars.
*/
-kukit.kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
- ";": 'this.emitAndReturn()',
- "}": 'this.emitAndReturn()',
- ")": 'this.emitAndReturn()',
- "]": 'this.emitAndReturn()',
- ",": 'this.emitAndReturn()',
- "'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
- '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
- "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
- });
-kukit.kssp.PropValueInMethod.prototype.multiword_allowed = false;
-kukit.kssp.PropValueInMethod.prototype.process =
- kukit.kssp.PropValue.prototype.process;
-kukit.kssp.PropValueInMethod.prototype.produceTxt = function(txt) {
+var _PropValueInMethod = function() {
+
+this.initialize = function() {
+ this.multiword_allowed = false;
+};
+
+this.produceTxt = function(txt) {
// txt parms are returned unwrapped
this.txt = txt;
};
+this.initialize.apply(this, arguments);
+};
+// this assignment needs to remain after initialization of _PropValue
+kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
+ ";": _emitAndReturn,
+ "}": _emitAndReturn,
+ ")": _emitAndReturn,
+ "]": _emitAndReturn,
+ ",": _emitAndReturn,
+ "'": _returnString,
+ '"': _returnString2,
+ "\/\*": _returnComment
+ },
+ _PropValueInMethod
+ );
+kssp.PropValueInMethod.prototype.process = kssp.PropValue.prototype.process;
/*
* class EventValue
*
-* PropValue in pseudo must be single word with no spaces around.
*/
-kukit.kssp.EventValue = kukit.tk.mkParser('propValue', {
- "{": 'this.emitAndReturn()',
- " ": 'this.emitAndReturn()',
- "\t": 'this.emitAndReturn()',
- "\n": 'this.emitAndReturn()',
- "\r": 'this.emitAndReturn()',
- "\/\*": 'this.emitAndReturn()',
- ":": 'this.emitAndReturn()',
- "(": '[new kukit.kssp.openParent(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
- ")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))'
- });
-kukit.kssp.EventValue.prototype.multiword_allowed = false;
-kukit.kssp.EventValue.prototype.process = function() {
+var _EventValue = function() {
+
+this.initialize = function() {
+ this.multiword_allowed = false;
+};
+
+this.process = function() {
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
this.txt = '';
var txt = context.txt;
- if (this.notInTokens(context, kukit.kssp.String)) {
+ if (this.notInTokens(context, kssp.String)) {
// The previous txt must be all whitespace.
if (txt) {
;;; kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
@@ -485,13 +561,13 @@
this.emitError(kukit.E);
}
// the next one must be a string.
- this.expectToken(context, kukit.kssp.String);
+ this.expectToken(context, kssp.String);
this.produceTxt(context.token.txt);
- } else if (this.notInTokens(context, kukit.kssp.openParent)) {
- this.expectToken(context, kukit.kssp.openParent);
- this.expectToken(context, kukit.kssp.PropValue);
+ } else if (this.notInTokens(context, kssp.openParent)) {
+ this.expectToken(context, kssp.openParent);
+ this.expectToken(context, kssp.PropValue);
this.value = new kukit.rd.KssEventValue(txt, context.token.value);
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
// we have to be at the end and have no text after
if (context.txt) {
;;; kukit.E = 'Wrong event selector : [' + context.txt;
@@ -501,7 +577,7 @@
this.emitError(kukit.E);
}
// eat up everything before the closing parent
- this.expectToken(context, kukit.kssp.closeParent);
+ this.expectToken(context, kssp.closeParent);
} else {
// not a string or method: check if we allowed multiword.
if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
@@ -512,7 +588,7 @@
}
// see what's after
if (context.nextTokenIndex < this.result.length) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
// we have to be at the end and have no text after
if (context.nextTokenIndex < this.result.length || context.txt) {
;;; kukit.E = 'Excess characters after the property value';
@@ -522,19 +598,35 @@
this.result = [];
};
-kukit.kssp.EventValue.prototype.produceTxt = function(txt) {
+this.produceTxt = function(txt) {
// txt parms are returned embedded
this.value = new kukit.rd.KssEventValue(txt, null);
};
+this.initialize.apply(this, arguments);
+};
+kssp.EventValue = kukit.tk.mkParser('propValue', {
+ "{": _emitAndReturn,
+ " ": _emitAndReturn,
+ "\t": _emitAndReturn,
+ "\n": _emitAndReturn,
+ "\r": _emitAndReturn,
+ "\/\*": _emitAndReturn,
+ ":": _emitAndReturn,
+ "(": function() {
+ return [new kssp.openParent(this.cursor),
+ new kssp.PropValue(this.cursor)]
+ },
+ ")": _mkEmitAndReturnToken(kssp.closeParent)
+ },
+ _EventValue
+ );
/*
* class String
*/
-kukit.kssp.String = kukit.tk.mkParser('string', {
- "'": 'this.emitAndReturn(new kukit.kssp.quote(this.cursor))',
- '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
- });
-kukit.kssp.String.prototype.process = function() {
+var _String = function() {
+
+this.process = function() {
// collect up the value of the string, omitting the quotes
this.txt = '';
for (var i=1; i<this.result.length-1; i++) {
@@ -542,23 +634,30 @@
}
};
+};
+kssp.String = kukit.tk.mkParser('string', {
+ "'": _mkEmitAndReturnToken(kssp.quote),
+ '\x5c': _returnBackslashed
+ },
+ _String
+ );
+
/*
* class String2
*/
-kukit.kssp.String2 = kukit.tk.mkParser('string', {
- '"': 'this.emitAndReturn(new kukit.kssp.dquote(this.cursor))',
- '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
- });
-kukit.kssp.String2.prototype.process = kukit.kssp.String.prototype.process;
+kssp.String2 = kukit.tk.mkParser('string', {
+ '"': _mkEmitAndReturnToken(kssp.dquote),
+ '\x5c': _returnBackslashed
+ },
+ _String
+ );
/*
* class StringInSelector
*/
-kukit.kssp.StringInSelector = kukit.tk.mkParser('string', {
- "'": 'this.emitAndReturn(new kukit.kssp.quote(this.cursor))',
- '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
- });
-kukit.kssp.StringInSelector.prototype.process = function() {
+var _StringInSelector = function() {
+
+this.process = function() {
// collect up the value of the string, including the quotes
this.txt = '';
for (var i=0; i<this.result.length; i++) {
@@ -566,20 +665,30 @@
}
};
+};
+kssp.StringInSelector = kukit.tk.mkParser('string', {
+ "'": _mkEmitAndReturnToken(kssp.quote),
+ '\x5c': _returnBackslashed
+ },
+ _StringInSelector
+ );
+
/*
* class String2InSelector
*/
-kukit.kssp.String2InSelector = kukit.tk.mkParser('string', {
- '"': 'this.emitAndReturn(new kukit.kssp.dquote(this.cursor))',
- '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
- });
-kukit.kssp.String2InSelector.prototype.process = kukit.kssp.StringInSelector.prototype.process;
+kssp.String2InSelector = kukit.tk.mkParser('string', {
+ '"': _mkEmitAndReturnToken(kssp.dquote),
+ '\x5c': _returnBackslashed
+ },
+ _StringInSelector
+ );
/*
* class Backslashed
*/
-kukit.kssp.Backslashed = kukit.tk.mkParser('backslashed', {});
-kukit.kssp.Backslashed.prototype.nextStep = function(table) {
+var _Backslashed = function() {
+
+this.nextStep = function(table) {
// digest the next character and store it as txt
var cursor = this.cursor;
var length = cursor.text.length;
@@ -592,35 +701,36 @@
this.finished = true;
}
};
-kukit.kssp.Backslashed.prototype.process = function() {
+
+this.process = function() {
this.txt = this.result[1].txt;
};
+};
+kssp.Backslashed = kukit.tk.mkParser('backslashed', {
+ },
+ _Backslashed
+ );
+
/*
* class MethodArgs
*
* methodargs are (a, b, c) lists.
*/
-kukit.kssp.MethodArgs = kukit.tk.mkParser('methodargs', {
- "'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
- '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
- ",": 'new kukit.kssp.comma(this.cursor)',
- ")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))',
- "(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)',
- "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
- });
-kukit.kssp.MethodArgs.prototype.process = function() {
+var _MethodArgs = function() {
+
+this.process = function() {
this.args = [];
// Parse all tokens (except first and last)
var context = {'nextTokenIndex': 1};
while (context.nextTokenIndex < this.result.length-1) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
var value = context.txt;
if (! value) {
// allow to bail out after widow ,
if (context.nextTokenIndex == this.result.length-1) break;
// here be a string then.
- this.expectToken(context, kukit.kssp.String);
+ this.expectToken(context, kssp.String);
value = context.token.txt;
} else {
// Just a value, must be one word then.
@@ -634,8 +744,8 @@
var valueClass;
var args;
var providedValue;
- if (this.notInTokens(context, kukit.kssp.MethodArgs)){
- this.expectToken(context, kukit.kssp.MethodArgs);
+ if (this.notInTokens(context, kssp.MethodArgs)){
+ this.expectToken(context, kssp.MethodArgs);
valueClass = kukit.rd.KssMethodValue;
args = context.token.args;
providedValue = new valueClass(value, args);
@@ -647,12 +757,24 @@
}
this.args.push(providedValue);
if (context.nextTokenIndex == this.result.length-1) break;
- this.expectToken(context, kukit.kssp.comma);
+ this.expectToken(context, kssp.comma);
}
this.result = [];
this.txt = '';
};
+};
+kssp.MethodArgs = kukit.tk.mkParser('methodargs', {
+ "'": _returnString,
+ '"': _returnString2,
+ ",": _mkReturnToken(kssp.comma),
+ ")": _mkEmitAndReturnToken(kssp.closeParent),
+ "(": _returnMethodArgs,
+ "\/\*": _returnComment
+ },
+ _MethodArgs
+ );
+
/*
* class KssSelectors
*
@@ -662,25 +784,20 @@
* KSS method selector: (has no spaces in it)
* document:name(id) or behaviour:name(id)
*/
-kukit.kssp.KssSelectors = kukit.tk.mkParser('kssselectors', {
- "'": 'new kukit.kssp.StringInSelector(this.cursor, kukit.kssp.quote)',
- '"': 'new kukit.kssp.String2InSelector(this.cursor, kukit.kssp.dquote)',
- ",": 'new kukit.kssp.comma(this.cursor)',
- "{": 'this.emitAndReturn()',
- "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
- });
-kukit.kssp.KssSelectors.prototype.process = function() {
+var _KssSelectors = function() {
+
+this.process = function() {
this.selectors = [];
// Parse all tokens (including first and last)
var context = {'nextTokenIndex': 0};
while (context.nextTokenIndex < this.result.length) {
- this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment,
- kukit.kssp.String, kukit.kssp.String2);
+ this.digestTxt(context, kukit.tk.Fraction, kssp.Comment,
+ kssp.String, kssp.String2);
var cursor = new kukit.tk.Cursor(context.txt + ' ')
- var parser = new kukit.kssp.KssSelector(cursor, null, true);
+ var parser = new kssp.KssSelector(cursor, null, true);
this.selectors.push(parser.kssSelector);
if (context.nextTokenIndex == this.result.length) break;
- this.expectToken(context, kukit.kssp.comma);
+ this.expectToken(context, kssp.comma);
if (context.nextTokenIndex == this.result.length) {
;;; kukit.E = 'Wrong event selector : trailing comma';
this.emitError(kukit.E);
@@ -690,6 +807,21 @@
this.txt = '';
};
+};
+kssp.KssSelectors = kukit.tk.mkParser('kssselectors', {
+ "'": function() {
+ return new kssp.StringInSelector(this.cursor, kssp.quote)
+ },
+ '"': function() {
+ return new kssp.String2InSelector(this.cursor, kssp.dquote)
+ },
+ ",": _mkReturnToken(kssp.comma),
+ "{": _emitAndReturn,
+ "\/\*": _returnComment
+ },
+ _KssSelectors
+ );
+
/*
* class KssSelector
*
@@ -701,13 +833,9 @@
* document:name(id) or behaviour:name(id)
* document:name(pprov(id)) or behaviour:name(pprov(id))
*/
-kukit.kssp.KssSelector = kukit.tk.mkParser('kssselector', {
- ":": '[new kukit.kssp.colon(this.cursor), new ' +
- 'kukit.kssp.EventValue(this.cursor)]',
- "{": 'this.emitAndReturn()',
- "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
- });
-kukit.kssp.KssSelector.prototype.process = function() {
+var _KssSelector = function() {
+
+this.process = function() {
var name;
var namespace = null;
var id = null;
@@ -728,7 +856,7 @@
this.emitError(kukit.E);
}
} break;
- case kukit.kssp.Comment.prototype.symbol: {
+ case kssp.Comment.prototype.symbol: {
tokenIndex -= 1;
} break;
default: {
@@ -740,9 +868,9 @@
tokenIndex -= 2;
if (tokenIndex < 0
|| (this.result[tokenIndex+2].symbol !=
- kukit.kssp.EventValue.prototype.symbol)
+ kssp.EventValue.prototype.symbol)
|| (this.result[tokenIndex+1].symbol !=
- kukit.kssp.colon.prototype.symbol)
+ kssp.colon.prototype.symbol)
|| (this.result[tokenIndex].symbol !=
kukit.tk.Fraction.prototype.symbol)) {
;;; kukit.E = 'Wrong event selector : missing event qualifier ';
@@ -806,7 +934,7 @@
// Protect the error for better logging
;;; try {
this.kssSelector = new kukit.rd.KssSelector(isEvent, css, name,
- namespace, id, ppid);
+ namespace, id, ppid, kukit.eventsGlobalRegistry);
;;; } catch(e) {
;;; if (e.name == 'KssSelectorError') {
;;; // Log the message
@@ -819,18 +947,32 @@
this.result = [];
};
+};
+kssp.KssSelector = kukit.tk.mkParser('kssselector', {
+ ":": function() {
+ return [new kssp.colon(this.cursor),
+ new kssp.EventValue(this.cursor)]
+ },
+ "{": _emitAndReturn,
+ "\/\*": _returnComment
+ },
+ _KssSelector
+ );
+
/*
* class KssRuleProcessor
*
* Rule processor that interfaces with kukit core
*/
-kukit.kssp.KssRuleProcessor = function(href) {
+kssp.KssRuleProcessor = function(href) {
+
+this.initialize = function() {
this.href = href;
this.loaded = false;
this.rules = [];
};
-
-kukit.kssp.KssRuleProcessor.prototype.load = function() {
+
+this.load = function() {
// Opera does not support getDomDocument.load, so we use XMLHttpRequest
var domDoc = new XMLHttpRequest();
domDoc.open("GET", this.href, false);
@@ -839,11 +981,11 @@
this.loaded = true;
};
-kukit.kssp.KssRuleProcessor.prototype.parse = function() {
+this.parse = function() {
;;; try {
//Build a parser and parse the text into it
var cursor = new kukit.tk.Cursor(this.txt);
- var parser = new kukit.kssp.Document(cursor, null, true);
+ var parser = new kssp.Document(cursor, null, true);
// Store event rules in the common list
for (var i=0; i<parser.eventRules.length; i++) {
var rule = parser.eventRules[i];
@@ -859,4 +1001,7 @@
;;; }
;;; }
};
+this.initialize.apply(this, arguments);
+};
+}(); /// MODULE END
Modified: kukit/kukit.js/trunk/kukit/kukit.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kukit.js (original)
+++ kukit/kukit.js/trunk/kukit/kukit.js Thu Jan 10 13:53:49 2008
@@ -17,6 +17,8 @@
* 02111-1307, USA.
*/
+/*global kukit, document, window */
+
kukit = new function() { /// MODULE START
var ku = this;
@@ -24,23 +26,47 @@
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 _RuleSheetLink
+*/
+var _RuleSheetLink = function(href, res_type) {
+ this.href = href;
+ this.res_type = res_type;
+};
+
/*
* class Engine
*/
ku.Engine = function() {
- this.baseUrl = this.calculateBase();
+
+this.initialize = function() {
this.documentRules = new kukit.rd.MethodTable();
// table from res_type to rule processor
this._ruleProcessorClasses = {};
// register processor for type kss
- this._ruleProcessorClasses['kss'] = kukit.kssp.KssRuleProcessor;
- this._ruleProcessors = new Array();
+ this._ruleProcessorClasses.kss = kukit.kssp.KssRuleProcessor;
+ this._ruleProcessors = [];
this.bindScheduler = new kukit.ut.SerializeScheduler();
// State vars storage. This can be used from kss via a method.
this.stateVariables = {};
// instantiate request manager
- this.requestManager = new kukit.rm.RequestManager();
+ this.requestManager = new kukit.rm.RequestManager(4);
this.binderInfoRegistry = new kukit.er.BinderInfoRegistry();
// instantiate a load scheduler
this.loadScheduler = new kukit.rd.LoadActions();
@@ -48,10 +74,10 @@
// setup events queuing, collect them at the end of commands
this.setupEventsQueue = [];
this.setupEventsInProgress = false;
-
+ this.baseUrl = this.calculateBase();
};
-ku.Engine.prototype.calculateBase = function() {
+this.calculateBase = function() {
var base = '';
try {
var _dummy = document;
@@ -70,8 +96,8 @@
}
}
nodes = document.getElementsByTagName("base");
- if (nodes.length == 0) {
- var base = window.location.href;
+ if (nodes.length === 0) {
+ base = window.location.href;
var pieces = base.split('/');
pieces.pop();
base = pieces.join('/');
@@ -86,7 +112,7 @@
return base;
};
-ku.Engine.prototype.getRuleSheetLinks = function() {
+this.getRuleSheetLinks = function() {
var nodes = document.getElementsByTagName("link");
var results = [];
for (var i=0; i<nodes.length; i++) {
@@ -106,17 +132,18 @@
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;
+this.createRuleProcessor = function(rulelink) {
+ var _RuleProcessorClass = this._ruleProcessorClasses[rulelink.res_type];
+;;; var msg = '';
+ if (_RuleProcessorClass) {
+;;; msg = "Start loading and processing " + rulelink.href;
;;; msg = msg + " of type " + rulelink.res_type;
;;; kukit.log(msg);
- var ruleprocessor = new ruleProcessorClass(rulelink.href);
+ var ruleprocessor = new _RuleProcessorClass(rulelink.href);
this._ruleProcessors[this._ruleProcessors.length] = ruleprocessor;
return ruleprocessor;
;;; } else {
-;;; var msg = "Ignore rulesheet " + rulelink.href;
+;;; msg = "Ignore rulesheet " + rulelink.href;
;;; msg = msg + " of type " + rulelink.res_type;
;;; kukit.log(msg);
}
@@ -124,9 +151,9 @@
};
-ku.Engine.prototype.getRules = function() {
- var rules = new Array();
- var ruleProcessors = this._ruleProcessors
+this.getRules = function() {
+ var rules = [];
+ 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++) {
@@ -134,28 +161,13 @@
}
}
return rules;
-}
-
-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;
- }
- return false;
+this.getRuleProcessors = function() {
+ return this._ruleProcessors;
};
-ku.Engine.prototype.setupEvents = function(inNodes) {
+this.setupEvents = function(inNodes) {
if (this.setupEventsInProgress) {
// remember them
this.setupEventsQueue = this.setupEventsQueue.concat(inNodes);
@@ -165,18 +177,18 @@
}
};
-ku.Engine.prototype.beginSetupEventsCollection = function() {
+this.beginSetupEventsCollection = function() {
this.setupEventsInProgress = true;
};
-ku.Engine.prototype.finishSetupEventsCollection = function() {
+this.finishSetupEventsCollection = function() {
this.setupEventsInProgress = false;
var setupEventsQueue = this.setupEventsQueue;
this.setupEventsQueue = [];
this.doSetupEvents(setupEventsQueue);
};
-ku.Engine.prototype.doSetupEvents = function(inNodes) {
+this.doSetupEvents = function(inNodes) {
var self = this;
var deferredEventsSetup = function() {
self._setupEvents(inNodes);
@@ -207,7 +219,7 @@
}
};
-ku.Engine.prototype._setupEvents = function(inNodes) {
+this._setupEvents = function(inNodes) {
// Decide phase. 1=initial, 2=insertion.
var phase;
if (typeof(inNodes) == 'undefined') {
@@ -234,10 +246,8 @@
this.binderInfoRegistry.processBindingEvents();
};
-
-
-
-ku.Engine.prototype.initializeRules = function() {
+this.initializeRules = function() {
+;;; var msg = '';
if (window.kukitRulesInitializing || window.kukitRulesInitialized) {
// Refuse to initialize a second time.
;;; kukit.log('[initializeRules] is called twice.');
@@ -260,7 +270,7 @@
;;; var ts_loaded = (new Date()).valueOf();
ruleprocessor.parse();
;;; var ts_end = (new Date()).valueOf();
-;;; var msg = "Finished loading and processing " + rulelink.href;
+;;; 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.';
@@ -272,11 +282,11 @@
;;; } catch(e) {
;;; // Event setup errors are logged.
;;; if (e.name == 'RuleMergeError' || e.name == 'EventBindError') {
-;;; var msg = 'Events setup - ' + e.toString();
+;;; msg = 'Events setup - ' + e.toString();
;;; // Log the message
;;; kukit.logFatal(msg);
;;; // and throw it...
- ;;; throw new Error(msg);
+;;; throw new Error(msg);
;;; } else {
;;; throw e;
;;; }
@@ -284,6 +294,9 @@
window.kukitRulesInitializing = false;
window.kukitRulesInitialized = true;
};
+this.initialize.apply(this, arguments);
+};
+
/* XXX deprecated methods, to be removed asap
@@ -298,14 +311,6 @@
kukit.bootstrap();
};
-/*
-* class _RuleSheetLink
-*/
-var _RuleSheetLink = function(href, res_type) {
- this.href = href;
- this.res_type = res_type;
-};
-
ku.bootstrap = function() {
;;; kukit.log('Instantiate engine.');
var engine = new kukit.Engine();
Modified: kukit/kukit.js/trunk/kukit/oper.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/oper.js (original)
+++ kukit/kukit.js/trunk/kukit/oper.js Thu Jan 10 13:53:49 2008
@@ -17,9 +17,9 @@
* 02111-1307, USA.
*/
+kukit.op = new function() { /// MODULE START
-
-kukit.op = {};
+var op = this;
/*
* class Oper
@@ -49,7 +49,9 @@
*
* browserevent: the original browser event.
*/
-kukit.op.Oper = function (dict) {
+op.Oper = function() {
+
+this.initialize = function(dict) {
this.node = null;
this.parms = {};
this.eventRule = null;
@@ -61,18 +63,18 @@
this.unrestrictedUpdate(dict);
};
-kukit.op.Oper.prototype.clone = function(dict, restricted) {
+this.clone = function(dict, restricted) {
var newoper = new kukit.op.Oper(this);
newoper.unrestrictedUpdate(dict, restricted);
return newoper;
};
-kukit.op.Oper.prototype.update = function(dict) {
+this.update = function(dict) {
// restricted attrs must not be changed on existing oper.
this.unrestrictedUpdate(dict, true);
};
-kukit.op.Oper.prototype.unrestrictedUpdate = function(dict, restricted) {
+this.unrestrictedUpdate = function(dict, restricted) {
if (typeof(dict) == 'undefined') {
return;
}
@@ -84,7 +86,7 @@
;;; var isEventRule = key == 'eventRule';
;;; var isBinder = key == 'binder';
;;; var isOrig = key == 'orignode';
-;;; return isNode || isParameters || isEventRule || isBinder || isOrig;
+;;; return isNode || isParameters || isEventRule || isBinder || isOrig;
;;; };
;;; }
;;; if (restricted && checkKey(key)) {
@@ -99,23 +101,23 @@
}
};
-kukit.op.Oper.prototype.logDebug = function() {
-;;; var result = [];
-;;; for (var key in this){
-;;; if (key == 'parms') {
-;;; var res2 = [];
-;;; for (var k2 in this.parms){
-;;; res2.push(k2 + '="' + this.parms[k2] + '"');
-;;; }
-;;; result.push('parms={' + res2.join(',') + '}');
-;;; } else if (typeof(kukit.op.Oper.prototype[key]) == 'undefined') {
-;;; result.push(key + '=' + this[key]);
+this.logDebug = function() {
+;;; var result = [];
+;;; for (var key in this){
+;;; if (key == 'parms') {
+;;; var res2 = [];
+;;; for (var k2 in this.parms){
+;;; res2.push(k2 + '="' + this.parms[k2] + '"');
;;; }
+;;; result.push('parms={' + res2.join(',') + '}');
+;;; } else if (typeof(kukit.op.Oper.prototype[key]) == 'undefined') {
+;;; result.push(key + '=' + this[key]);
;;; }
-;;; kukit.logDebug('Oper values: ' + result.join(', '));
+;;; }
+;;; kukit.logDebug('Oper values: ' + result.join(', '));
};
-kukit.op.Oper.prototype.executeClientAction = function(name) {
+this.executeClientAction = function(name) {
// Check kss action parms
var nodes = null;
// XXX TODO this should be refactored with parms constraint checking
@@ -166,7 +168,7 @@
}
};
-kukit.op.Oper.prototype.executeDefaultAction = function(name, optional) {
+this.executeDefaultAction = function(name, optional) {
// Check kss action parms
;;; for (key in this.kssParms) {
;;; kukit.E = 'Wrong parameter : [' + key + '] starts with "kss";';
@@ -196,14 +198,14 @@
} else {
this.parms = {};
}
- this.binder._EventBinder_callMethod(
+ this.binder.callMethod(
namespace, name, this, methodName);
success = true;
}
return success;
};
-kukit.op.Oper.prototype.executeServerAction = function(name) {
+this.executeServerAction = function(name) {
;;; for (key in this.kssParms) {
;;; if (key == 'kssUrl') {
;;; // Value will be evaluated.
@@ -222,17 +224,17 @@
/* Helpers the serve binding */
-kukit.op.Oper.prototype.getEventName = function () {
+this.getEventName = function () {
// Gets event name
return this.eventRule.kssSelector.name;
};
-kukit.op.Oper.prototype.getEventNamespace = function () {
+this.getEventNamespace = function () {
// Gets event name
return this.eventRule.kssSelector.namespace;
};
-kukit.op.Oper.prototype.hasExecuteActions = function () {
+this.hasExecuteActions = function () {
// Decide if there are any actions (or a default action)
// to execute. This can speed up execution if in case
// we have nothing to do, there is no reason to bind
@@ -254,7 +256,7 @@
return false;
};
-kukit.op.Oper.prototype.makeExecuteActionsHook = function (filter) {
+this.makeExecuteActionsHook = function (filter) {
// Factory that creates the function that executes the actions.
// The function may take a dict that is updated on the oper
// If filter is specified, it will we called with a function and
@@ -277,7 +279,7 @@
// (Filter has a chance to set a defaultParameters on oper.
if (filter && ! filter(newoper)) return false;
// execute the event's actions
- newoper.binder._EventBinder_triggerEvent(eventName, newoper);
+ newoper.binder.triggerEvent(eventName, newoper);
// show that the event's actions have been executed
return true;
};
@@ -286,7 +288,7 @@
/* Utility for parameter checking */
-kukit.op.Oper.prototype.evaluateParameters =
+this.evaluateParameters =
function(mandatory, defaults, errname, allow_excess) {
// Checks if mandatory params are supplied and there are no excess params
// also fill up default values
@@ -296,7 +298,7 @@
// 'event X');
;;; if (typeof(allow_excess) == 'undefined') {
;;; allow_excess = false;
-;;;}
+;;; }
var newParameters = {};
for (var i=0; i<mandatory.length; i++) {
var next = mandatory[i];
@@ -327,7 +329,7 @@
this.parms = newParameters;
};
-kukit.op.Oper.prototype.completeParms =
+this.completeParms =
function(mandatory, defaults, errname, allow_excess) {
;;; var msg = 'Deprecated [Oper.completeParms],';
;;; msg += 'use [Oper.evaluateParameters] instead !';
@@ -335,38 +337,42 @@
this.evaluateParameters(mandatory, defaults, errname, allow_excess);
};
-kukit.op.Oper.prototype.evalBool = function(key, errname) {
+this.evalBool = function(key, errname) {
var value = this.parms[key];
;;; kukit.E = 'for key [' + key + '] in [' + errname + '].';
this.parms[key] = kukit.ut.evalBool(value, kukit.E);
};
-kukit.op.Oper.prototype.evalInt = function(key, errname) {
+this.evalInt = function(key, errname) {
var value = this.parms[key];
;;; kukit.E = 'for key [' + key + '] in [';
;;; kukit.E += errname || this.componentName + '].';
this.parms[key] = kukit.ut.evalInt(value, kukit.E);
};
-kukit.op.Oper.prototype.evalList = function(key, errname) {
+this.evalList = function(key, errname) {
var value = this.parms[key];
;;; kukit.E = 'for key [' + key + '] in [';
;;; kukit.E += errname || this.componentName + '].';
this.parms[key] = kukit.ut.evalList(value, kukit.E);
};
-;;; kukit.op.Oper.prototype.debugInformation = function() {
-;;; if (this.eventRule) {
-;;; var eventRule = this.eventRule;
-;;; var node = this.node;
-;;; var nodeName = '<DOCUMENT>';
-;;; if (node != null) {
-;;; nodeName = node.nodeName;
+;;; this.debugInformation = function() {
+;;; if (this.eventRule) {
+;;; var eventRule = this.eventRule;
+;;; var node = this.node;
+;;; var nodeName = '<DOCUMENT>';
+;;; if (node != null) {
+;;; nodeName = node.nodeName;
+;;; }
+;;; var message = ', event [' + eventRule.kssSelector.name;
+;;; message += '], rule #' + eventRule.getIndex() + ', node [';
+;;; message += nodeName + '].';
+;;; return message;
;;; }
-;;; var message = ', event [' + eventRule.kssSelector.name;
-;;; message += '], rule #' + eventRule.getIndex() + ', node [';
-;;; message += nodeName + '].';
-;;; return message;
-;;; }
-;;; return '';
+;;; return '';
;;; };
+this.initialize.apply(this, arguments);
+};
+
+}(); /// MODULE END
Modified: kukit/kukit.js/trunk/kukit/plugin.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/plugin.js (original)
+++ kukit/kukit.js/trunk/kukit/plugin.js Thu Jan 10 13:53:49 2008
@@ -19,7 +19,9 @@
/* Core plugins and utilities */
-kukit.pl = {};
+kukit.pl = new function() { /// MODULE START
+
+var pl = this;
/*
* Event plugins
@@ -37,7 +39,7 @@
* can be defined to specify a default event action.
*/
-kukit.pl.getTargetForBrowserEvent = function(e) {
+pl.getTargetForBrowserEvent = function(e) {
// this prevents the handler to be called on wrong elements, which
// can happen because of propagation or bubbling
// XXX this needs to be tested in all browsers
@@ -60,10 +62,10 @@
*
* This can be used to register native events in a way that
* they handle allowbubbling, preventdefault and preventbubbling as needed.
-* (THe handling of these parms are optional, it is allowed not to have them
+* (The handling of these parms are optional, it is allowed not to have them
* in the oper.parms.)
*
-* THe register function can also take a filter function as parameter.
+* The register function can also take a filter function as parameter.
* This function needs to receive oper as a parameter,
* where 'browserevent' will be set on oper too as the native browser event.
* The function must return true if it wants the event to execute,
@@ -78,12 +80,12 @@
* event from the desired one.
*/
-kukit.pl.registerBrowserEvent = function(oper, filter, eventName) {
+pl.registerBrowserEvent = function(oper, filter, eventName) {
var func_to_bind = oper.makeExecuteActionsHook(filter);
if (! eventName)
eventName = oper.getEventName();
var func = function(e) {
- var target = kukit.pl.getTargetForBrowserEvent(e);
+ var target = pl.getTargetForBrowserEvent(e);
if (oper.parms.allowbubbling || target == oper.node) {
// Execute the action, provide browserevent on oper
// ... however, do it protected. We want the preventdefault
@@ -129,33 +131,45 @@
;;; kukit.log(msg);
}
};
+
+ // register the event listener
kukit.ut.registerEventListener(oper.node, eventName, func);
+
+ //
+ // XXX Safari hack
+ // necessary since Safari does not prevent the <a href...> following
+ // (in case of allowbubbling we have to apply it to all clicks, as there
+ // might be a link inside that we cannot detect on the current node)
+ //
+ if (oper.parms.preventdefault && kukit.HAVE_SAFARI
+ && (oper.parms.allowbubbling || eventName == 'click'
+ && oper.node.tagName.toLowerCase() == 'a')) {
+ oper.node.onclick = function cancelClickSafari() {
+ return false;
+ };
+ }
};
/*
* class NativeEventBinder
*/
-kukit.pl.NativeEventBinder = function() {
-};
+pl.NativeEventBinder = function() {
-kukit.pl.NativeEventBinder.prototype.__bind__node =
- function(name, func_to_bind, oper) {
+this.__bind__node = function(name, func_to_bind, oper) {
;;; if (oper.node == null) {
;;; throw new Error('Native event [' + name + '] must be bound to a node.');
;;; }
this.__bind__(name, func_to_bind, oper);
};
-kukit.pl.NativeEventBinder.prototype.__bind__nodeorwindow =
- function(name, func_to_bind, oper) {
+this.__bind__nodeorwindow = function(name, func_to_bind, oper) {
if (oper.node == null) {
oper.node = window;
}
this.__bind__(name, func_to_bind, oper);
};
-kukit.pl.NativeEventBinder.prototype.__bind__window =
- function(name, func_to_bind, oper) {
+this.__bind__window = function(name, func_to_bind, oper) {
;;; if (oper.node != null) {
;;; throw new Error('Native event [' + name + '] must not be bound to a node.');
;;; }
@@ -163,16 +177,14 @@
this.__bind__(name, func_to_bind, oper);
};
-kukit.pl.NativeEventBinder.prototype.__bind__nodeordocument =
- function(name, func_to_bind, oper) {
+this.__bind__nodeordocument = function(name, func_to_bind, oper) {
if (oper.node == null) {
oper.node = document;
}
this.__bind__(name, func_to_bind, oper);
};
-kukit.pl.NativeEventBinder.prototype.__bind__ =
- function(name, func_to_bind, oper) {
+this.__bind__ = function(name, func_to_bind, oper) {
;;; oper.componentName = 'native event binding';
oper.evaluateParameters([],
{'preventdefault': '', 'allowbubbling': '', 'preventbubbling': ''});
@@ -186,25 +198,12 @@
throw new Error(kukit.E);
}
}
- kukit.pl.registerBrowserEvent(oper);
- //
- // XXX Safari hack
- // necessary since Safari does not prevent the <a href...> following
- // (in case of allowbubbling we have to apply it to all clicks, as there
- // might be a link inside that we cannot detect on the current node)
- //
- // XXX not needed since we have the legacy name parameter:
- // var name = oper.getEventName();
- if (oper.parms.preventdefault && kukit.HAVE_SAFARI
- && (oper.parms.allowbubbling || name == 'click'
- && oper.node.tagName.toLowerCase() == 'a')) {
- oper.node.onclick = function cancelClickSafari() {
- return false;
- };
- }
+ // we give the name parameter to the registration, so we
+ // really bind to the event name we want.
+ pl.registerBrowserEvent(oper, null, name);
};
-kukit.pl.NativeEventBinder.prototype.__bind_key__ =
+this.__bind_key__ =
function(name, func_to_bind, oper) {
;;; oper.componentName = 'native key event binding';
oper.evaluateParameters([],
@@ -275,52 +274,10 @@
return true;
}
};
- kukit.pl.registerBrowserEvent(oper, filter);
+ pl.registerBrowserEvent(oper, filter);
+};
};
-/*
-* Registration of all the native events that can bound
-* to a node or to document
-* (= document or window, depending on the event specs)
-* Unsupported are those with absolute no hope to work in a cross browser way
-* Preventdefault is only allowed for click and key events, currently
-*/
-kukit.eventsGlobalRegistry.register(null, 'blur', kukit.pl.NativeEventBinder,
- '__bind__nodeorwindow', null);
-kukit.eventsGlobalRegistry.register(null, 'focus', kukit.pl.NativeEventBinder,
- '__bind__nodeorwindow', null);
-kukit.eventsGlobalRegistry.register(null, 'resize', kukit.pl.NativeEventBinder,
- '__bind__nodeorwindow', null);
-kukit.eventsGlobalRegistry.register(null, 'click', kukit.pl.NativeEventBinder,
- '__bind__nodeordocument', null);
-kukit.eventsGlobalRegistry.register(null, 'dblclick',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'mousedown',
- kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
-kukit.eventsGlobalRegistry.register(null, 'mouseup',
- kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
-kukit.eventsGlobalRegistry.register(null, 'mousemove',
- kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
-kukit.eventsGlobalRegistry.register(null, 'mouseover',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'mouseout',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'change',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'reset',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'select',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'submit',
- kukit.pl.NativeEventBinder, '__bind__node', null);
-kukit.eventsGlobalRegistry.register(null, 'keydown',
- kukit.pl.NativeEventBinder, '__bind_key__', null);
-kukit.eventsGlobalRegistry.register(null, 'keypress',
- kukit.pl.NativeEventBinder, '__bind_key__', null);
-kukit.eventsGlobalRegistry.register(null, 'keyup',
- kukit.pl.NativeEventBinder, '__bind_key__', null);
-//kukit.eventsGlobalRegistry.register(null, 'unload',
-// kukit.pl.NativeEventBinder, '__bind__window', null);
/*
* class TimeoutEventBinder
@@ -331,12 +288,13 @@
* unless the binding node has been deleted, in which case it stops,
* or it runs only once if repeat=false is given.
*/
-kukit.pl.TimeoutEventBinder = function() {
+pl.TimeoutEventBinder = function() {
+
+this.initialize = function() {
this.counters = {};
};
-kukit.pl.TimeoutEventBinder.prototype.__bind__ =
- function(name, func_to_bind, oper) {
+this.__bind__ = function(name, func_to_bind, oper) {
;;; oper.componentName = 'timeout event binding';
oper.evaluateParameters(['delay'], {'repeat': 'true'});
oper.evalBool('repeat');
@@ -371,17 +329,15 @@
;;; kukit.logDebug(msg);
}
};
-
-kukit.eventsGlobalRegistry.register(null, 'timeout',
- kukit.pl.TimeoutEventBinder, '__bind__', null);
+this.initialize.apply(this, arguments);
+};
/*
* class LoadEventBinder
*/
-kukit.pl.LoadEventBinder = function() {
-};
+pl.LoadEventBinder = function() {
-kukit.pl.LoadEventBinder.prototype.processParameters =
+this.processParameters =
function(oper, iload) {
if (! oper) {
return;
@@ -428,7 +384,7 @@
return oper;
};
-kukit.pl.LoadEventBinder.prototype.__bind__ = function(opers_by_eventName) {
+this.__bind__ = function(opers_by_eventName) {
// This bind method handles load and iload events together, and
// opers_by_eventName is
// a dictionary of opers which can contain a load and an iload key,
@@ -541,11 +497,7 @@
}
};
-// Use the [node] iterator to provide expected invocation
-// and call signature of the bind method.
-kukit.eventsGlobalRegistry.registerForAllEvents(null, ['load', 'iload'],
- kukit.pl.LoadEventBinder, '__bind__', null, 'Node');
-
+};
/*
* class SpinnerEventBinder
@@ -553,17 +505,18 @@
* Spinner support. Besides the event itself we use some utility
* classes to introduce lazyness (delay) for the spinner.
*/
-kukit.pl.SpinnerEventBinder = function() {
+pl.SpinnerEventBinder = function() {
+
+this.initialize = function() {
this.state = false;
var self = this;
- var timeoutSetState = function(spinnerevent) {
+ var _timeoutSetState = function(spinnerevent) {
self.timeoutSetState(spinnerevent);
};
- this.scheduler = new kukit.ut.Scheduler(timeoutSetState);
+ this.scheduler = new kukit.ut.Scheduler(_timeoutSetState);
};
-kukit.pl.SpinnerEventBinder.prototype.__bind__ = function(name, func_to_bind,
- oper) {
+this.__bind__ = function(name, func_to_bind, oper) {
;;; oper.componentName = '[spinner] event binding';
oper.evaluateParameters([], {'laziness': 0});
oper.evalInt('laziness');
@@ -576,8 +529,7 @@
kukit.engine.requestManager.registerSpinnerEvent(func, state_to_bind);
};
-kukit.pl.SpinnerEventBinder.prototype.setState = function(func_to_bind, state,
- laziness) {
+this.setState = function(func_to_bind, state, laziness) {
// This is called when state changes. We introduce laziness
// before calling the func.
this.func_to_bind = func_to_bind;
@@ -587,17 +539,73 @@
this.scheduler.setNextWakeAtLeast(wakeUp);
};
-kukit.pl.SpinnerEventBinder.prototype.timeoutSetState = function() {
+this.timeoutSetState = function() {
// really call the bound actions which should set the spinner
this.func_to_bind();
};
+this.initialize.apply(this, arguments);
+};
+
+}(); /// MODULE END
+
+/*
+* Registration of all the native events that can bound
+* to a node or to document
+* (= document or window, depending on the event specs)
+* Unsupported are those with absolute no hope to work in a cross browser way
+* Preventdefault is only allowed for click and key events, currently
+*/
+kukit.eventsGlobalRegistry.register(null, 'blur', kukit.pl.NativeEventBinder,
+ '__bind__nodeorwindow', null);
+kukit.eventsGlobalRegistry.register(null, 'focus', kukit.pl.NativeEventBinder,
+ '__bind__nodeorwindow', null);
+kukit.eventsGlobalRegistry.register(null, 'resize', kukit.pl.NativeEventBinder,
+ '__bind__nodeorwindow', null);
+kukit.eventsGlobalRegistry.register(null, 'click', kukit.pl.NativeEventBinder,
+ '__bind__nodeordocument', null);
+kukit.eventsGlobalRegistry.register(null, 'dblclick',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'mousedown',
+ kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
+kukit.eventsGlobalRegistry.register(null, 'mouseup',
+ kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
+kukit.eventsGlobalRegistry.register(null, 'mousemove',
+ kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
+kukit.eventsGlobalRegistry.register(null, 'mouseover',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'mouseout',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'change',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'reset',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'select',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'submit',
+ kukit.pl.NativeEventBinder, '__bind__node', null);
+kukit.eventsGlobalRegistry.register(null, 'keydown',
+ kukit.pl.NativeEventBinder, '__bind_key__', null);
+kukit.eventsGlobalRegistry.register(null, 'keypress',
+ kukit.pl.NativeEventBinder, '__bind_key__', null);
+kukit.eventsGlobalRegistry.register(null, 'keyup',
+ kukit.pl.NativeEventBinder, '__bind_key__', null);
+//kukit.eventsGlobalRegistry.register(null, 'unload',
+// kukit.pl.NativeEventBinder, '__bind__window', null);
+
+kukit.eventsGlobalRegistry.register(null, 'timeout',
+ kukit.pl.TimeoutEventBinder, '__bind__', null);
+
+// Use the [node] iterator to provide expected invocation
+// and call signature of the bind method.
+kukit.eventsGlobalRegistry.registerForAllEvents(null, ['load', 'iload'],
+ kukit.pl.LoadEventBinder, '__bind__', null, 'Node');
+
kukit.eventsGlobalRegistry.register(null, 'spinneron',
kukit.pl.SpinnerEventBinder, '__bind__', null);
kukit.eventsGlobalRegistry.register(null, 'spinneroff',
kukit.pl.SpinnerEventBinder, '__bind__', null);
-
/* Core actions
*
* The core client actions that can be executed on the client
Modified: kukit/kukit.js/trunk/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/providerreg.js (original)
+++ kukit/kukit.js/trunk/kukit/providerreg.js Thu Jan 10 13:53:49 2008
@@ -17,19 +17,22 @@
* 02111-1307, USA.
*/
-kukit.pr = {};
+kukit.pr = new function() { /// MODULE START
+
+var pr = this;
/*
* class ValueProviderRegistry
*
* The parameter providers need to be registered here.
*/
+pr.ValueProviderRegistry = function () {
-kukit.pr.ValueProviderRegistry = function () {
+this.initialize = function() {
this.content = {};
};
-kukit.pr.ValueProviderRegistry.prototype.register = function(name, func) {
+this.register = function(name, func) {
if (typeof(func) == 'undefined') {
;;; kukit.E = 'func argument is mandatory when registering a parameter'
;;; kukit.E += ' provider [ValueProviderRegistry.register].';
@@ -45,27 +48,21 @@
this.content[name] = func;
};
-kukit.pr.ValueProviderRegistry.prototype.exists = function(name) {
+this.exists = function(name) {
var entry = this.content[name];
return (typeof(entry) != 'undefined');
};
-kukit.pr.ValueProviderRegistry.prototype.get = function(name) {
+this.get = function(name) {
var func = this.content[name];
if (! func) {
- // not found
- if (name == '') {
- // default provider for the strings
- return kukit.pr.IdentityPP;
- } else {
-;;; kukit.E = 'Error : undefined parameter provider [' + name + '].';
- throw new Error(kukit.E);
- }
+;;; kukit.E = 'Error : undefined parameter provider [' + name + '].';
+ throw new Error(kukit.E);
}
return func;
};
-
-kukit.pprovidersGlobalRegistry = new kukit.pr.ValueProviderRegistry();
+this.initialize.apply(this, arguments);
+};
/*
* Register the core parameter providers
@@ -90,229 +87,289 @@
* this provider expects a single parameter, the string.
*/
-kukit.pr.IdentityPP = function() {};
-kukit.pr.IdentityPP.prototype = {
- check: function(args) {
- // check does not need to be used here actually.
-;;; if (args.length != 1) {
-;;; throw new Error('internal error, IdentityPP needs 1 argument');
-;;; }
- },
- eval: function(args, node) {
- return args[0];
- }
+/*
+* class _IdentityPP
+*/
+var _IdentityPP = function() {
+
+this.check = function(args) {
+ // check does not need to be used here actually.
+;;; if (args.length != 1) {
+;;; throw new Error('internal error, _IdentityPP needs 1 argument');
+;;; }
};
-kukit.pprovidersGlobalRegistry.register('', kukit.pr.IdentityPP);
-kukit.pr.FormVarPP = function() {};
-kukit.pr.FormVarPP.prototype = {
- check: function(args) {
-;;; if (args.length != 2) {
-;;; throw new Error('formVar method needs 2 arguments [formname, varname]');
-;;; }
- },
- eval: function(args, node) {
- return kukit.fo.getFormVar(new kukit.fo.NamedFormLocator(args[0]),
- args[1]);
- }
+this.eval = function(args, node) {
+ return args[0];
};
-kukit.pprovidersGlobalRegistry.register('formVar', kukit.pr.FormVarPP);
-kukit.pr.CurrentFormVarPP = function() {};
-kukit.pr.CurrentFormVarPP.prototype = {
- check: function(args) {
-;;; if (args.length != 0 && args.length != 1) {
-;;; throw new Error('currentFormVar method needs 0 or 1 argument [varname]');
-;;; }
- },
- eval: function(args, node) {
- if (args.length == 1) {
- return kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(node),
- args[0]);
- } else {
- // no form var name, just get the value of the node.
- return kukit.fo.getValueOfFormElement(node);
- }
- }
};
-kukit.pprovidersGlobalRegistry.register('currentFormVar',
- kukit.pr.CurrentFormVarPP);
-kukit.pr.CurrentFormVarFromKssAttrPP = function() {};
-kukit.pr.CurrentFormVarFromKssAttrPP.prototype = {
- check: function(args) {
-;;; if (args.length != 1 && args.length != 2) {
-;;; kukit.E = 'currentFormVarFromKssAttr method needs 1 or 2 argument';
-;;; kukit.E += ' [attrname, [recurseParents]]';
-;;; throw new Error(kukit.E);
-;;; }
- },
- eval: function(args, node) {
- var argname = args[0];
- var recurseParents = false;
- if (args.length == 2) {
-;;; kukit.E = '2nd attribute of currentFormVarForKssAttr must be a';
-;;; kukit.E += ' boolean';
- kukit.ut.evalBool(args[1], kukit.E);
- recurseParents = args[1];
- }
- var formvarname = kukit.dom.getRecursiveAttribute(node, argname,
- recurseParents, kukit.dom.getKssAttribute);
+/*
+* class _FormVarPP
+*/
+var _FormVarPP = function() {
+
+this.check = function(args) {
+;;; if (args.length != 2) {
+;;; throw new Error('formVar method needs 2 arguments [formname, varname]');
+;;; }
+};
+
+this.eval = function(args, node) {
+ return kukit.fo.getFormVar(new kukit.fo.NamedFormLocator(args[0]), args[1]);
+};
+
+};
+
+/*
+* class _CurrentFormPP
+*/
+var _CurrentFormVarPP = function() {
+
+this.check = function(args) {
+;;; if (args.length != 0 && args.length != 1) {
+;;; throw new Error('currentFormVar method needs 0 or 1 argument [varname]');
+;;; }
+};
+
+this.eval = function(args, node) {
+ if (args.length == 1) {
return kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(node),
- formvarname);
+ args[0]);
+ } else {
+ // no form var name, just get the value of the node.
+ return kukit.fo.getValueOfFormElement(node);
}
};
-kukit.pprovidersGlobalRegistry.register('currentFormVarFromKssAttr',
- kukit.pr.CurrentFormVarFromKssAttrPP);
+
+};
+
+/*
+* class _CurrentFormVarFromKssAttrPP
+*/
+var _CurrentFormVarFromKssAttrPP = function() {
+
+this.check = function(args) {
+;;; if (args.length != 1 && args.length != 2) {
+;;; kukit.E = 'currentFormVarFromKssAttr method needs 1 or 2 argument';
+;;; kukit.E += ' [attrname, [recurseParents]]';
+;;; throw new Error(kukit.E);
+;;; }
+};
+
+this.eval = function(args, node) {
+ var argname = args[0];
+ var recurseParents = false;
+ if (args.length == 2) {
+;;; kukit.E = '2nd attribute of currentFormVarForKssAttr must be a';
+;;; kukit.E += ' boolean';
+ kukit.ut.evalBool(args[1], kukit.E);
+ recurseParents = args[1];
+ }
+ var formvarname = kukit.dom.getRecursiveAttribute(node, argname,
+ recurseParents, kukit.dom.getKssAttribute);
+ return kukit.fo.getFormVar(new kukit.fo.CurrentFormLocator(node),
+ formvarname);
+};
+
+};
/* BBB. To be deprecated at 2007-08-15 */
-kukit.pr.FormPP = function() {};
-kukit.pr.FormPP.prototype = {
- check: function(args) {
-;;; if (args.length != 1) {
-;;; throw new Error('form method needs 1 arguments [formname]');
-;;; }
-;;; var msg = 'Deprecated the [form(formname)] parameter provider,';
-;;; msg += ' use [xxx-kssSubmitForm: form(formname)] instead !';
-;;; kukit.logWarning(msg);
- },
- eval: function(args, node) {
- return kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator(args[0]),
- new kukit.ut.DictCollector());
- }
+/*
+* class _FormPP
+*/
+var _FormPP = function() {
+
+this.check = function(args) {
+;;; if (args.length != 1) {
+;;; throw new Error('form method needs 1 arguments [formname]');
+;;; }
+;;; var msg = 'Deprecated the [form(formname)] parameter provider,';
+;;; msg += ' use [xxx-kssSubmitForm: form(formname)] instead !';
+;;; kukit.logWarning(msg);
+};
+
+this.eval = function(args, node) {
+ return kukit.fo.getAllFormVars(new kukit.fo.NamedFormLocator(args[0]),
+ new kukit.ut.DictCollector());
+};
+
};
-kukit.pprovidersGlobalRegistry.register('form', kukit.pr.FormPP);
/* BBB. To be deprecated at 2007-08-15 */
-kukit.pr.CurrentFormPP = function() {};
-kukit.pr.CurrentFormPP.prototype = {
- check: function(args) {
-;;; if (args.length != 0) {
-;;; throw new Error('currentForm method needs no argument');
-;;; }
-;;; var msg = 'Deprecated the [currentForm()] parameter provider,';
-;;; msg += ' use [xxx-kssSubmitForm: currentForm()] instead !';
-;;; kukit.logWarning(msg);
- },
- eval: function(args, node) {
- return kukit.fo.getAllFormVars(new kukit.fo.CurrentFormLocator(node),
- new kukit.ut.DictCollector());
- }
+/*
+* class _CurrentFormPP
+*/
+var _CurrentFormPP = function() {
+
+this.check = function(args) {
+;;; if (args.length != 0) {
+;;; throw new Error('currentForm method needs no argument');
+;;; }
+;;; var msg = 'Deprecated the [currentForm()] parameter provider,';
+;;; msg += ' use [xxx-kssSubmitForm: currentForm()] instead !';
+;;; kukit.logWarning(msg);
};
-kukit.pprovidersGlobalRegistry.register('currentForm', kukit.pr.CurrentFormPP);
-kukit.pr.NodeAttrPP = function() {};
-kukit.pr.NodeAttrPP.prototype = {
- check: function(args) {
-;;; if (args.length != 1 && args.length != 2) {
-;;; kukit.E = 'nodeAttr method needs 1 or 2 argument (attrname,';
-;;; kukit.E += ' [recurseParents]).';
-;;; throw new Error(kukit.E);
-;;; }
-;;; if (args[0].toLowerCase() == 'style') {
-;;; throw new Error('nodeAttr method does not accept [style] as attrname.');
-;;; }
-;;; if (args[0].match(/[ ]/)) {
-;;; throw new Error('attrname parameter in nodeAttr method cannot contain space.');
-;;; }
- },
- ev