国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

模仿jq寫個庫 完善中 。。。

Drinkey / 1118人閱讀

(function() {
  var es = function(selector) {
    return new es.prototype.init(selector);
  };

  es.domReady = function(fn) {
    document.addEventListener("DOMContentLoaded", function() {
      fn && fn();
    }, false);

  };

  es.each = function(obj, cb) {
    var ret, i = 0;
    if (obj.length === +obj.length) { //鴨辯
      while(obj.length !== i) {
        ret = cb.call(obj[i], i, obj[i]);
        if (ret === "break") {
          break;
        }
        if (ret !== undefined) {
          return ret;
        }
        i++;
      }
    }

    else if (obj instanceof Object) {
      for (var k in obj) {
        if (obj.hasOwnProperty(k)) {
          ret = cb.call(obj[k], k, obj[k]);
          if (ret === "break") {
            break;
          }
          if (ret !== undefined) {
            return ret;
          }
        }
      }
    }
  };

  es.event = function() {
    var events = [];
    var types = ["click"]
    return {
      on: function(type, cb) {
        var arr = events[type] = events[type] || [];

        if (types.indexOf(type) !== -1) {
          es.each(this, function(i, el) {
            el.addEventListener(type, cb);
          });
        }

        if (arr.indexOf(cb) === -1) {
          arr.push(cb);
        }
        return this;
      },
      off: function(type, cb) {
        var arr = events[type] = events[type] || [], i = 0;

        //傳統事件
        if (types.indexOf(type) !== -1) { 
          es.each(this, function(i, el) {
            cb && el.removeEventListener(type, cb);
            if (!cb) {
              es.each(events[type], function(i, cb) {
                el.removeEventListener(type, cb);
              });
            }
          });
        }

        if(!cb) events[type] = [];
        cb && es.each(arr, function(i, fn) {
          if (fn === cb) {
            arr.splice(i, 1);
            return "break";
          }  
        });

        return this;
      },
      emit: function(type) {
        var arr = events[type] = events[type] || [], self = this, argv = arguments;
        es.each(arr, function(i, fn) {
          fn.apply(self, [].slice.call(argv, 1));
        });
      }
    }
  }();

  es.ajax = function (opt) {
    var callback = opt.callback || function() {};
    var type = opt.type || "GET";
    var req = new XMLHttpRequest();
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.open(type, URL, true);
    req.onreadystatechange = function() {
      if (req.status === 200) {
        callback(null, req.responseText);
      } else {
        callback(new Error(req.statusText), req.response);
      }
    };
    req.onerror = function() {
      callback(new Error(req.statusText));
    };
    req.send(opt.data ? opt.data : null);
  };

  es.get = function(url, data, callback) {
    es.ajax({
      url : url,
      data: data,
      callback : callback
    });
  };

  es.post = function(url, callback) {
    es.ajax({
      type: "POST",
      data: data,
      callback: callback
    });
  };

  var oo = es.prototype = {
    constructor: es,
    splice: [].splice,
    shift: [].shift,
    push: [].push,
    length: 0,
  };
  

  oo.init = function(selector) {
    var els;

    if (typeof selector === "string") {
      els = document.querySelectorAll(selector), els = [].slice.call(els, 0);
    } else if(selector instanceof HTMLElement) {
      els = [selector];
    } else if (selector instanceof es) {
      return es;
    } else if (selector instanceof Array) {
      els = selector;
    }

    while(els[0]) {
      this.push(els.shift());
    }
  };

  oo.init.prototype = oo;

  oo.each = function(cb) {    
    return es.each(this, function(i, el) {
      return cb.call(el, i, el);
    });
  };

  oo.is = function(name) {
    return es.each(this, function(i, el) {
      if (name.slice(0, 1) === "#") {
        return el.id === name.slice(1);
      }
      else if(name.slice(0, 1) === ".") {
        return el.classList.contains(name.slice(1));
      }
      else {
        return el.tagName.toLowerCase() === name.toLowerCase()
      }
    });
  };

  oo.addClass = function(cls) {
    es.each(this, function(i, el) {
      el.classList.add(cls);
    });
    return this;
  };

  oo.removeClass = function(cls) {
    es.each(this, function(i, el) {
      el.classList.remove(cls);
    });
    return this;
  };

  oo.addStyle = function(cssText) {
    es.each(this, function(i, el) {
      el.style.cssText = cssText;
    });
    return this;
  };

  oo.next = function() {
    var self = this;
    es.each(this, function(i, el) {
      self[i] = el.nextElementSibling;
    });
    return this;
  };


  oo.prev = function() {
    var self = this;
    es.each(this, function(i, el) {
      self[i] = el.previousElementSibling;
    });
    return this;
  };

  oo.parent = function(selector) {
    var parent = [];
    es.each(this, function(i, el) {
      if (parent.indexOf(el.parentNode) === -1) {
        parent.push(el.parentNode);
      }
    });

    this.length = 0;
    while(parent[0]) {
      var el = parent.shift();
      if (selector) {
        es(el).is(selector) && this.push(el);
      } else {
        this.push(el);
      }
    };
    return this;
  };

  oo.children = function(selector) {
    var children = [], el;
    es.each(this, function(i, el) {
      children = children.concat([].slice.call(el.children, 0));
    });

    this.length = 0;

    while(children[0]) {
      el = children.shift();
      if (!selector) {
        this.push(el);
      }
      if (selector && es(el).is(selector)) {
        this.push(el);
      } 
    }
    return this;
  };

  oo.find = function(selector) {
    var all = [];
    es.each(this, function(i, el) {
      all = all.concat([].slice.call(el.querySelectorAll(selector), 0));
    });

    this.length = 0;
    while(all[0]) {
      this.push(all.shift());
    }
    return this;
  };

  oo.first = function() {
    return es(this[0]);
  };

  oo.last = function() {
    return es(this[this.length - 1]);
  };

  oo.attr = function(key, value) {
    if (value === undefined) {
      return es.each(this, function(i, el) {
        return el.getAttribute(key);
      });
    }

    es.each(this, function(i, el) {
      el.setAttribute(key, value);
    });
    return this;
  };

  es.insert = function (arr, pos, str) {
    es.each(arr, function(i, el) {
      el.insertAdjacentHTML(pos, str);
    });
  };

  oo.append = function(str) {
    if (typeof str === "string") {
      es.insert(this, "beforeend", str);
    } 

    if (str instanceof HTMLElement) {
      es.each(this, function(i, el) {
        el.appendChild(str);
        return "break";
      });
    }
    return this;
  };

  oo.after = function(str) {
    es.insert(this, "afterend", str);
    return this;
  };

  oo.before = function(str) {
    es.insert(this, "beforebegin", str);
    return this;
  };

  oo.prepend = function(str) {
    es.insert(this, "afterbegin", str);
    return this;
  };

  oo.on = es.event.on;
  oo.off = es.event.off;
  oo.emit = es.event.emit;

  window.es = es;

})();

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/78929.html

相關文章

  • 原生js造輪子之模仿JQ的slideDown()與slideUp()

    摘要:代碼如下原生調用該文件中加入這一行代碼參數參數時間調用該文件加入這一行代碼中引入綁定到實例原型上組件中調用鄙人創建了一個群,供大家學習交流,希望和大家合作愉快,互相幫助,交流學習,以下為群二維碼 代碼如下: const slider = (function() { var Slider = {}; // the constructed function,timeManager,...

    王笑朝 評論0 收藏0
  • 原生js造輪子之模仿JQ的slideDown()與slideUp()

    摘要:代碼如下原生調用該文件中加入這一行代碼參數參數時間調用該文件加入這一行代碼中引入綁定到實例原型上組件中調用鄙人創建了一個群,供大家學習交流,希望和大家合作愉快,互相幫助,交流學習,以下為群二維碼 代碼如下: const slider = (function() { var Slider = {}; // the constructed function,timeManager,...

    RancherLabs 評論0 收藏0
  • 回顧自己三次失敗的面試經歷

    摘要:站在這個時間點上,我對自己之前三次失敗的面試經歷做了一次深度回顧。關于我第三次面試失敗的經歷,依然是與輪播圖有關。當然,這次思特奇面試之旅,最后也是以失敗告終,這也是我離進大廠最近的一次。 showImg(https://segmentfault.com/img/bVYQuP?w=528&h=513); 前言 時間的齒輪已經來到了2017年的11月份,距離2018年僅僅還剩下不到兩...

    DC_er 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<