diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo-1.7.2/dojox/lang/oo | |
Diffstat (limited to 'js/dojo-1.7.2/dojox/lang/oo')
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/oo/Decorator.js | 41 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/oo/Filter.js | 49 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/oo/aop.js | 79 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/oo/general.js | 65 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/oo/mixin.js | 139 | ||||
| -rw-r--r-- | js/dojo-1.7.2/dojox/lang/oo/rearrange.js | 69 |
6 files changed, 442 insertions, 0 deletions
diff --git a/js/dojo-1.7.2/dojox/lang/oo/Decorator.js b/js/dojo-1.7.2/dojox/lang/oo/Decorator.js new file mode 100644 index 0000000..42f18c7 --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/oo/Decorator.js @@ -0,0 +1,41 @@ +//>>built +// wrapped by build app +define("dojox/lang/oo/Decorator", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.oo.Decorator"); + +(function(){ + var oo = dojox.lang.oo, + + D = oo.Decorator = function(value, decorator){ + // summary: + // The base class for all decorators. + // description: + // This object holds an original function or another decorator + // object, and implements a special mixin algorithm to be used + // by dojox.lang.oo.mixin. + // value: Object: + // a payload to be processed by the decorator. + // decorator: Function|Object: + // a function to handle the custom assignment, or an object with exec() + // method. The signature is: + // decorator(/*String*/ name, /*Function*/ newValue, /*Function*/ oldValue). + this.value = value; + this.decorator = typeof decorator == "object" ? + function(){ return decorator.exec.apply(decorator, arguments); } : decorator; + }; + + oo.makeDecorator = function(decorator){ + // summary: + // creates new custom decorator creator + // decorator: Function|Object: + // a function to handle the custom assignment, + // or an object with exec() method + // returns: Function: + // new decorator constructor + return function(value){ + return new D(value, decorator); + }; + }; +})(); + +}); diff --git a/js/dojo-1.7.2/dojox/lang/oo/Filter.js b/js/dojo-1.7.2/dojox/lang/oo/Filter.js new file mode 100644 index 0000000..f85eb10 --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/oo/Filter.js @@ -0,0 +1,49 @@ +//>>built +// wrapped by build app +define("dojox/lang/oo/Filter", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.oo.Filter"); + +(function(){ + var oo = dojox.lang.oo, + + F = oo.Filter = function(bag, filter){ + // summary: + // Filter to control mixing in objects by skipping + // properties and renaming them. + // description: + // This object is used as a holder of an original object + // (whose properites are to be copied), and a filter + // function used while copying by dojox.lang.oo.mixin. + // bag: Object: + // object to be filtered + // filter: Function|Object: + // a function to handle the name filtering, + // or an object with exec() method + this.bag = bag; + this.filter = typeof filter == "object" ? + function(){ return filter.exec.apply(filter, arguments); } : filter; + }, + + // the default map-based filter object + MapFilter = function(map){ + this.map = map; + }; + + MapFilter.prototype.exec = function(name){ + return this.map.hasOwnProperty(name) ? this.map[name] : name; + }; + + oo.filter = function(bag, map){ + // summary: + // creates a simple filter object + // bag: Object: + // object to be filtered + // map: Object: + // the dictionary for renaming/removing while copying + // returns: + // new dojox.lang.oo.Filter object + return new F(bag, new MapFilter(map)); + }; +})(); + +}); diff --git a/js/dojo-1.7.2/dojox/lang/oo/aop.js b/js/dojo-1.7.2/dojox/lang/oo/aop.js new file mode 100644 index 0000000..df2f03b --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/oo/aop.js @@ -0,0 +1,79 @@ +//>>built +// wrapped by build app +define("dojox/lang/oo/aop", ["dijit","dojo","dojox","dojo/require!dojox/lang/oo/Decorator,dojox/lang/oo/general"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.oo.aop"); + +dojo.require("dojox.lang.oo.Decorator"); +dojo.require("dojox.lang.oo.general"); + +(function(){ + var oo = dojox.lang.oo, md = oo.makeDecorator, oog = oo.general, ooa = oo.aop, + isF = dojo.isFunction; + + // five decorators implementing light-weight AOP weaving + + /*===== + ooa.before = md(function(name, newValue, oldValue){ + // summary: creates a "before" advise, by calling new function + // before the old one + + // dummy body + }); + + ooa.around = md(function(name, newValue, oldValue){ + // summary: creates an "around" advise, + // the previous value is passed as a first argument and can be null, + // arguments are passed as a second argument + + // dummy body + }); + =====*/ + + // reuse existing decorators + ooa.before = oog.before; + ooa.around = oog.wrap; + + ooa.afterReturning = md(function(name, newValue, oldValue){ + // summary: creates an "afterReturning" advise, + // the returned value is passed as the only argument + return isF(oldValue) ? + function(){ + var ret = oldValue.apply(this, arguments); + newValue.call(this, ret); + return ret; + } : function(){ newValue.call(this); }; + }); + + ooa.afterThrowing = md(function(name, newValue, oldValue){ + // summary: creates an "afterThrowing" advise, + // the exception is passed as the only argument + return isF(oldValue) ? + function(){ + var ret; + try{ + ret = oldValue.apply(this, arguments); + }catch(e){ + newValue.call(this, e); + throw e; + } + return ret; + } : oldValue; + }); + + ooa.after = md(function(name, newValue, oldValue){ + // summary: creates an "after" advise, + // it takes no arguments + return isF(oldValue) ? + function(){ + var ret; + try{ + ret = oldValue.apply(this, arguments); + }finally{ + newValue.call(this); + } + return ret; + } : function(){ newValue.call(this); } + }); +})(); + +}); diff --git a/js/dojo-1.7.2/dojox/lang/oo/general.js b/js/dojo-1.7.2/dojox/lang/oo/general.js new file mode 100644 index 0000000..874b857 --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/oo/general.js @@ -0,0 +1,65 @@ +//>>built +// wrapped by build app +define("dojox/lang/oo/general", ["dijit","dojo","dojox","dojo/require!dojox/lang/oo/Decorator"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.oo.general"); + +dojo.require("dojox.lang.oo.Decorator"); + +(function(){ + var oo = dojox.lang.oo, md = oo.makeDecorator, oog = oo.general, + isF = dojo.isFunction; + + // generally useful decorators + + oog.augment = md(function(name, newValue, oldValue){ + // summary: add property, if it was not defined before + return typeof oldValue == "undefined" ? newValue : oldValue; + }); + + oog.override = md(function(name, newValue, oldValue){ + // summary: override property only if it was already present + return typeof oldValue != "undefined" ? newValue : oldValue; + }); + + oog.shuffle = md(function(name, newValue, oldValue){ + // summary: replaces arguments for an old method + return isF(oldValue) ? + function(){ + return oldValue.apply(this, newValue.apply(this, arguments)); + } : oldValue; + }); + + oog.wrap = md(function(name, newValue, oldValue){ + // summary: wraps the old values with a supplied function + return function(){ return newValue.call(this, oldValue, arguments); }; + }); + + oog.tap = md(function(name, newValue, oldValue){ + // summary: always returns "this" ignoring the actual return + return function(){ newValue.apply(this, arguments); return this; }; + }); + + oog.before = md(function(name, newValue, oldValue){ + // summary: + // creates a chain of calls where the new method is called + // before the old method + return isF(oldValue) ? + function(){ + newValue.apply(this, arguments); + return oldValue.apply(this, arguments); + } : newValue; + }); + + oog.after = md(function(name, newValue, oldValue){ + // summary: + // creates a chain of calls where the new method is called + // after the old method + return isF(oldValue) ? + function(){ + oldValue.apply(this, arguments); + return newValue.apply(this, arguments); + } : newValue; + }); +})(); + +}); diff --git a/js/dojo-1.7.2/dojox/lang/oo/mixin.js b/js/dojo-1.7.2/dojox/lang/oo/mixin.js new file mode 100644 index 0000000..ec2c060 --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/oo/mixin.js @@ -0,0 +1,139 @@ +//>>built +// wrapped by build app +define("dojox/lang/oo/mixin", ["dijit","dojo","dojox","dojo/require!dojox/lang/oo/Filter,dojox/lang/oo/Decorator"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.oo.mixin"); + +dojo.experimental("dojox.lang.oo.mixin"); + +dojo.require("dojox.lang.oo.Filter"); +dojo.require("dojox.lang.oo.Decorator"); + +(function(){ + var oo = dojox.lang.oo, Filter = oo.Filter, Decorator = oo.Decorator, empty = {}, + defaultFilter = function(name){ return name; }, + defaultDecorator = function(name, newValue, oldValue){ return newValue; }, + defaultMixer = function(target, name, newValue, oldValue){ target[name] = newValue; }, + defaults = {}, // for the internal use in the mixin() + extraNames = dojo._extraNames, extraLen = extraNames.length, + + applyDecorator = oo.applyDecorator = function(decorator, name, newValue, oldValue){ + // summary: + // applies a decorator unraveling all embedded decorators + // decorator: Function: + // top-level decorator to apply + // name: String: + // name of the property + // newValue: Object: + // new value of the property + // oldValue: Object: + // old value of the property + // returns: Object: + // returns the final value of the property + if(newValue instanceof Decorator){ + var d = newValue.decorator; + newValue = applyDecorator(decorator, name, newValue.value, oldValue); + return d(name, newValue, oldValue); + } + return decorator(name, newValue, oldValue); + }; + + /*===== + dojox.lang.oo.__MixinDefaults = function(){ + // summary: + // a dict of default parameters for dojox.lang.oo._mixin + // decorator: Function: + // a decorator function to be used in absence of other decorators + // filter: Function: + // a filter function to be used in absence of other filters + // mixer: Function: + // a mixer function to be used to mix in new properties + this.decorator = decorator; + this.filter = filter; + this.mixer = mixer; + }; + =====*/ + + oo.__mixin = function(target, source, decorator, filter, mixer){ + // summary: + // mixes in two objects processing decorators and filters + // target: Object: + // target to receive new/updated properties + // source: Object: + // source of properties + // defaults: dojox.lang.oo.__MixinDefaults?: + // default functions for various aspects of mixing + // returns: Object: + // target + + var name, targetName, prop, newValue, oldValue, i; + + // start mixing in properties + for(name in source){ + prop = source[name]; + if(!(name in empty) || empty[name] !== prop){ + targetName = filter(name, target, source, prop); + if(targetName && (!(targetName in target) || !(targetName in empty) || empty[targetName] !== prop)){ + // name is accepted + oldValue = target[targetName]; + newValue = applyDecorator(decorator, targetName, prop, oldValue); + if(oldValue !== newValue){ + mixer(target, targetName, newValue, oldValue); + } + } + } + } + if(extraLen){ + for(i = 0; i < extraLen; ++i){ + name = extraNames[i]; + // repeating the body above + prop = source[name]; + if(!(name in empty) || empty[name] !== prop){ + targetName = filter(name, target, source, prop); + if(targetName && (!(targetName in target) || !(targetName in empty) || empty[targetName] !== prop)){ + // name is accepted + oldValue = target[targetName]; + newValue = applyDecorator(decorator, targetName, prop, oldValue); + if(oldValue !== newValue){ + mixer(target, targetName, newValue, oldValue); + } + } + } + } + } + + return target; // Object + }; + + oo.mixin = function(target, source){ + // summary: + // mixes in two or more objects processing decorators and filters + // using defaults as a fallback + // target: Object: + // target to receive new/updated properties + // source: Object...: + // source of properties, more than one source is allowed + // returns: Object: + // target + + var decorator, filter, i = 1, l = arguments.length; + for(; i < l; ++i){ + source = arguments[i]; + if(source instanceof Filter){ + filter = source.filter; + source = source.bag; + }else{ + filter = defaultFilter; + } + if(source instanceof Decorator){ + decorator = source.decorator; + source = source.value; + }else{ + decorator = defaultDecorator; + } + oo.__mixin(target, source, decorator, filter, defaultMixer); + } + return target; // Object + }; +})(); + +}); diff --git a/js/dojo-1.7.2/dojox/lang/oo/rearrange.js b/js/dojo-1.7.2/dojox/lang/oo/rearrange.js new file mode 100644 index 0000000..5fbd78e --- /dev/null +++ b/js/dojo-1.7.2/dojox/lang/oo/rearrange.js @@ -0,0 +1,69 @@ +//>>built +// wrapped by build app +define("dojox/lang/oo/rearrange", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.lang.oo.rearrange"); + +(function(){ + var extraNames = dojo._extraNames, extraLen = extraNames.length, + opts = Object.prototype.toString, empty = {}; + + dojox.lang.oo.rearrange = function(bag, map){ + // summary: + // Process properties in place by removing and renaming them. + // description: + // Properties of an object are to be renamed or removed specified + // by "map" argument. Only own properties of "map" are processed. + // example: + // | oo.rearrange(bag, { + // | abc: "def", // rename "abc" attribute to "def" + // | ghi: null // remove/hide "ghi" attribute + // | }); + // bag: Object: + // the object to be processed + // map: Object: + // the dictionary for renaming (false value indicates removal of the named property) + // returns: Object: + // the original object + + var name, newName, prop, i, t; + + for(name in map){ + newName = map[name]; + if(!newName || opts.call(newName) == "[object String]"){ + prop = bag[name]; + if(!(name in empty) || empty[name] !== prop){ + if(!(delete bag[name])){ + // can't delete => hide it + bag[name] = undefined; + } + if(newName){ + bag[newName] = prop; + } + } + } + } + if(extraLen){ + for(i = 0; i < extraLen; ++i){ + name = extraNames[i]; + // repeating the body above + newName = map[name]; + if(!newName || opts.call(newName) == "[object String]"){ + prop = bag[name]; + if(!(name in empty) || empty[name] !== prop){ + if(!(delete bag[name])){ + // can't delete => hide it + bag[name] = undefined; + } + if(newName){ + bag[newName] = prop; + } + } + } + } + } + + return bag; // Object + }; +})(); + +}); |
