Skip to content

Commit d3962bf

Browse files
use window inside closures to improve minification
1 parent 095a5a5 commit d3962bf

File tree

7 files changed

+50
-48
lines changed

7 files changed

+50
-48
lines changed

Source/Core/Core.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
2020
...
2121
*/
2222

23-
(function(){
23+
(function(window){
2424

25-
this.MooTools = {
25+
window.MooTools = {
2626
version: '1.5.1-dev',
2727
build: '%build%'
2828
};
2929

3030
// typeOf, instanceOf
3131

32-
var typeOf = this.typeOf = function(item){
32+
var typeOf = window.typeOf = function(item){
3333
if (item == null) return 'null';
3434
if (item.$family != null) return item.$family();
3535

@@ -44,7 +44,7 @@ var typeOf = this.typeOf = function(item){
4444
return typeof item;
4545
};
4646

47-
var instanceOf = this.instanceOf = function(item, object){
47+
var instanceOf = window.instanceOf = function(item, object){
4848
if (item == null) return false;
4949
var constructor = item.$constructor || item.constructor;
5050
while (constructor){
@@ -59,7 +59,7 @@ var instanceOf = this.instanceOf = function(item, object){
5959

6060
// Function overloading
6161

62-
var Function = this.Function;
62+
var Function = window.Function;
6363

6464
var enumerables = true;
6565
for (var i in {toString: 1}) enumerables = null;
@@ -149,7 +149,7 @@ Function.implement({
149149

150150
// Type
151151

152-
var Type = this.Type = function(name, object){
152+
var Type = window.Type = function(name, object){
153153
if (name){
154154
var lower = name.toLowerCase();
155155
var typeCheck = function(item){
@@ -400,7 +400,7 @@ String.extend('uniqueID', function(){
400400

401401
//<1.2compat>
402402

403-
var Hash = this.Hash = new Type('Hash', function(object){
403+
var Hash = window.Hash = new Type('Hash', function(object){
404404
if (typeOf(object) == 'hash') object = Object.clone(object.getClean());
405405
for (var key in object) this[key] = object[key];
406406
return this;
@@ -434,7 +434,7 @@ Hash.alias('each', 'forEach');
434434

435435
Object.type = Type.isObject;
436436

437-
var Native = this.Native = function(properties){
437+
var Native = window.Native = function(properties){
438438
return new Type(properties.name, properties.initialize);
439439
};
440440

@@ -450,58 +450,58 @@ Array.type = function(item){
450450
return instanceOf(item, Array) || arrayType(item);
451451
};
452452

453-
this.$A = function(item){
453+
window.$A = function(item){
454454
return Array.from(item).slice();
455455
};
456456

457-
this.$arguments = function(i){
457+
window.$arguments = function(i){
458458
return function(){
459459
return arguments[i];
460460
};
461461
};
462462

463-
this.$chk = function(obj){
463+
window.$chk = function(obj){
464464
return !!(obj || obj === 0);
465465
};
466466

467-
this.$clear = function(timer){
467+
window.$clear = function(timer){
468468
clearTimeout(timer);
469469
clearInterval(timer);
470470
return null;
471471
};
472472

473-
this.$defined = function(obj){
473+
window.$defined = function(obj){
474474
return (obj != null);
475475
};
476476

477-
this.$each = function(iterable, fn, bind){
477+
window.$each = function(iterable, fn, bind){
478478
var type = typeOf(iterable);
479479
((type == 'arguments' || type == 'collection' || type == 'array' || type == 'elements') ? Array : Object).each(iterable, fn, bind);
480480
};
481481

482-
this.$empty = function(){};
482+
window.$empty = function(){};
483483

484-
this.$extend = function(original, extended){
484+
window.$extend = function(original, extended){
485485
return Object.append(original, extended);
486486
};
487487

488-
this.$H = function(object){
488+
window.$H = function(object){
489489
return new Hash(object);
490490
};
491491

492-
this.$merge = function(){
492+
window.$merge = function(){
493493
var args = Array.slice(arguments);
494494
args.unshift({});
495495
return Object.merge.apply(null, args);
496496
};
497497

498-
this.$lambda = Function.from;
499-
this.$mixin = Object.merge;
500-
this.$random = Number.random;
501-
this.$splat = Array.from;
502-
this.$time = Date.now;
498+
window.$lambda = Function.from;
499+
window.$mixin = Object.merge;
500+
window.$random = Number.random;
501+
window.$splat = Array.from;
502+
window.$time = Date.now;
503503

504-
this.$type = function(object){
504+
window.$type = function(object){
505505
var type = typeOf(object);
506506
if (type == 'elements') return 'array';
507507
return (type == 'null') ? false : type;
@@ -518,4 +518,4 @@ this.$unlink = function(object){
518518

519519
//</1.2compat>
520520

521-
})();
521+
})(this);

Source/Element/Element.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ provides: [Element, Elements, $, $$, IFrame, Selectors]
1313
1414
...
1515
*/
16-
17-
var Element = this.Element = function(tag, props){
16+
(function(window){
17+
var Element = window.Element = function(tag, props){
1818
var konstructor = Element.Constructors[tag];
1919
if (konstructor) return konstructor(props);
2020
if (typeof tag != 'string') return document.id(tag).set(props);
@@ -89,7 +89,7 @@ Element.Constructors = new Hash;
8989

9090
//</1.2compat>
9191

92-
var IFrame = new Type('IFrame', function(){
92+
var IFrame = window.IFrame = new Type('IFrame', function(){
9393
var params = Array.link(arguments, {
9494
properties: Type.isObject,
9595
iframe: function(obj){
@@ -113,7 +113,7 @@ var IFrame = new Type('IFrame', function(){
113113
return iframe;
114114
});
115115

116-
var Elements = this.Elements = function(nodes){
116+
var Elements = window.Elements = function(nodes){
117117
if (nodes && nodes.length){
118118
var uniques = {}, node;
119119
for (var i = 0; node = nodes[i++];){
@@ -184,6 +184,8 @@ Elements.alias('extend', 'append');
184184

185185
//</1.2compat>
186186

187+
})(this);
188+
187189
(function(){
188190

189191
// FF, IE
@@ -259,7 +261,7 @@ Document.implement({
259261

260262
})();
261263

262-
(function(){
264+
(function(window){
263265

264266
Slick.uidOf(window);
265267
Slick.uidOf(document);
@@ -1191,4 +1193,4 @@ if (document.createElement('div').getAttributeNode('id')) Element.Properties.id
11911193
};
11921194
/*</IE>*/
11931195

1194-
})();
1196+
})(this);

Source/Fx/Fx.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ provides: Fx
1414
...
1515
*/
1616

17-
(function(){
17+
(function(window){
1818

19-
var Fx = this.Fx = new Class({
19+
var Fx = window.Fx = new Class({
2020

2121
Implements: [Chain, Events, Options],
2222

@@ -180,4 +180,4 @@ var pullInstance = function(fps){
180180
}
181181
};
182182

183-
})();
183+
})(this);

Source/Request/Request.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ provides: Request
1414
...
1515
*/
1616

17-
(function(){
17+
(function(window){
1818

1919
var empty = function(){},
2020
progressSupport = ('onprogress' in new Browser.Request);
2121

22-
var Request = this.Request = new Class({
22+
var Request = window.Request = new Class({
2323

2424
Implements: [Chain, Events, Options],
2525

@@ -282,4 +282,4 @@ Element.implement({
282282

283283
});
284284

285-
})();
285+
})(this);

Source/Slick/Slick.Finder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires: Slick.Parser
77
...
88
*/
99

10-
;(function(){
10+
;(function(window){
1111

1212
var local = {},
1313
featuresCache = {},
@@ -897,7 +897,7 @@ attributeGetters.MAXLENGTH = attributeGetters.maxLength = attributeGetters.maxle
897897

898898
// Slick
899899

900-
var Slick = local.Slick = (this.Slick || {});
900+
var Slick = local.Slick = (window.Slick || {});
901901

902902
Slick.version = '1.1.7';
903903

@@ -980,6 +980,6 @@ Slick.uidOf = function(node){
980980
return local.getUIDHTML(node);
981981
};
982982

983-
if (!this.Slick) this.Slick = Slick;
983+
if (!window.Slick) window.Slick = Slick;
984984

985-
}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
985+
})(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);

Source/Slick/Slick.Parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ provides: Slick.Parser
66
...
77
*/
88

9-
;(function(){
9+
;(function(window){
1010

1111
var parsed,
1212
separatorIndex,
@@ -217,14 +217,14 @@ function parser(
217217

218218
// Slick NS
219219

220-
var Slick = (this.Slick || {});
220+
var Slick = (window.Slick || {});
221221

222222
Slick.parse = function(expression){
223223
return parse(expression);
224224
};
225225

226226
Slick.escapeRegExp = escapeRegExp;
227227

228-
if (!this.Slick) this.Slick = Slick;
228+
if (!window.Slick) window.Slick = Slick;
229229

230-
}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);
230+
})(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);

Source/Types/DOMEvent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ provides: Event
1414
...
1515
*/
1616

17-
(function() {
17+
(function(window) {
1818

1919
var _keys = {};
2020

21-
var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){
21+
var DOMEvent = window.DOMEvent = new Type('DOMEvent', function(event, win){
2222
if (!win) win = window;
2323
event = event || win.event;
2424
if (event.$extended) return event;
@@ -111,7 +111,7 @@ DOMEvent.defineKeys({
111111
'46': 'delete', '13': 'enter'
112112
});
113113

114-
})();
114+
})(this);
115115

116116
/*<1.3compat>*/
117117
var Event = DOMEvent;

0 commit comments

Comments
 (0)