Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. addClass: function (newClass) {
  2.         this.elements.forEach((element, index) => {
  3.             if (typeof newClass === 'function') {
  4.                 const cssClasses = newClass.call(element, index, element.className);
  5.                 $(element).addClass(cssClasses);
  6.             }
  7.         })
  8.     }
  9.     return this;
  10. },
  11.  
  12. append: function (newChild) {
  13.     if (typeof newChild == 'string') {
  14.         if (this.elements.length > 1) {
  15.             this.elements.forEach(element =>
  16.                 element.innerHTML = newChild);
  17.         } else {
  18.             this.elements[0].innerHTML = newChild;
  19.         }
  20.  
  21.     } else {
  22.         this.elements.forEach((element, index) => {
  23.             if (newChild.hasOwnProperty('elements')) {
  24.                 element.appendChild(newChild.elements[0].cloneNode(true))
  25.             } else {
  26.                 element.appendChild(newChild.cloneNode(true))
  27.             }
  28.         });
  29.  
  30.     }
  31.     return this;
  32. },
  33. attr: function (attr, args) {
  34.     if (arguments.length == 1) {
  35.         return this.elements[0].getAttribute(attr);
  36.     } else {
  37.         this.elements.forEach(element => {
  38.             for (let i = 0; i < arguments.length; i += 2) {
  39.                 element.setAttribute(arguments[i], arguments[i + 1]);
  40.             }
  41.         });
  42.     }
  43.     return this;
  44. },
  45. children : function () {
  46.     if (typeof this.elements.length == 'undefined') {
  47.         this.elements.children;
  48.     }
  49.     return this.elements[0].children;
  50. };
  51. html : function(arg) {
  52.     if (!arg) return this.elements[0].innerHTML;
  53.     if (typeof(arg) === "string") this.each(function (index, item) { item.innerHTML = arg; });
  54.     if (typeof(arg) === "function") this.each(function (index, item) {item.innerHTML = arg(index); });
  55.     return this;
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement