Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------*\
- DOM class
- \*----------------------------------------------------------------------------*/
- class Dom {
- /*------------------------------------------------------------------------*\
- CONSTRUCTOR
- Args: CSS Selector, DOM obj (optional)
- \*------------------------------------------------------------------------*/
- constructor(sel, obj) {
- // Set the element this component refers to
- this.nodes = this._querySelectorAll
- .call(obj && typeof obj.nodes !== 'undefined'? obj.nodes :document,sel);
- this.each = this.each.bind(this);
- // ... Rest of bound functions
- this.factory = this.factory.bind(this);
- }
- /*------------------------------------------------------------------------*\
- FACTORY
- Factory function which returns a new instance of this class
- \*------------------------------------------------------------------------*/
- factory(sel) {
- return new Dom(sel);
- }
- /*------------------------------------------------------------------------*\
- _querySelectorAll : PRIVATE
- Args: CSS Selector
- Returns: A NodeList containing elements matching selector
- \*------------------------------------------------------------------------*/
- _querySelectorAll(sel) {
- return this.querySelectorAll(sel);
- }
- /*------------------------------------------------------------------------*\
- EACH
- Args: Callback Function
- \*------------------------------------------------------------------------*/
- each(fn) {
- // Casts NodeList to array and maps items to
- // supplied callback function
- for (var node of [...this.nodes]) {
- fn(...arguments);
- }
- return this;
- }
- // ... etc ...
- }
- /*----------------------------------------------------------------------------*\
- EXPORTS
- Export factory as default so we can use jQuery-style constructors
- \*----------------------------------------------------------------------------*/
- export default Dom.prototype.factory;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement