Fixed eslint issues

This commit is contained in:
Tomas Korcak 2015-08-14 19:54:03 +02:00
parent 3a4355416c
commit 82ba3fab49
3 changed files with 63 additions and 65 deletions

View File

@ -11,8 +11,8 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
var ARR_EACH = Array.prototype.forEach;
var ARR_SLICE = Array.prototype.slice;
const ARR_EACH = Array.prototype.forEach;
const ARR_SLICE = Array.prototype.slice;
/**
* Band-aid methods for things that should be a lot easier in JavaScript.
@ -20,118 +20,112 @@ var ARR_SLICE = Array.prototype.slice;
* http://documentcloud.github.com/underscore/
*/
var Common = {
const Common = {
BREAK: {},
extend: function (target) {
this.each(ARR_SLICE.call(arguments, 1), function (obj) {
for (var key in obj)
if (!this.isUndefined(obj[key]))
extend: function(target) {
this.each(ARR_SLICE.call(arguments, 1), function(obj) {
for (const key in obj) {
if (!this.isUndefined(obj[key])) {
target[key] = obj[key];
}
}
}, this);
return target;
},
defaults: function (target) {
this.each(ARR_SLICE.call(arguments, 1), function (obj) {
for (var key in obj)
if (this.isUndefined(target[key]))
defaults: function(target) {
this.each(ARR_SLICE.call(arguments, 1), function(obj) {
for (const key in obj) {
if (this.isUndefined(target[key])) {
target[key] = obj[key];
}
}
}, this);
return target;
},
compose: function () {
var toCall = ARR_SLICE.call(arguments);
return function () {
var args = ARR_SLICE.call(arguments);
for (var i = toCall.length - 1; i >= 0; i--) {
compose: function() {
const toCall = ARR_SLICE.call(arguments);
return function() {
let args = ARR_SLICE.call(arguments);
for (let i = toCall.length - 1; i >= 0; i--) {
args = [toCall[i].apply(this, args)];
}
return args[0];
}
};
},
each: function (obj, itr, scope) {
if (!obj) return;
each: function(obj, itr, scope) {
if (!obj) {
return;
}
if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {
obj.forEach(itr, scope);
} else if (obj.length === obj.length + 0) { // Is number but not NaN
for (var key = 0, l = obj.length; key < l; key++)
if (key in obj && itr.call(scope, obj[key], key) === this.BREAK)
let key;
for (key = 0, l = obj.length; key < l; key++) {
if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) {
return;
}
}
} else {
for (var key in obj)
if (itr.call(scope, obj[key], key) === this.BREAK)
for (const key in obj) {
if (itr.call(scope, obj[key], key) === this.BREAK) {
return;
}
}
}
},
defer: function (fnc) {
defer: function(fnc) {
setTimeout(fnc, 0);
},
toArray: function (obj) {
toArray: function(obj) {
if (obj.toArray) return obj.toArray();
return ARR_SLICE.call(obj);
},
isUndefined: function (obj) {
isUndefined: function(obj) {
return obj === undefined;
},
isNull: function (obj) {
isNull: function(obj) {
return obj === null;
},
isNaN: function (obj) {
return obj !== obj;
isNaN: function(obj) {
return isNaN(obj);
},
isArray: Array.isArray || function (obj) {
isArray: Array.isArray || function(obj) {
return obj.constructor === Array;
},
isObject: function (obj) {
isObject: function(obj) {
return obj === Object(obj);
},
isNumber: function (obj) {
isNumber: function(obj) {
return obj === obj + 0;
},
isString: function (obj) {
isString: function(obj) {
return obj === obj + '';
},
isBoolean: function (obj) {
isBoolean: function(obj) {
return obj === false || obj === true;
},
isFunction: function (obj) {
isFunction: function(obj) {
return Object.prototype.toString.call(obj) === '[object Function]';
}
};
module.exports = Common;
export default Common;

View File

@ -12,19 +12,20 @@
*/
module.exports = {
load: function (url, doc) {
doc = doc || document;
var link = doc.createElement('link');
load: function(url, indoc) {
const doc = indoc || document;
const link = doc.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = url;
doc.getElementsByTagName('head')[0].appendChild(link);
},
inject: function (css, doc) {
doc = doc || document;
var injected = document.createElement('style');
inject: function(css, indoc) {
const doc = indoc || document;
const injected = document.createElement('style');
injected.type = 'text/css';
injected.innerHTML = css;
doc.getElementsByTagName('head')[0].appendChild(injected);
}
};
};

View File

@ -11,13 +11,16 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
module.exports = function () {
export default function() {
function requestAnimationFrame(callback) {
// TODO: Get rid of window
window.setTimeout(callback, 1000 / 60);
}
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback, element) {
window.setTimeout(callback, 1000 / 60);
};
};
requestAnimationFrame;
}