Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change this & window reference to a global passed in closure #2630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions Source/Browser/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ provides: [Browser, Window, Document]
...
*/

(function(){
(function(global){

var document = this.document;
var window = document.window = this;
var document = global.document;
var window = document.window = global;

var parse = function(ua, platform){
ua = ua.toLowerCase();
Expand Down Expand Up @@ -52,9 +52,9 @@ if (Browser.name == 'ie'){
Browser.extend({
Features: {
xpath: !!(document.evaluate),
air: !!(window.runtime),
air: !!(global.runtime),
query: !!(document.querySelector),
json: !!(window.JSON)
json: !!(global.JSON)
},
parseUA: parse
});
Expand Down Expand Up @@ -131,8 +131,8 @@ Browser.Plugins = {

Browser.exec = function(text){
if (!text) return text;
if (window.execScript){
window.execScript(text);
if (global.execScript){
global.execScript(text);
} else {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
Expand Down Expand Up @@ -163,15 +163,15 @@ Browser.extend({
Event: this.Event
});

this.Window = this.$constructor = new Type('Window', function(){});
global.Window = global.$constructor = new Type('Window', function(){});

this.$family = Function.from('window').hide();
global.$family = Function.from('window').hide();

Window.mirror(function(name, method){
window[name] = method;
global[name] = method;
});

this.Document = document.$constructor = new Type('Document', function(){});
global.Document = document.$constructor = new Type('Document', function(){});

document.$family = Function.from('document').hide();

Expand All @@ -187,12 +187,12 @@ if (document.execCommand) try {
} catch (e){}

/*<ltIE9>*/
if (this.attachEvent && !this.addEventListener){
if (global.attachEvent && !global.addEventListener){
var unloadEvent = function(){
this.detachEvent('onunload', unloadEvent);
global.detachEvent('onunload', unloadEvent);
document.head = document.html = document.window = null;
};
this.attachEvent('onunload', unloadEvent);
global.attachEvent('onunload', unloadEvent);
}

// IE fails on collections and <select>.options (refers to <select>)
Expand Down Expand Up @@ -278,8 +278,8 @@ if (Browser.name == 'unknown'){
}
}

this.$exec = Browser.exec;
global.$exec = Browser.exec;

//</1.2compat>

})();
})(this);
52 changes: 26 additions & 26 deletions Source/Core/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ provides: [Core, MooTools, Type, typeOf, instanceOf, Native]
...
*/

(function(){
(function(global){

this.MooTools = {
global.MooTools = {
version: '1.5.1-dev',
build: '%build%'
};

// typeOf, instanceOf

var typeOf = this.typeOf = function(item){
var typeOf = global.typeOf = function(item){
if (item == null) return 'null';
if (item.$family != null) return item.$family();

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

var instanceOf = this.instanceOf = function(item, object){
var instanceOf = global.instanceOf = function(item, object){
if (item == null) return false;
var constructor = item.$constructor || item.constructor;
while (constructor){
Expand All @@ -59,7 +59,7 @@ var instanceOf = this.instanceOf = function(item, object){

// Function overloading

var Function = this.Function;
var Function = global.Function;

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

// Type

var Type = this.Type = function(name, object){
var Type = global.Type = function(name, object){
if (name){
var lower = name.toLowerCase();
var typeCheck = function(item){
Expand Down Expand Up @@ -400,7 +400,7 @@ String.extend('uniqueID', function(){

//<1.2compat>

var Hash = this.Hash = new Type('Hash', function(object){
var Hash = global.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;
Expand Down Expand Up @@ -434,7 +434,7 @@ Hash.alias('each', 'forEach');

Object.type = Type.isObject;

var Native = this.Native = function(properties){
var Native = global.Native = function(properties){
return new Type(properties.name, properties.initialize);
};

Expand All @@ -450,64 +450,64 @@ Array.type = function(item){
return instanceOf(item, Array) || arrayType(item);
};

this.$A = function(item){
global.$A = function(item){
return Array.from(item).slice();
};

this.$arguments = function(i){
global.$arguments = function(i){
return function(){
return arguments[i];
};
};

this.$chk = function(obj){
global.$chk = function(obj){
return !!(obj || obj === 0);
};

this.$clear = function(timer){
global.$clear = function(timer){
clearTimeout(timer);
clearInterval(timer);
return null;
};

this.$defined = function(obj){
global.$defined = function(obj){
return (obj != null);
};

this.$each = function(iterable, fn, bind){
global.$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(){};
global.$empty = function(){};

this.$extend = function(original, extended){
global.$extend = function(original, extended){
return Object.append(original, extended);
};

this.$H = function(object){
global.$H = function(object){
return new Hash(object);
};

this.$merge = function(){
global.$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;
global.$lambda = Function.from;
global.$mixin = Object.merge;
global.$random = Number.random;
global.$splat = Array.from;
global.$time = Date.now;

this.$type = function(object){
global.$type = function(object){
var type = typeOf(object);
if (type == 'elements') return 'array';
return (type == 'null') ? false : type;
};

this.$unlink = function(object){
global.$unlink = function(object){
switch (typeOf(object)){
case 'object': return Object.clone(object);
case 'array': return Array.clone(object);
Expand All @@ -518,4 +518,4 @@ this.$unlink = function(object){

//</1.2compat>

})();
})(this);
6 changes: 3 additions & 3 deletions Source/Element/Element.Delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ provides: [Element.Delegation]
...
*/

(function(){
(function(global){

var eventListenerSupport = !!window.addEventListener;
var eventListenerSupport = !!global.addEventListener;

Element.NativeEvents.focusin = Element.NativeEvents.focusout = 2;

Expand Down Expand Up @@ -198,4 +198,4 @@ var delegation = {
removeEvent: relay(removeEvent, delegation.removeEvent)
});

})();
})(this);
8 changes: 4 additions & 4 deletions Source/Element/Element.Dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provides: [Element.Dimensions]
...
*/

(function(){
(function(global){

var element = document.createElement('div'),
child = document.createElement('div');
Expand All @@ -32,7 +32,7 @@ var heightComponents = ['height', 'paddingTop', 'paddingBottom', 'borderTopWidth

var svgCalculateSize = function(el){

var gCS = window.getComputedStyle(el),
var gCS = global.getComputedStyle(el),
bounds = {x: 0, y: 0};

heightComponents.each(function(css){
Expand Down Expand Up @@ -69,7 +69,7 @@ Element.implement({

//<ltIE9>
// This if clause is because IE8- cannot calculate getBoundingClientRect of elements with visibility hidden.
if (!window.getComputedStyle) return {x: this.offsetWidth, y: this.offsetHeight};
if (!global.getComputedStyle) return {x: this.offsetWidth, y: this.offsetHeight};
//</ltIE9>

// This svg section under, calling `svgCalculateSize()`, can be removed when FF fixed the svg size bug.
Expand Down Expand Up @@ -274,7 +274,7 @@ function getCompatElement(element){
return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
}

})();
})(this);

//aliases
Element.alias({position: 'setPosition'}); //compatability
Expand Down
6 changes: 3 additions & 3 deletions Source/Element/Element.Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ provides: Element.Event
...
*/

(function(){
(function(global){

Element.Properties.events = {set: function(events){
this.addEvents(events);
Expand Down Expand Up @@ -171,7 +171,7 @@ if ('onmouseenter' in document.documentElement){
}

/*<ltIE9>*/
if (!window.addEventListener){
if (!global.addEventListener){
Element.NativeEvents.propertychange = 2;
Element.Events.change = {
base: function(){
Expand All @@ -191,4 +191,4 @@ Element.Events = new Hash(Element.Events);

//</1.2compat>

})();
})(this);
6 changes: 3 additions & 3 deletions Source/Element/Element.Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ provides: Element.Style
...
*/

(function(){
(function(global){

var html = document.html, el;

Expand All @@ -32,7 +32,7 @@ var returnsBordersInWrongOrder = el.style.border != border;
el = null;
//</ltIE9>

var hasGetComputedStyle = !!window.getComputedStyle,
var hasGetComputedStyle = !!global.getComputedStyle,
supportBorderRadius = document.createElement('div').style.borderRadius != null;

Element.Properties.styles = {set: function(styles){
Expand Down Expand Up @@ -260,4 +260,4 @@ Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, bor
});

if (hasBackgroundPositionXY) Element.ShortStyles.backgroundPosition = {backgroundPositionX: '@', backgroundPositionY: '@'};
})();
})(this);
Loading