Skip to content

Commit

Permalink
Replace JSHint with ESLint (Karma and all source files follows eslintrc)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrongRef committed Jun 20, 2016
1 parent b391e80 commit b63c426
Show file tree
Hide file tree
Showing 33 changed files with 832 additions and 759 deletions.
8 changes: 5 additions & 3 deletions bliss._.js
Expand Up @@ -58,10 +58,12 @@ Object.defineProperty(Array.prototype, _, {
if (self.EventTarget && "addEventListener" in EventTarget.prototype) {
var addEventListener = EventTarget.prototype.addEventListener,
removeEventListener = EventTarget.prototype.removeEventListener,
equal = function(callback, capture, l){
return l.callback === callback && l.capture == capture;
equal = function(callback, capture, l) {
return l.callback === callback && l.capture == capture;
},
notEqual = function() { return !equal.apply(this, arguments); };
notEqual = function() {
return !equal.apply(this, arguments);
};

EventTarget.prototype.addEventListener = function(type, callback, capture) {
if (this && this[_] && this[_].bliss && callback) {
Expand Down
68 changes: 39 additions & 29 deletions bliss.js
Expand Up @@ -7,7 +7,7 @@ function overload(callback, start, end) {

if (end - start <= 1) {
return function() {
if (arguments.length <= start || $.type(arguments[start]) === 'string') {
if (arguments.length <= start || $.type(arguments[start]) === "string") {
return callback.apply(this, arguments);
}

Expand Down Expand Up @@ -68,7 +68,7 @@ extend($, {

sources: {},

noop: function(){},
noop: function() {},

$: function(expr, context) {
if (expr instanceof Node || expr instanceof Window) {
Expand All @@ -82,14 +82,18 @@ extend($, {
* Returns the [[Class]] of an object in lowercase (eg. array, date, regexp, string etc)
*/
type: function(obj) {
if (obj === null) { return 'null'; }
if (obj === null) {
return "null";
}

if (obj === undefined) { return 'undefined'; }
if (obj === undefined) {
return "undefined";
}

var ret = (Object.prototype.toString.call(obj).match(/^\[object\s+(.*?)\]$/)[1] || "").toLowerCase();

if(ret == 'number' && isNaN(obj)) {
return 'nan';
if (ret == "number" && isNaN(obj)) {
return "nan";
}

return ret;
Expand Down Expand Up @@ -119,7 +123,9 @@ extend($, {
else {
o = tag;
tag = o.tag;
o = $.extend({}, o, function(property) { return property !== "tag"; });
o = $.extend({}, o, function(property) {
return property !== "tag";
});
}
}

Expand All @@ -139,12 +145,12 @@ extend($, {
ready: function(context) {
context = context || document;

return new Promise(function(resolve, reject){
return new Promise(function(resolve, reject) {
if (context.readyState !== "loading") {
resolve();
}
else {
context.addEventListener("DOMContentLoaded", function(){
context.addEventListener("DOMContentLoaded", function() {
resolve();
});
}
Expand Down Expand Up @@ -269,7 +275,7 @@ extend($, {

var script = document.createElement("script");

return loaded? Promise.resolve() : new Promise(function(resolve, reject){
return loaded? Promise.resolve() : new Promise(function(resolve, reject) {
$.set(script, {
async: true,
onload: function() {
Expand Down Expand Up @@ -313,7 +319,7 @@ extend($, {
env.url.search += env.data;
}

document.body.setAttribute('data-loading', env.url);
document.body.setAttribute("data-loading", env.url);

env.xhr.open(env.method, env.url.href, env.async !== false, env.user, env.password);

Expand All @@ -328,17 +334,17 @@ extend($, {
}
}

if (env.method !== 'GET' && !env.headers['Content-type'] && !env.headers['Content-Type']) {
if (env.method !== "GET" && !env.headers["Content-type"] && !env.headers["Content-Type"]) {
env.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}

for (var header in env.headers) {
env.xhr.setRequestHeader(header, env.headers[header]);
}

return new Promise(function(resolve, reject){
env.xhr.onload = function(){
document.body.removeAttribute('data-loading');
return new Promise(function(resolve, reject) {
env.xhr.onload = function() {
document.body.removeAttribute("data-loading");

if (env.xhr.status === 0 || env.xhr.status >= 200 && env.xhr.status < 300 || env.xhr.status === 304) {
// Success!
Expand All @@ -347,22 +353,24 @@ extend($, {
else {
reject($.extend(Error(env.xhr.statusText), {
xhr: env.xhr,
get status() { return this.xhr.status; }
get status() {
return this.xhr.status;
}
}));
}
};

env.xhr.onerror = function() {
document.body.removeAttribute('data-loading');
document.body.removeAttribute("data-loading");
reject($.extend(Error("Network Error"), {xhr: env.xhr}));
};

env.xhr.ontimeout = function() {
document.body.removeAttribute('data-loading');
document.body.removeAttribute("data-loading");
reject($.extend(Error("Network Timeout"), {xhr: env.xhr}));
};

env.xhr.send(env.method === 'GET'? null : env.data);
env.xhr.send(env.method === "GET"? null : env.data);
});
},

Expand Down Expand Up @@ -422,7 +430,7 @@ $.Element.prototype = {
transition: function(props, duration) {
duration = +duration || 400;

return new Promise(function(resolve, reject){
return new Promise(function(resolve, reject) {
if ("transition" in this.style) {
// Get existing style
var previous = $.extend({}, this.style, /^transition(Duration|Property)$/);
Expand All @@ -432,7 +440,7 @@ $.Element.prototype = {
transitionProperty: Object.keys(props).join(", ")
});

$.once(this, "transitionend", function(){
$.once(this, "transitionend", function() {
clearTimeout(i);
$.style(this, previous);
resolve(this);
Expand Down Expand Up @@ -478,7 +486,7 @@ $.Element.prototype = {
for (var i=0, l; l=listeners[ltype][i]; i++) {
if ((!className || className === l.className) &&
(!callback || callback === l.callback )) { // TODO what about capture?
this.removeEventListener.call(this, ltype, l.callback, l.capture);
this.removeEventListener(ltype, l.callback, l.capture);
i--;
}
}
Expand Down Expand Up @@ -527,7 +535,7 @@ $.setProps = {
var listeners = val[_].bliss.listeners;

for (var type in listeners) {
listeners[type].forEach(function(l){
listeners[type].forEach(function(l) {
me.addEventListener(type, l.callback, l.capture);
});
}
Expand All @@ -554,11 +562,11 @@ $.setProps = {
}
},

once: overload(function(events, callback){
once: overload(function(events, callback) {
events = events.split(/\s+/);
var me = this;
var once = function() {
events.forEach(function(event){
events.forEach(function(event) {
me.removeEventListener(event, once);
});

Expand Down Expand Up @@ -684,7 +692,7 @@ $.add($.classProps, {element: false, array: false});

// Add native methods on $ and _
var dummy = document.createElement("_");
$.add($.extend({}, HTMLElement.prototype, function(method){
$.add($.extend({}, HTMLElement.prototype, function(method) {
return $.type(dummy[method]) === "function";
}), null, true);

Expand Down Expand Up @@ -751,10 +759,12 @@ Object.defineProperty(Array.prototype, _, {
if (self.EventTarget && "addEventListener" in EventTarget.prototype) {
var addEventListener = EventTarget.prototype.addEventListener,
removeEventListener = EventTarget.prototype.removeEventListener,
equal = function(callback, capture, l){
return l.callback === callback && l.capture == capture;
equal = function(callback, capture, l) {
return l.callback === callback && l.capture == capture;
},
notEqual = function() { return !equal.apply(this, arguments); };
notEqual = function() {
return !equal.apply(this, arguments);
};

EventTarget.prototype.addEventListener = function(type, callback, capture) {
if (this && this[_] && this[_].bliss && callback) {
Expand Down
2 changes: 1 addition & 1 deletion bliss.min.js

Large diffs are not rendered by default.

0 comments on commit b63c426

Please sign in to comment.