Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*\
  2. DOM class
  3. \*----------------------------------------------------------------------------*/
  4. class Dom {
  5.  
  6.  
  7. /*------------------------------------------------------------------------*\
  8. CONSTRUCTOR
  9. Args: CSS Selector, DOM obj (optional)
  10. \*------------------------------------------------------------------------*/
  11. constructor(sel, obj) {
  12.  
  13. // Set the element this component refers to
  14. this.nodes = this._querySelectorAll
  15. .call(obj && typeof obj.nodes !== 'undefined'? obj.nodes :document,sel);
  16.  
  17. this.each = this.each.bind(this);
  18.  
  19. // ... Rest of bound functions
  20.  
  21. this.factory = this.factory.bind(this);
  22. }
  23.  
  24.  
  25. /*------------------------------------------------------------------------*\
  26. FACTORY
  27. Factory function which returns a new instance of this class
  28. \*------------------------------------------------------------------------*/
  29. factory(sel) {
  30. return new Dom(sel);
  31. }
  32.  
  33.  
  34. /*------------------------------------------------------------------------*\
  35. _querySelectorAll : PRIVATE
  36. Args: CSS Selector
  37. Returns: A NodeList containing elements matching selector
  38. \*------------------------------------------------------------------------*/
  39. _querySelectorAll(sel) {
  40. return this.querySelectorAll(sel);
  41. }
  42.  
  43.  
  44.  
  45. /*------------------------------------------------------------------------*\
  46. EACH
  47. Args: Callback Function
  48. \*------------------------------------------------------------------------*/
  49. each(fn) {
  50.  
  51. // Casts NodeList to array and maps items to
  52. // supplied callback function
  53. for (var node of [...this.nodes]) {
  54. fn(...arguments);
  55. }
  56.  
  57. return this;
  58. }
  59.  
  60. // ... etc ...
  61. }
  62.  
  63. /*----------------------------------------------------------------------------*\
  64. EXPORTS
  65. Export factory as default so we can use jQuery-style constructors
  66. \*----------------------------------------------------------------------------*/
  67. export default Dom.prototype.factory;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement