Permalink
Browse files

use window inside closures to improve minification

  • Loading branch information...
1 parent 095a5a5 commit d3962bf02ab96affbd3152f05ab35f9da743852c @SergioCrisostomo committed Jul 6, 2014
View
50 Source/Core/Core.js
@@ -20,16 +20,16 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
...
*/
-(function(){
+(function(window){
-this.MooTools = {
+window.MooTools = {
version: '1.5.1-dev',
build: '%build%'
};
// typeOf, instanceOf
-var typeOf = this.typeOf = function(item){
+var typeOf = window.typeOf = function(item){
if (item == null) return 'null';
if (item.$family != null) return item.$family();
@@ -44,7 +44,7 @@ var typeOf = this.typeOf = function(item){
return typeof item;
};
-var instanceOf = this.instanceOf = function(item, object){
+var instanceOf = window.instanceOf = function(item, object){
if (item == null) return false;
var constructor = item.$constructor || item.constructor;
while (constructor){
@@ -59,7 +59,7 @@ var instanceOf = this.instanceOf = function(item, object){
// Function overloading
-var Function = this.Function;
+var Function = window.Function;
var enumerables = true;
for (var i in {toString: 1}) enumerables = null;
@@ -149,7 +149,7 @@ Function.implement({
// Type
-var Type = this.Type = function(name, object){
+var Type = window.Type = function(name, object){
if (name){
var lower = name.toLowerCase();
var typeCheck = function(item){
@@ -400,7 +400,7 @@ String.extend('uniqueID', function(){
//<1.2compat>
-var Hash = this.Hash = new Type('Hash', function(object){
+var Hash = window.Hash = new Type('Hash', function(object){
if (typeOf(object) == 'hash') object = Object.clone(object.getClean());
for (var key in object) this[key] = object[key];
return this;
@@ -434,7 +434,7 @@ Hash.alias('each', 'forEach');
Object.type = Type.isObject;
-var Native = this.Native = function(properties){
+var Native = window.Native = function(properties){
return new Type(properties.name, properties.initialize);
};
@@ -450,58 +450,58 @@ Array.type = function(item){
return instanceOf(item, Array) || arrayType(item);
};
-this.$A = function(item){
+window.$A = function(item){
return Array.from(item).slice();
};
-this.$arguments = function(i){
+window.$arguments = function(i){
return function(){
return arguments[i];
};
};
-this.$chk = function(obj){
+window.$chk = function(obj){
return !!(obj || obj === 0);
};
-this.$clear = function(timer){
+window.$clear = function(timer){
clearTimeout(timer);
clearInterval(timer);
return null;
};
-this.$defined = function(obj){
+window.$defined = function(obj){
return (obj != null);
};
-this.$each = function(iterable, fn, bind){
+window.$each = function(iterable, fn, bind){
var type = typeOf(iterable);
((type == 'arguments' || type == 'collection' || type == 'array' || type == 'elements') ? Array : Object).each(iterable, fn, bind);
};
-this.$empty = function(){};
+window.$empty = function(){};
-this.$extend = function(original, extended){
+window.$extend = function(original, extended){
return Object.append(original, extended);
};
-this.$H = function(object){
+window.$H = function(object){
return new Hash(object);
};
-this.$merge = function(){
+window.$merge = function(){
var args = Array.slice(arguments);
args.unshift({});
return Object.merge.apply(null, args);
};
-this.$lambda = Function.from;
-this.$mixin = Object.merge;
-this.$random = Number.random;
-this.$splat = Array.from;
-this.$time = Date.now;
+window.$lambda = Function.from;
+window.$mixin = Object.merge;
+window.$random = Number.random;
+window.$splat = Array.from;
+window.$time = Date.now;
-this.$type = function(object){
+window.$type = function(object){
var type = typeOf(object);
if (type == 'elements') return 'array';
return (type == 'null') ? false : type;
@@ -518,4 +518,4 @@ this.$unlink = function(object){
//</1.2compat>
-})();
+})(this);
View
14 Source/Element/Element.js
@@ -13,8 +13,8 @@ provides: [Element, Elements, $, $$, IFrame, Selectors]
...
*/
-
-var Element = this.Element = function(tag, props){
+(function(window){
+var Element = window.Element = function(tag, props){
var konstructor = Element.Constructors[tag];
if (konstructor) return konstructor(props);
if (typeof tag != 'string') return document.id(tag).set(props);
@@ -89,7 +89,7 @@ Element.Constructors = new Hash;
//</1.2compat>
-var IFrame = new Type('IFrame', function(){
+var IFrame = window.IFrame = new Type('IFrame', function(){
var params = Array.link(arguments, {
properties: Type.isObject,
iframe: function(obj){
@@ -113,7 +113,7 @@ var IFrame = new Type('IFrame', function(){
return iframe;
});
-var Elements = this.Elements = function(nodes){
+var Elements = window.Elements = function(nodes){
if (nodes && nodes.length){
var uniques = {}, node;
for (var i = 0; node = nodes[i++];){
@@ -184,6 +184,8 @@ Elements.alias('extend', 'append');
//</1.2compat>
+})(this);
+
(function(){
// FF, IE
@@ -259,7 +261,7 @@ Document.implement({
})();
-(function(){
+(function(window){
Slick.uidOf(window);
Slick.uidOf(document);
@ibolmo
ibolmo Jul 7, 2014

Should this become window.document, or pass in a document reference?

@@ -1191,4 +1193,4 @@ if (document.createElement('div').getAttributeNode('id')) Element.Properties.id
};
/*</IE>*/
-})();
+})(this);
View
6 Source/Fx/Fx.js
@@ -14,9 +14,9 @@ provides: Fx
...
*/
-(function(){
+(function(window){
-var Fx = this.Fx = new Class({
+var Fx = window.Fx = new Class({
Implements: [Chain, Events, Options],
@@ -180,4 +180,4 @@ var pullInstance = function(fps){
}
};
-})();
+})(this);
View
6 Source/Request/Request.js
@@ -14,12 +14,12 @@ provides: Request
...
*/
-(function(){
+(function(window){
var empty = function(){},
progressSupport = ('onprogress' in new Browser.Request);
-var Request = this.Request = new Class({
+var Request = window.Request = new Class({
Implements: [Chain, Events, Options],
@@ -282,4 +282,4 @@ Element.implement({
});
-})();
+})(this);
View
8 Source/Slick/Slick.Finder.js
@@ -7,7 +7,7 @@ requires: Slick.Parser
...
*/
-;(function(){
+;(function(window){
var local = {},
featuresCache = {},
@@ -897,7 +897,7 @@ attributeGetters.MAXLENGTH = attributeGetters.maxLength = attributeGetters.maxle
// Slick
-var Slick = local.Slick = (this.Slick || {});
+var Slick = local.Slick = (window.Slick || {});
Slick.version = '1.1.7';
@@ -980,6 +980,6 @@ Slick.uidOf = function(node){
return local.getUIDHTML(node);
};
-if (!this.Slick) this.Slick = Slick;
+if (!window.Slick) window.Slick = Slick;
-}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
+})(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
View
8 Source/Slick/Slick.Parser.js
@@ -6,7 +6,7 @@ provides: Slick.Parser
...
*/
-;(function(){
+;(function(window){
var parsed,
separatorIndex,
@@ -217,14 +217,14 @@ function parser(
// Slick NS
-var Slick = (this.Slick || {});
+var Slick = (window.Slick || {});
Slick.parse = function(expression){
return parse(expression);
};
Slick.escapeRegExp = escapeRegExp;
-if (!this.Slick) this.Slick = Slick;
+if (!window.Slick) window.Slick = Slick;
-}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
+})(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
View
6 Source/Types/DOMEvent.js
@@ -14,11 +14,11 @@ provides: Event
...
*/
-(function() {
+(function(window) {
var _keys = {};
-var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){
+var DOMEvent = window.DOMEvent = new Type('DOMEvent', function(event, win){
if (!win) win = window;
event = event || win.event;
if (event.$extended) return event;
@@ -111,7 +111,7 @@ DOMEvent.defineKeys({
'46': 'delete', '13': 'enter'
});
-})();
+})(this);
/*<1.3compat>*/
var Event = DOMEvent;

0 comments on commit d3962bf

Please sign in to comment.