Created
March 31, 2017 18:26
-
-
Save caiotarifa/73812569aa7ad0a1b1a64e72a66608d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BigCoffee = function(selector) { | |
var elements = document.querySelectorAll(selector), | |
index = 0; | |
if (this === window) { | |
return new BigCoffee(selector); | |
} | |
for (; index < elements.length; index++) { | |
this[index] = elements[index]; | |
} | |
this.length = elements.length; | |
return this; | |
}; | |
BigCoffee.prototype = { | |
map: function(callback) { | |
var results = [], | |
index = 0; | |
for (; index < this.length; index++) { | |
results.push(callback.call(this, this[index], index)); | |
} | |
return results; | |
}, | |
forEach: function(callback) { | |
this.map(callback); | |
return this; | |
}, | |
// CLASSES | |
addClass: function(className) { | |
return this.forEach(function(element) { | |
element.classList.add(className); | |
}); | |
}, | |
hasClass: function() { | |
return 105; | |
}, | |
removeClass: function(className) { | |
return this.forEach(function(element) { | |
element.classList.remove(className); | |
}); | |
}, | |
// ATTRIBUTES | |
getAttribute: function(attribute) { | |
return this.forEach(function(element) { | |
element.getAttribute(attribute); | |
}); | |
}, | |
removeAttribute: function(attribute) { | |
return this.forEach(function(element) { | |
element.removeAttribute(attribute); | |
}); | |
}, | |
setAttribute: function(attribute, value) { | |
return this.forEach(function(element) { | |
element.setAttribute(attribute, value); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment