From 41ba3a424c376918695028eca60fb31f04a7a7c9 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Mon, 8 Mar 2010 02:10:24 +0100 Subject: [PATCH] * The low level APIs of MooTools Core 1.3 are now CommonJS compatible * Hash moved outside of compatibility block * Fixing Hash provides/require --- Source/Class/Class.Extras.js | 13 +++++-- Source/Class/Class.js | 7 +++- Source/Core/Core.js | 89 ++++++++++++++++++++++---------------------- Source/Types/Array.js | 6 +++ Source/Types/Hash.js | 10 ++++- 5 files changed, 76 insertions(+), 49 deletions(-) diff --git a/Source/Class/Class.Extras.js b/Source/Class/Class.Extras.js index 424188e6..0a7ee19b 100644 --- a/Source/Class/Class.Extras.js +++ b/Source/Class/Class.Extras.js @@ -14,7 +14,12 @@ provides: [Class.Extras, Chain, Events, Options] ... */ -var Chain = new Class({ +(function(){ + +var typeOf = (/**/(typeof require != 'undefined') ? require('../Core/Core') : /**/this).typeOf, + Class = (/**/(typeof require != 'undefined') ? require('./Class') : /**/this).Class; + +this.Chain = new Class({ $chain: [], @@ -34,7 +39,7 @@ var Chain = new Class({ }); -var Events = new Class({ +var Events = this.Events = new Class({ $events: {}, @@ -92,7 +97,7 @@ Events.removeOn = function(string){ }); }; -var Options = new Class({ +this.Options = new Class({ setOptions: function(){ this.options = Object.merge.run([{}, this.options].extend(arguments)); @@ -106,3 +111,5 @@ var Options = new Class({ } }); + +}).call(typeof exports != 'undefined' ? exports : this); \ No newline at end of file diff --git a/Source/Class/Class.js b/Source/Class/Class.js index 089bc340..f66a944a 100644 --- a/Source/Class/Class.js +++ b/Source/Class/Class.js @@ -16,6 +16,11 @@ provides: Class (function(){ +var Core = /**/(typeof require != 'undefined') ? require('../Core/Core') : /**/this, + Type = Core.Type, + typeOf = Core.typeOf, + instanceOf = Core.instanceOf; + var Class = this.Class = new Type('Class', function(params){ if (instanceOf(params, Function)) params = {'initialize': params}; @@ -123,4 +128,4 @@ Class.Mutators = { } }; -})(); +}).call(typeof exports != 'undefined' ? exports : this); diff --git a/Source/Core/Core.js b/Source/Core/Core.js index 1a838ec5..15d8fc51 100644 --- a/Source/Core/Core.js +++ b/Source/Core/Core.js @@ -7,7 +7,7 @@ description: The heart of MooTools. license: MIT-style license. -copyright: Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/). +copyright: Copyright (c) 2006-2010 [Valerio Proietti](http://mad4milk.net/). authors: The MooTools production team (http://mootools.net/developers/) @@ -15,13 +15,20 @@ inspiration: - Class implementation inspired by [Base.js](http://dean.edwards.name/weblog/2006/03/base/) Copyright (c) 2006 Dean Edwards, [GNU Lesser General Public License](http://opensource.org/licenses/lgpl-license.php) - Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php) -provides: [Core, MooTools, Type, typeOf, instanceOf] +provides: [Core, MooTools, Type, typeOf, instanceOf, Hash.Base] ... */ (function(){ +/**/ +if (typeof require == 'undefined') + this.require = function(){ + return this; + }; +/**/ + this.MooTools = { version: '1.3dev', build: '%build%' @@ -29,12 +36,10 @@ this.MooTools = { // nil -this.nil = function(item){ +var nil = this.nil = function(item){ return (item != null && item != nil) ? item : null; }; -var Function = this.Function; - Function.prototype.extend = function(object){ for (var key in object) this[key] = object[key]; return this; @@ -47,7 +52,7 @@ Function.prototype.implement = function(object){ // typeOf, instanceOf -this.typeOf = function(item){ +var typeOf = this.typeOf = function(item){ if (item == null) return 'null'; if (item.$family) return item.$family(); @@ -64,7 +69,7 @@ this.typeOf = function(item){ return typeof item; }; -this.instanceOf = function(item, object){ +var instanceOf = this.instanceOf = function(item, object){ if (item == null) return false; var constructor = item.$constructor || item.constructor; while (constructor){ @@ -348,22 +353,7 @@ Object.extend({ Type(name); }); -})(); - -/**/ - -Object.type = Type.isObject; - -var Native = function(properties){ - return new Type(properties.name, properties.initialize); -}; - -Native.implement = function(objects, methods){ - for (var i = 0; i < objects.length; i++) objects[i].implement(methods); - return Native; -}; - -var Hash = new Type('Hash', function(object){ +var Hash = this.Hash = new Type('Hash', function(object){ if (typeOf(object) == 'hash') object = $unlink(object.getClean()); for (var key in object) this[key] = object[key]; return this; @@ -397,69 +387,78 @@ Hash.implement({ Hash.alias({each: 'forEach'}); -var $A = function(item){ +/**/ + +Object.type = Type.isObject; + +var Native = function(properties){ + return new Type(properties.name, properties.initialize); +}; + +Native.implement = function(objects, methods){ + for (var i = 0; i < objects.length; i++) objects[i].implement(methods); + return Native; +}; + +this.$A = function(item){ return Array.from(item).slice(); }; -var $arguments = function(i){ +this.$arguments = function(i){ return function(){ return arguments[i]; }; }; -var $chk = function(obj){ +this.$chk = function(obj){ return !!(obj || obj === 0); }; -var $clear = function(timer){ +this.$clear = function(timer){ clearTimeout(timer); clearInterval(timer); return null; }; -var $defined = function(obj){ +this.$defined = function(obj){ return (obj != null); }; -var $each = function(iterable, fn, bind){ +this.$each = function(iterable, fn, bind){ var type = typeOf(iterable); ((type == 'arguments' || type == 'collection' || type == 'array') ? Array : Hash).each(iterable, fn, bind); }; -var $empty = function(){}; +this.$empty = function(){}; -var $extend = function(original, extended){ +this.$extend = function(original, extended){ for (var key in (extended || {})) original[key] = extended[key]; return original; }; -var $H = function(object){ +this.$H = function(object){ return new Hash(object); }; -var $lambda = Function.from; - -var $merge = function(){ +this.$merge = function(){ var args = Array.slice(arguments); args.unshift({}); return Object.merge.apply(null, args); }; -var $mixin = Object.merge; +this.$lambda = Function.from; +this.$mixin = Object.merge; +this.$random = Number.random; +this.$splat = Array.from; +this.$time = Date.now; -var $random = Number.random; - -var $splat = Array.from; - -var $time = Date.now; - -var $type = function(object){ +this.$type = function(object){ var type = typeOf(object); if (type == 'elements') return 'array'; return (type == 'null') ? false : type; }; -var $unlink = function(object){ +this.$unlink = function(object){ switch (typeOf(object)){ case 'object': return Object.clone(object); case 'array': return Array.clone(object); @@ -469,3 +468,5 @@ var $unlink = function(object){ }; /**/ + +}).call(typeof exports != 'undefined' ? exports : this); diff --git a/Source/Types/Array.js b/Source/Types/Array.js index 05e1f231..e1b88b8a 100644 --- a/Source/Types/Array.js +++ b/Source/Types/Array.js @@ -14,6 +14,10 @@ provides: Array ... */ +(function(){ + +var typeOf = (/**/(typeof require != 'undefined') ? require('../Core/Core') : /**/this).typeOf; + Array.implement({ call: function(name){ @@ -165,6 +169,8 @@ Array.implement({ }); +}).call(typeof exports != 'undefined' ? exports : this); + /**/ Array.alias({extend: 'append'}); diff --git a/Source/Types/Hash.js b/Source/Types/Hash.js index 3cae95bd..9aa9bb56 100644 --- a/Source/Types/Hash.js +++ b/Source/Types/Hash.js @@ -7,13 +7,19 @@ description: Contains Hash Prototypes. Provides a means for overcoming the JavaS license: MIT-style license. -requires: Hash.base +requires: Hash.Base provides: Hash ... */ +(function(){ + +var Core = (/**/(typeof require != 'undefined') ? require('../Core/Core') : /**/this), + Hash = Core.Hash, + typeOf = Core.typeOf; + Hash.implement({ has: Object.prototype.hasOwnProperty, @@ -140,3 +146,5 @@ Hash.implement({ }); Hash.alias({indexOf: 'keyOf', contains: 'hasValue'}); + +}).call(typeof exports != 'undefined' ? exports : this); \ No newline at end of file -- 2.11.4.GIT