[KSS-checkins] r49935 - kukit/kukit.js/branch/finish-closures/kukit
gotcha at codespeak.net
gotcha at codespeak.net
Wed Dec 19 17:12:46 CET 2007
Author: gotcha
Date: Wed Dec 19 17:12:45 2007
New Revision: 49935
Modified:
kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
kukit/kukit.js/branch/finish-closures/kukit/selectorreg.js
Log:
module and class closures
Modified: kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/TODO.txt (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/TODO.txt Wed Dec 19 17:12:45 2007
@@ -3,5 +3,4 @@
plugin.js
requestmanager.js
resourcedata.js
-selectorreg.js
utils.js move to kukit the names that are defined in kukit namespaces.
Modified: kukit/kukit.js/branch/finish-closures/kukit/selectorreg.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/selectorreg.js (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/selectorreg.js Wed Dec 19 17:12:45 2007
@@ -17,51 +17,49 @@
* 02111-1307, USA.
*/
-kukit.sr = {};
+kukit.sr = new function() { /// MODULE START
-// Registry of the pprovider functions for selecting
+var sr = this;
-kukit.sr.pproviderSelRegistry = new kukit.pr.ValueProviderRegistry();
+// Registry of the pprovider functions for selecting
+sr.pproviderSelRegistry = new kukit.pr.ValueProviderRegistry();
// this will provide an arbitrary selector, and is designed to
// be used with the makeAnyPP factory function.
-kukit.sr.AnyPP = function() {};
-kukit.sr.AnyPP.prototype = {
- check: function(args) {
+var _AnyPP = function() {
+ this.check = function(args) {
// check does not need to be used here actually.
;;; if (args.length != 1) {
;;; throw new Error('internal error, xxxselector() needs 1 argument');
;;; }
- },
- eval: function(args, node, defaultParameters) {
+ };
+ this.eval = function(args, node, defaultParameters) {
var f = kukit.selectorTypesGlobalRegistry.get(this.selector_type);
// We don't have orignode if we evaluate from here, consequently
// the orignode parameter cannot be used from selectors. We pass
// node just to be sure...
return f(args[0], node, defaultParameters, node);
- }
+ };
};
-kukit.sr.pproviderSelRegistry.register('', kukit.sr.AnyPP);
+sr.pproviderSelRegistry.register('', _AnyPP);
-kukit.sr.makeAnyPP = function(selector_type) {
+sr.makeAnyPP = function(selector_type) {
var pp = function () {};
- pp.prototype.eval = kukit.sr.AnyPP.prototype.eval;
-;;; pp.prototype.check = kukit.sr.AnyPP.prototype.check;
+ pp.prototype = new _AnyPP();
pp.prototype.selector_type = selector_type;
return pp;
};
// this can be used to pass a node programmatically
-kukit.sr.PassnodePP = function() {};
-kukit.sr.PassnodePP.prototype = {
- check: function(args) {
+var _PassnodePP = function() {
+ this.check = function(args) {
;;; if (args.length != 1) {
;;; throw new Error('passnode selector method needs 1 argument');
;;; }
- },
- eval: function(args, node, defaultParameters) {
+ };
+ this.eval = function(args, node, defaultParameters) {
var value = defaultParameters[args[0]];
if (typeof(value) == 'undefined') {
// notfound arguments will get null
@@ -70,9 +68,9 @@
}
nodes = [value];
return nodes;
- }
+ };
};
-kukit.sr.pproviderSelRegistry.register('passnode', kukit.sr.PassnodePP);
+sr.pproviderSelRegistry.register('passnode', _PassnodePP);
/*
@@ -85,41 +83,41 @@
* kukit.selectorTypesGlobalRegistry.register(name, func);
*
*/
-kukit.sr.SelectorTypeRegistry = function () {
+var _SelectorTypeRegistry = function () {
this.mapping = {};
+ this.register = function(name, func) {
+ if (typeof(func) == 'undefined') {
+ throw new Error('Func is mandatory.');
+ }
+;;; if (this.mapping[name]) {
+;;; // Do not allow redefinition
+;;; kukit.logError('Error : redefinition attempt of selector ' + name);
+;;; return;
+;;; }
+ this.mapping[name] = func;
+ // Also register the selector param provider
+ var pp = sr.makeAnyPP(name);
+ sr.pproviderSelRegistry.register(name, pp);
+ };
+
+ this.get = function(name) {
+ if (! name) {
+ // if name is null or undefined or '',
+ // we use the default type.
+ name = this.defaultSelectorType;
+ }
+ var result = this.mapping[name];
+;;; if (typeof(result) == 'undefined') {
+;;; throw new Error('Unknown selector type "' + name + '"');
+;;; }
+ return result;
+ };
};
-kukit.sr.SelectorTypeRegistry.prototype.defaultSelectorType = 'css';
+_SelectorTypeRegistry.prototype.defaultSelectorType = 'css';
-kukit.sr.SelectorTypeRegistry.prototype.register = function(name, func) {
- if (typeof(func) == 'undefined') {
- throw new Error('Func is mandatory.');
- }
-;;; if (this.mapping[name]) {
-;;; // Do not allow redefinition
-;;; kukit.logError('Error : redefinition attempt of selector ' + name);
-;;; return;
-;;; }
- this.mapping[name] = func;
- // Also register the selector param provider
- var pp = kukit.sr.makeAnyPP(name);
- kukit.sr.pproviderSelRegistry.register(name, pp);
-};
-kukit.sr.SelectorTypeRegistry.prototype.get = function(name) {
- if (! name) {
- // if name is null or undefined or '',
- // we use the default type.
- name = this.defaultSelectorType;
- }
- var result = this.mapping[name];
-;;; if (typeof(result) == 'undefined') {
-;;; throw new Error('Unknown selector type "' + name + '"');
-;;; }
- return result;
-};
-
-kukit.selectorTypesGlobalRegistry = new kukit.sr.SelectorTypeRegistry();
+kukit.selectorTypesGlobalRegistry = new _SelectorTypeRegistry();
kukit.selectorTypesGlobalRegistry.register('htmlid', function(expr, node) {
var nodes = [];
@@ -166,3 +164,5 @@
}
return results;
});
+
+}(); /// MODULE END
More information about the Kukit-checkins
mailing list