]> iEval git - plack-app-gruntmaster.git/blobdiff - js/05-ki.js
Replace Zepto with ki.js, rewrite all JS
[plack-app-gruntmaster.git] / js / 05-ki.js
diff --git a/js/05-ki.js b/js/05-ki.js
new file mode 100644 (file)
index 0000000..59104b4
--- /dev/null
@@ -0,0 +1,71 @@
+/*!
+ * ki.js - jQuery-like API super-tiny JavaScript library
+ * Copyright (c) 2014 Denis Ciccale (@tdecs)
+ * Released under MIT license
+ */
+!function (b, c, d, e) {
+
+  /*
+   * init function (internal use)
+   * a = selector, dom element or function
+   */
+  function i(a) {
+    c.push.apply(this, a && a.nodeType ? [a] : '' + a === a ? b.querySelectorAll(a) : e)
+  }
+
+  /*
+   * $ main function
+   * a = css selector, dom object, or function
+   * http://www.dustindiaz.com/smallest-domready-ever
+   * returns instance or executes function on ready
+   */
+  $ = function (a) {
+    return /^f/.test(typeof a) ? /c/.test(b.readyState) ? a() : $(b).on('DOMContentLoaded', a) : new i(a)
+  }
+
+  // set ki prototype
+  $[d] = i[d] = {
+
+    // default length
+    length: 0,
+
+    /*
+     * on method
+     * a = string event type i.e 'click'
+     * b = function
+     * return this
+     */
+    on: function (a, b) {
+      return this.each(function (c) {
+        c.addEventListener(a, b)
+      })
+    },
+
+    /*
+     * off method
+     * a = string event type i.e 'click'
+     * b = function
+     * return this
+     */
+    off: function (a, b) {
+      return this.each(function (c) {
+        c.removeEventListener(a, b)
+      })
+    },
+
+    /*
+     * each method
+     * use native forEach to iterate collection
+     * a = the function to call on each iteration
+     * b = the this value for that function
+     */
+    each: function (a, b) {
+      c.forEach.call(this, a, b)
+      return this
+    },
+
+    // for some reason is needed to get an array-like
+    // representation instead of an object
+    splice: c.splice
+  }
+}(document, [], 'prototype');
This page took 0.024892 seconds and 4 git commands to generate.