Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cash-dom

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cash-dom - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

src/offset.js

4

bower.json
{
"name": "cash",
"main": ["dist/cash.min.js", "dist/cash.js"],
"version": "1.0.0",
"version": "1.2.0",
"homepage": "https://github.com/kenwheeler/cash",

@@ -9,3 +9,3 @@ "authors": [

],
"description": "Supermodel-weight jQuery replacement for modern browsers",
"description": "An absurdly small jQuery alternative for modern browsers.",
"keywords": [

@@ -12,0 +12,0 @@ "jquery",

@@ -12,18 +12,35 @@ "use strict";

})(this, function () {
var doc = document, win = window, ArrayProto = Array.prototype, slice = ArrayProto.slice, filter = ArrayProto.filter;
var doc = document, win = window, ArrayProto = Array.prototype, slice = ArrayProto.slice, filter = ArrayProto.filter, push = ArrayProto.push;
var idMatch = /^#[\w-]*$/, classMatch = /^\.[\w-]*$/, singlet = /^[\w-]*$/;
var noop = function () {}, isFunction = function (item) {
return typeof item === typeof noop;
}, isString = function (item) {
return typeof item === typeof "";
};
function cash(selector, context) {
return new cash.fn.init(selector, context);
var idMatch = /^#[\w-]*$/, classMatch = /^\.[\w-]*$/, htmlMatch = /<.+>/, singlet = /^\w+$/;
function find(selector, context) {
context = context || doc;
var elems = (classMatch.test(selector) ? context.getElementsByClassName(selector.slice(1)) : singlet.test(selector) ? context.getElementsByTagName(selector) : context.querySelectorAll(selector));
return elems;
}
var fn = cash.fn = cash.prototype = {
cash: true,
length: 0
};
var frag, tmp;
function parseHTML(str) {
frag = frag || doc.createDocumentFragment();
tmp = tmp || frag.appendChild(doc.createElement("div"));
tmp.innerHTML = str;
return tmp.childNodes;
}
fn.init = function (selector, context) {
var result = [], matcher, elem;
function onReady(fn) {
if (doc.readyState !== "loading") {
fn();
} else {
doc.addEventListener("DOMContentLoaded", fn);
}
}
function Init(selector, context) {
if (!selector) {

@@ -33,62 +50,80 @@ return this;

this.length = 1;
// If already a cash collection, don't do any further processing
if (selector.cash && selector !== win) {
return selector;
}
if (typeof selector !== "string") {
if (selector.cash) {
return selector;
}
var elems = selector, i = 0, length;
this[0] = selector;
if (isString(selector)) {
elems = (idMatch.test(selector) ?
// If an ID use the faster getElementById check
doc.getElementById(selector.slice(1)) : htmlMatch.test(selector) ?
// If HTML, parse it into real elements
parseHTML(selector) :
// else use `find`
find(selector, context));
// If function, use as shortcut for DOM ready
} else if (isFunction(selector)) {
onReady(selector);return this;
}
if (!elems) {
return this;
}
if (selector.charAt(0) === "<" && selector.charAt(selector.length - 1) === ">" && selector.length >= 3) {
result = cash.parseHTML(selector);
// If a single DOM element is passed in or received via ID, return the single element
if (elems.nodeType || elems === win) {
this[0] = elems;
this.length = 1;
} else {
matcher = idMatch.test(selector);
elem = selector.slice(1);
if (!context && matcher) {
this[0] = doc.getElementById(elem);
return this;
} else {
context = (cash(context)[0] || doc);
result = slice.call(singlet.test(elem) ? classMatch.test(selector) ? doc.getElementsByClassName(elem) : doc.getElementsByTagName(selector) : context.querySelectorAll(selector));
// Treat like an array and loop through each item.
length = this.length = elems.length;
for (; i < length; i++) {
this[i] = elems[i];
}
}
this.length = 0;
cash.merge(this, result);
return this;
};
}
fn.init.prototype = fn;
function buildFragment(str) {
var fragment = fragment || doc.createDocumentFragment(), tmp = tmp || fragment.appendChild(doc.createElement("div"));
tmp.innerHTML = str;
return tmp;
function cash(selector, context) {
return new Init(selector, context);
}
cash.each = function (collection, callback) {
var l = collection.length, i = 0;
for (; i < l; i++) {
callback.call(collection[i], collection[i], i, collection);
}
var fn = cash.fn = cash.prototype = Init.prototype = {
constructor: cash,
cash: true,
length: 0,
push: push,
splice: ArrayProto.splice,
map: ArrayProto.map,
init: Init
};
cash.extend = fn.extend = function (target, source) {
var prop;
cash.parseHTML = parseHTML;
cash.noop = noop;
cash.isFunction = isFunction;
cash.isString = isString;
if (!source) {
source = target;
cash.extend = fn.extend = function (target) {
target = target || {};
var args = slice.call(arguments), length = args.length, i = 1;
if (args.length === 1) {
target = this;
i = 0;
}
for (prop in source) {
if (source.hasOwnProperty(prop)) {
target[prop] = source[prop];
for (; i < length; i++) {
if (!args[i]) {
continue;
}
for (var key in args[i]) {
if (args[i].hasOwnProperty(key)) {
target[key] = args[i][key];
}
}
}

@@ -99,60 +134,125 @@

cash.matches = function (el, selector) {
return (el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(el, selector);
};
function each(collection, callback) {
var l = collection.length, i = 0;
cash.merge = function (first, second) {
var len = +second.length, i = first.length, j = 0;
for (; j < len; i++, j++) {
first[i] = second[j];
for (; i < l; i++) {
if (callback.call(collection[i], collection[i], i, collection) === false) {
break;
}
}
}
first.length = i;
return first;
};
function matches(el, selector) {
return (el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector).call(el, selector);
}
cash.parseHTML = function (str) {
var parsed = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/).exec(str);
function unique(collection) {
return cash(slice.call(collection).filter(function (item, index, self) {
return self.indexOf(item) === index;
}));
}
if (parsed) {
return [doc.createElement(parsed[1])];
cash.extend({
merge: function (first, second) {
var len = +second.length, i = first.length, j = 0;
for (; j < len; i++, j++) {
first[i] = second[j];
}
first.length = i;
return first;
},
each: each,
matches: matches,
unique: unique,
isArray: Array.isArray,
isNumeric: function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
parsed = buildFragment(str);
return slice.call(parsed.childNodes);
};
});
cash.unique = function (collection) {
return cash.merge(cash(), slice.call(collection).filter(function (item, index, self) {
return self.indexOf(item) === index;
}));
};
var uid = cash.uid = "_cash" + Date.now();
var notWhiteMatch = /\S+/g;
function getDataCache(node) {
return (node[uid] = node[uid] || {});
}
function setData(node, key, value) {
return (getDataCache(node)[key] = value);
}
function getData(node, key) {
var c = getDataCache(node);
if (c[key] === undefined) {
c[key] = node.dataset ? node.dataset[key] : cash(node).attr("data-" + key);
}
return c[key];
}
function removeData(node, key) {
var c = getDataCache(node);
if (c) {
delete c[key];
} else if (node.dataset) {
delete node.dataset[key];
} else {
cash(node).removeAttr("data-" + name);
}
}
fn.extend({
addClass: function (className) {
data: function (key, value) {
// TODO: tear out into module for IE9
var classes = className.match(notWhiteMatch), spacedName, l;
if (!value) {
return getData(this[0], key);
}
return this.each(function (v) {
return setData(v, key, value);
});
},
this.each(function (v) {
l = classes.length;
removeData: function (key) {
// TODO: tear out into module for IE9
return this.each(function (v) {
return removeData(v, key);
});
}
if (v.classList) {
while (l--) {
v.classList.add(classes[l]);
}
} else {
while (l--) {
spacedName = " " + v.className + " ";
});
if (spacedName.indexOf(" " + classes[l] + " ") === -1) {
v.className += " " + classes[l];
}
}
}
var notWhiteMatch = /\S+/g;
function hasClass(v, c) {
return (v.classList ? v.classList.contains(c) : new RegExp("(^| )" + c + "( |$)", "gi").test(v.className));
}
function addClass(v, c, spacedName) {
if (v.classList) {
v.classList.add(c);
} else if (spacedName.indexOf(" " + c + " ")) {
v.className += " " + c;
}
}
function removeClass(v, c) {
if (v.classList) {
v.classList.remove(c);
} else {
v.className = v.className.replace(c, "");
}
}
fn.extend({
addClass: function (c) {
var classes = c.match(notWhiteMatch);
return this.each(function (v) {
var spacedName = " " + v.className + " ";
each(classes, function (c) {
addClass(v, c, spacedName);
});
});
return this;
},

@@ -162,106 +262,113 @@

if (!value) {
return this[0].getAttribute(name);
} else {
this.each(function (v) {
return v.setAttribute(name, value);
});
return this;
return (this[0].getAttribute ? this[0].getAttribute(name) : this[0][name]);
}
return this.each(function (v) {
if (v.setAttribute) {
v.setAttribute(name, value);
} else {
v[name] = value;
}
});
},
hasClass: function (className) {
// TODO: tear out into module for IE9
if (this[0].classList) {
return this[0].classList.contains(className);
} else {
return this[0].className.indexOf(className) !== -1;
}
hasClass: function (c) {
var check = false;
this.each(function (v) {
check = hasClass(v, c);
return !check;
});
return check;
},
prop: function (name) {
return this[0][name];
prop: function (name, value) {
if (!value) {
return this[0][name];
}
return this.each(function (v) {
v[name] = value;
});
},
removeAttr: function (name) {
this.each(function (v) {
return v.removeAttribute(name);
return this.each(function (v) {
if (v.removeAttribute) {
v.removeAttribute(name);
} else {
delete v[name];
}
});
return this;
},
removeClass: function (className) {
// TODO: tear out into module for IE9
var classes = className.match(notWhiteMatch), l, newClassName;
removeClass: function (c) {
var classes = c.match(notWhiteMatch);
this.each(function (v) {
l = classes.length;
return this.each(function (v) {
each(classes, function (c) {
removeClass(v, c);
});
});
},
if (v.classList) {
while (l--) {
v.classList.remove(classes[l]);
}
} else {
newClassName = " " + v.className + " ";
removeProp: function (name) {
return this.each(function (v) {
delete v[name];
});
},
while (l--) {
newClassName = newClassName.replace(" " + classes[l] + " ", " ");
toggleClass: function (c, state) {
if (state !== undefined) {
return this[state ? "addClass" : "removeClass"](c);
}
var classes = c.match(notWhiteMatch);
return this.each(function (v) {
var spacedName = " " + v.className + " ";
each(classes, function (c) {
if (hasClass(v, c)) {
removeClass(v, c);
} else {
addClass(v, c, spacedName);
}
v.className = newClassName.trim();
}
});
});
} });
return this;
}
});
fn.extend({
add: function () {
var arr = slice.call(this), i = 0, l;
for (l = arguments.length; i < l; i++) {
arr = arr.concat(slice.call(cash(arguments[i])));
}
return cash.unique(arr);
add: function (selector, context) {
return unique(cash.merge(this, cash(selector, context)));
},
each: function (callback) {
cash.each(this, callback);
each(this, callback);
return this;
},
eq: function (index) {
return cash(this[index]);
return cash(this.get(index));
},
filter: function (selector) {
if (typeof selector === "string") {
return filter.call(this, function (e) {
return cash.matches(e, selector);
});
} else {
return filter.call(this, selector);
}
return filter.call(this, (isString(selector) ? function (e) {
return matches(e, selector);
} : selector));
},
first: function () {
return cash(this[0]);
return this.eq(0);
},
get: function (num) {
return this[num];
get: function (index) {
if (index === undefined) {
return slice.call(this);
}
return (index < 0 ? this[index + this.length] : this[index]);
},
index: function (elem) {
if (!elem) {
return slice.call(cash(this[0]).parent().children()).indexOf(this[0]);
} else {
return slice.call(cash(elem).children()).indexOf(this[0]);
}
var f = this[0];
return slice.call(elem ? cash(elem) : cash(f).parent().children()).indexOf(f);
},
last: function () {
return cash(this[this.length - 1]);
return this.eq(-1);
}

@@ -271,92 +378,44 @@

fn.extend({
css: function (prop, value) {
if (typeof prop === "object") {
this.each(function (v) {
for (var key in prop) {
if (prop.hasOwnProperty(key)) {
v.style[key] = prop[key];
}
}
});
} else if (value) {
this.each(function (v) {
return v.style[prop] = value;
});
return this;
} else {
return win.getComputedStyle(this[0], null)[prop];
}
var getPrefixedProp = (function () {
var cache = {}, div = doc.createElement("div"), style = div.style, camelRegex = /(?:^\w|[A-Z]|\b\w)/g, whiteSpace = /\s+/g;
function camelCase(str) {
return str.replace(camelRegex, function (letter, index) {
return letter[index === 0 ? "toLowerCase" : "toUpperCase"]();
}).replace(whiteSpace, "");
}
});
return function (prop) {
prop = camelCase(prop);
if (cache[prop]) {
return cache[prop];
}
fn.extend({
data: function (key, value) {
// TODO: tear out into module for IE9
if (!value) {
return this[0].dataset ? this[0].dataset[key] : cash(this[0]).attr("data-" + key);
} else {
this.each(function (v) {
if (v.dataset) {
v.dataset[key] = value;
} else {
cash(v).attr("data-" + key, value);
}
});
var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1), prefixes = ["webkit", "moz", "ms", "o"], props = (prop + " " + (prefixes).join(ucProp + " ") + ucProp).split(" ");
return this;
}
},
removeData: function (name) {
// TODO: tear out into module for IE9
this.each(function (v) {
if (v.dataset) {
delete v.dataset[name];
} else {
cash(v).removeAttr("data-" + name);
each(props, function (p) {
if (p in style) {
cache[p] = prop = cache[prop] = p;
return false;
}
});
return this;
}
return cache[prop];
};
}());
});
function compute(el, prop) {
return parseInt(win.getComputedStyle(el[0], null)[prop], 10);
}
fn.extend({
height: function () {
return this[0].getBoundingClientRect().height;
},
innerWidth: function () {
return this[0].clientWidth;
},
innerHeight: function () {
return this[0].clientHeight;
},
outerWidth: function (margins) {
if (margins === true) {
return this[0].offsetWidth + (compute(this, "margin-left") || compute(this, "marginLeft") || 0) + (compute(this, "margin-right") || compute(this, "marginRight") || 0);
css: function (prop, value) {
if (isString(prop)) {
prop = getPrefixedProp(prop);
return (value ? this.each(function (v) {
return v.style[prop] = value;
}) : win.getComputedStyle(this[0])[prop]);
}
return this[0].offsetWidth;
},
outerHeight: function (margins) {
if (margins === true) {
return this[0].offsetHeight + (compute(this, "margin-top") || compute(this, "marginTop") || 0) + (compute(this, "margin-bottom") || compute(this, "marginBottom") || 0);
for (var key in prop) {
this.css(key, prop[key]);
}
return this[0].offsetHeight;
},
width: function () {
return this[0].getBoundingClientRect().width;
return this;
}

@@ -366,27 +425,39 @@

var _eventCache = {};
function compute(el, prop) {
return parseInt(win.getComputedStyle(el[0], null)[prop], 10) || 0;
}
function guid() {
function _p8(s) {
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
}
each(["Width", "Height"], function (v) {
var lower = v.toLowerCase();
return _p8() + _p8(true) + _p8(true) + _p8();
}
fn[lower] = function () {
return this[0].getBoundingClientRect()[lower];
};
function registerEvent(node, eventName, callback) {
var nid = cash(node).data("cshid") || guid();
fn["inner" + v] = function () {
return this[0]["client" + v];
};
cash(node).data("cshid", nid);
fn["outer" + v] = function (margins) {
return this[0]["offset" + v] + (margins ? compute(this, "margin" + (v === "Width" ? "Left" : "Top")) + compute(this, "margin" + (v === "Width" ? "Right" : "Bottom")) : 0);
};
});
if (!(nid in _eventCache)) {
_eventCache[nid] = {};
}
function registerEvent(node, eventName, callback) {
var eventCache = getData(node, "_cashEvents") || setData(node, "_cashEvents", {});
eventCache[eventName] = eventCache[eventName] || [];
eventCache[eventName].push(callback);
node.addEventListener(eventName, callback);
}
if (!(eventName in _eventCache[nid])) {
_eventCache[nid][eventName] = [];
function removeEvent(node, eventName, callback) {
var eventCache = getData(node, "_cashEvents")[eventName];
if (callback) {
node.removeEventListener(eventName, callback);
} else {
each(eventCache, function (event) {
node.removeEventListener(eventName, event);
});
eventCache = [];
}
_eventCache[nid][eventName].push(callback);
}

@@ -396,64 +467,72 @@

off: function (eventName, callback) {
this.each(function (v) {
if (callback) {
v.removeEventListener(eventName, callback);
} else {
for (var i in _eventCache[cash(v).data("cshid")][eventName]) {
v.removeEventListener(eventName, _eventCache[cash(v).data("cshid")][eventName][i]);
}
}
return this.each(function (v) {
return removeEvent(v, eventName, callback);
});
return this;
},
on: function (eventName, delegate, callback) {
if (typeof delegate === "function") {
callback = delegate;
on: function (eventName, delegate, callback, runOnce) {
var originalCallback;
this.each(function (v) {
registerEvent(cash(v), eventName, callback);
v.addEventListener(eventName, callback);
});
if (!isString(eventName)) {
for (var key in eventName) {
this.on(key, delegate, eventName[key]);
}
return this;
} else {
this.each(function (v) {
function handler(e) {
var t = e.target;
}
if (cash.matches(t, delegate)) {
callback.call(t);
} else {
while (!cash.matches(t, delegate)) {
if (t === v) {
return (t = false);
}
t = t.parentNode;
}
if (isFunction(delegate)) {
callback = delegate;
delegate = null;
}
if (t) {
callback.call(t);
if (eventName === "ready") {
onReady(callback);return this;
}
if (delegate) {
originalCallback = callback;
callback = function (e) {
var t = e.target;
if (matches(t, delegate)) {
originalCallback.call(t);
} else {
while (!matches(t, delegate)) {
if (t === this) {
return (t = false);
}
t = t.parentNode;
}
if (t) {
originalCallback.call(t);
}
}
};
}
registerEvent(cash(v), eventName, handler);
v.addEventListener(eventName, handler);
});
return this;
}
return this.each(function (v) {
var finalCallback = callback;
if (runOnce) {
finalCallback = function () {
callback.apply(this, arguments);
removeEvent(v, eventName, finalCallback);
};
}
registerEvent(v, eventName, finalCallback);
});
},
ready: function (callback) {
this[0].addEventListener("DOMContentLoaded", callback);
one: function (eventName, delegate, callback) {
return this.on(eventName, delegate, callback, true);
},
ready: onReady,
trigger: function (eventName) {
var evt = doc.createEvent("HTMLEvents");
evt.initEvent(eventName, true, false);
this.each(function (v) {
return this.each(function (v) {
return v.dispatchEvent(evt);
});
return this;
}

@@ -463,23 +542,28 @@

var encode = encodeURIComponent;
function encode(name, value) {
return "&" + encodeURIComponent(name) + "=" + encodeURIComponent(value).replace(/%20/g, "+");
}
function isCheckable(field) {
return field.type === "radio" || field.type === "checkbox";
}
var formExcludes = ["file", "reset", "submit", "button"];
fn.extend({
serialize: function () {
var form = this[0], query = "", field, i, j;
var formEl = this[0].elements, query = "";
for (i = form.elements.length - 1; i >= 0; i--) {
field = form.elements[i];
if (field.name && field.type !== "file" && field.type !== "reset") {
each(formEl, function (field) {
if (field.name && formExcludes.indexOf(field.type) < 0) {
if (field.type === "select-multiple") {
for (j = form.elements[i].options.length - 1; j >= 0; j--) {
if (field.options[j].selected) {
query += "&" + field.name + "=" + encode(field.options[j].value).replace(/%20/g, "+");
each(field.options, function (o) {
if (o.selected) {
query += encode(field.name, o.value);
}
}
} else if ((field.type !== "submit" && field.type !== "button")) {
query += "&" + field.name + "=" + encode(field.value).replace(/%20/g, "+");
});
} else if (!isCheckable(field) || (isCheckable(field) && field.checked)) {
query += encode(field.name, field.value);
}
}
}
});

@@ -493,6 +577,5 @@ return query.substr(1);

} else {
this.each(function (v) {
return this.each(function (v) {
return v.value = value;
});
return this;
}

@@ -503,21 +586,57 @@ }

function insertElement(el, child, prepend) {
if (prepend) {
var first = el.childNodes[0];
el.insertBefore(child, first);
} else {
el.appendChild(child);
}
}
function insertContent(parent, child, prepend) {
var str = isString(child);
if (!str && child.length) {
each(child, function (v) {
return insertContent(parent, v, prepend);
});
return;
}
each(parent, str ? function (v) {
return v.insertAdjacentHTML(prepend ? "afterbegin" : "beforeend", child);
} : function (v, i) {
return insertElement(v, (i === 0 ? child : child.cloneNode(true)), prepend);
});
}
fn.extend({
after: function (selector) {
cash(selector).insertAfter(this);
return this;
},
append: function (content) {
this[0].appendChild(cash(content)[0]);
insertContent(this, content);
return this;
},
appendTo: function (content) {
cash(content)[0].appendChild(this[0]);
appendTo: function (parent) {
insertContent(cash(parent), this);
return this;
},
before: function (selector) {
cash(selector).insertBefore(this);
return this;
},
clone: function () {
return cash(this[0].cloneNode(true));
return cash(this.map(function (v) {
return v.cloneNode(true);
}));
},
empty: function () {
this.each(function (v) {
return v.innerHTML = "";
});
this.html("");
return this;

@@ -527,17 +646,22 @@ },

html: function (content) {
var source;
if (content === "undefined") {
if (content === undefined) {
return this[0].innerHTML;
} else {
source = typeof content === "object" ? cash(content)[0].outerHTML : content;
this.each(function (v) {
return v.innerHTML = "" + source;
});
return this;
}
var source = (content.nodeType ? content[0].outerHTML : content);
return this.each(function (v) {
return v.innerHTML = source;
});
},
insertAfter: function (selector) {
cash(selector)[0].insertAdjacentHTML("afterend", this[0].outerHTML);
var _this = this;
cash(selector).each(function (el, i) {
var parent = el.parentNode, sibling = el.nextSibling;
_this.each(function (v) {
parent.insertBefore((i === 0 ? v : v.cloneNode(true)), sibling);
});
});
return this;

@@ -547,13 +671,19 @@ },

insertBefore: function (selector) {
cash(selector)[0].insertAdjacentHTML("beforebegin", this[0].outerHTML);
var _this2 = this;
cash(selector).each(function (el, i) {
var parent = el.parentNode;
_this2.each(function (v) {
parent.insertBefore((i === 0 ? v : v.cloneNode(true)), el);
});
});
return this;
},
prepend: function (selector) {
cash(this)[0].insertAdjacentHTML("afterBegin", cash(selector)[0].outerHTML);
prepend: function (content) {
insertContent(this, content, true);
return this;
},
prependTo: function (selector) {
cash(selector)[0].insertAdjacentHTML("afterBegin", this[0].outerHTML);
prependTo: function (parent) {
insertContent(cash(parent), this, true);
return this;

@@ -563,3 +693,3 @@ },

remove: function () {
this.each(function (v) {
return this.each(function (v) {
return v.parentNode.removeChild(v);

@@ -572,8 +702,6 @@ });

return this[0].textContent;
} else {
this.each(function (v) {
return v.textContent = content;
});
return this;
}
return this.each(function (v) {
return v.textContent = content;
});
}

@@ -583,19 +711,49 @@

var docEl = doc.documentElement;
fn.extend({
position: function () {
var el = this[0];
return {
left: el.offsetLeft,
top: el.offsetTop
};
},
offset: function () {
var rect = this[0].getBoundingClientRect();
return {
top: rect.top + win.pageYOffset - docEl.clientTop,
left: rect.left + win.pageXOffset - docEl.clientLeft
};
},
offsetParent: function () {
return cash(this[0].offsetParent);
}
});
function directCompare(el, selector) {
return el === selector;
}
fn.extend({
children: function (selector) {
if (!selector) {
return cash.fn.extend(this[0].children, cash.fn);
} else {
return cash(this[0].children).filter(function (v) {
return cash.matches(v, selector);
});
}
var elems = [];
this.each(function (el) {
push.apply(elems, el.children);
});
elems = unique(elems);
return (!selector ? elems : elems.filter(function (v) {
return matches(v, selector);
}));
},
closest: function (selector) {
if (!selector || cash.matches(this[0], selector)) {
if (!selector || matches(this[0], selector)) {
return this;
} else {
return this.parent().closest(selector);
}
return this.parent().closest(selector);
},

@@ -608,11 +766,25 @@

if (selector.cash) {
return this[0] === selector[0];
}
var match = false, comparator = (isString(selector) ? matches : selector.cash ? function (el) {
return selector.is(el);
} : directCompare);
return typeof selector === "string" ? cash.matches(this[0], selector) : false;
this.each(function (el, i) {
match = comparator(el, selector, i);
return !match;
});
return match;
},
find: function (selector) {
return cash.fn.extend(this[0].querySelectorAll(selector), cash.fn);
if (!selector) {
return cash();
}
var elems = [];
this.each(function (el) {
push.apply(elems, find(selector, el));
});
return unique(elems);
},

@@ -632,3 +804,3 @@

return filter.call(this, function (el) {
return !cash.matches(el, selector);
return !matches(el, selector);
});

@@ -638,11 +810,11 @@ },

parent: function () {
var result = ArrayProto.map.call(this, function (item) {
var result = this.map(function (item) {
return item.parentElement || doc.body.parentNode;
});
return cash.unique(result);
return unique(result);
},
parents: function (selector) {
var last, result = [], count = 0;
var last, result = [];

@@ -655,5 +827,4 @@ this.each(function (item) {

if (!selector || (selector && cash.matches(last, selector))) {
result[count] = last;
count++;
if (!selector || (selector && matches(last, selector))) {
result.push(last);
}

@@ -663,3 +834,3 @@ }

return cash.unique(result);
return unique(result);
},

@@ -681,3 +852,4 @@

return cash;
});

@@ -1,1 +0,1 @@

"use strict";!function(t,e){"function"==typeof define&&define.amd?define(e):"undefined"!=typeof exports?module.exports=e():t.cash=t.$=e()}(this,function(){function t(e,n){return new t.fn.init(e,n)}function e(t){var e=e||s.createDocumentFragment(),n=n||e.appendChild(s.createElement("div"));return n.innerHTML=t,n}function n(t,e){return parseInt(u.getComputedStyle(t[0],null)[e],10)}function i(){function t(t){var e=(Math.random().toString(16)+"000000000").substr(2,8);return t?"-"+e.substr(0,4)+"-"+e.substr(4,4):e}return t()+t(!0)+t(!0)+t()}function r(e,n,r){var s=t(e).data("cshid")||i();t(e).data("cshid",s),s in p||(p[s]={}),n in p[s]||(p[s][n]=[]),p[s][n].push(r)}var s=document,u=window,c=Array.prototype,a=c.slice,h=c.filter,o=/^#[\w-]*$/,f=/^\.[\w-]*$/,l=/^[\w-]*$/,d=t.fn=t.prototype={cash:!0,length:0};d.init=function(e,n){var i,r,u=[];if(!e)return this;if(this.length=1,"string"!=typeof e)return e.cash?e:(this[0]=e,this);if("<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3)u=t.parseHTML(e);else{if(i=o.test(e),r=e.slice(1),!n&&i)return this[0]=s.getElementById(r),this;n=t(n)[0]||s,u=a.call(l.test(r)?f.test(e)?s.getElementsByClassName(r):s.getElementsByTagName(e):n.querySelectorAll(e))}return this.length=0,t.merge(this,u),this},d.init.prototype=d,t.each=function(t,e){for(var n=t.length,i=0;n>i;i++)e.call(t[i],t[i],i,t)},t.extend=d.extend=function(t,e){var n;e||(e=t,t=this);for(n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t},t.matches=function(t,e){return(t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector).call(t,e)},t.merge=function(t,e){for(var n=+e.length,i=t.length,r=0;n>r;i++,r++)t[i]=e[r];return t.length=i,t},t.parseHTML=function(t){var n=/^<(\w+)\s*\/?>(?:<\/\1>|)$/.exec(t);return n?[s.createElement(n[1])]:(n=e(t),a.call(n.childNodes))},t.unique=function(e){return t.merge(t(),a.call(e).filter(function(t,e,n){return n.indexOf(t)===e}))};var m=/\S+/g;d.extend({addClass:function(t){var e,n,i=t.match(m);return this.each(function(t){if(n=i.length,t.classList)for(;n--;)t.classList.add(i[n]);else for(;n--;)e=" "+t.className+" ",-1===e.indexOf(" "+i[n]+" ")&&(t.className+=" "+i[n])}),this},attr:function(t,e){return e?(this.each(function(n){return n.setAttribute(t,e)}),this):this[0].getAttribute(t)},hasClass:function(t){return this[0].classList?this[0].classList.contains(t):-1!==this[0].className.indexOf(t)},prop:function(t){return this[0][t]},removeAttr:function(t){return this.each(function(e){return e.removeAttribute(t)}),this},removeClass:function(t){var e,n,i=t.match(m);return this.each(function(t){if(e=i.length,t.classList)for(;e--;)t.classList.remove(i[e]);else{for(n=" "+t.className+" ";e--;)n=n.replace(" "+i[e]+" "," ");t.className=n.trim()}}),this}}),d.extend({add:function(){var e,n=a.call(this),i=0;for(e=arguments.length;e>i;i++)n=n.concat(a.call(t(arguments[i])));return t.unique(n)},each:function(e){t.each(this,e)},eq:function(e){return t(this[e])},filter:function(e){return"string"==typeof e?h.call(this,function(n){return t.matches(n,e)}):h.call(this,e)},first:function(){return t(this[0])},get:function(t){return this[t]},index:function(e){return e?a.call(t(e).children()).indexOf(this[0]):a.call(t(this[0]).parent().children()).indexOf(this[0])},last:function(){return t(this[this.length-1])}}),d.extend({css:function(t,e){return"object"!=typeof t?e?(this.each(function(n){return n.style[t]=e}),this):u.getComputedStyle(this[0],null)[t]:void this.each(function(e){for(var n in t)t.hasOwnProperty(n)&&(e.style[n]=t[n])})}}),d.extend({data:function(e,n){return n?(this.each(function(i){i.dataset?i.dataset[e]=n:t(i).attr("data-"+e,n)}),this):this[0].dataset?this[0].dataset[e]:t(this[0]).attr("data-"+e)},removeData:function(e){return this.each(function(n){n.dataset?delete n.dataset[e]:t(n).removeAttr("data-"+e)}),this}}),d.extend({height:function(){return this[0].getBoundingClientRect().height},innerWidth:function(){return this[0].clientWidth},innerHeight:function(){return this[0].clientHeight},outerWidth:function(t){return t===!0?this[0].offsetWidth+(n(this,"margin-left")||n(this,"marginLeft")||0)+(n(this,"margin-right")||n(this,"marginRight")||0):this[0].offsetWidth},outerHeight:function(t){return t===!0?this[0].offsetHeight+(n(this,"margin-top")||n(this,"marginTop")||0)+(n(this,"margin-bottom")||n(this,"marginBottom")||0):this[0].offsetHeight},width:function(){return this[0].getBoundingClientRect().width}});var p={};d.extend({off:function(e,n){return this.each(function(i){if(n)i.removeEventListener(e,n);else for(var r in p[t(i).data("cshid")][e])i.removeEventListener(e,p[t(i).data("cshid")][e][r])}),this},on:function(e,n,i){return"function"==typeof n?(i=n,this.each(function(n){r(t(n),e,i),n.addEventListener(e,i)}),this):(this.each(function(s){function u(e){var r=e.target;if(t.matches(r,n))i.call(r);else{for(;!t.matches(r,n);){if(r===s)return r=!1;r=r.parentNode}r&&i.call(r)}}r(t(s),e,u),s.addEventListener(e,u)}),this)},ready:function(t){this[0].addEventListener("DOMContentLoaded",t)},trigger:function(t){var e=s.createEvent("HTMLEvents");return e.initEvent(t,!0,!1),this.each(function(t){return t.dispatchEvent(e)}),this}});var g=encodeURIComponent;return d.extend({serialize:function(){var t,e,n,i=this[0],r="";for(e=i.elements.length-1;e>=0;e--)if(t=i.elements[e],t.name&&"file"!==t.type&&"reset"!==t.type)if("select-multiple"===t.type)for(n=i.elements[e].options.length-1;n>=0;n--)t.options[n].selected&&(r+="&"+t.name+"="+g(t.options[n].value).replace(/%20/g,"+"));else"submit"!==t.type&&"button"!==t.type&&(r+="&"+t.name+"="+g(t.value).replace(/%20/g,"+"));return r.substr(1)},val:function(t){return void 0===t?this[0].value:(this.each(function(e){return e.value=t}),this)}}),d.extend({append:function(e){return this[0].appendChild(t(e)[0]),this},appendTo:function(e){return t(e)[0].appendChild(this[0]),this},clone:function(){return t(this[0].cloneNode(!0))},empty:function(){return this.each(function(t){return t.innerHTML=""}),this},html:function(e){var n;return"undefined"===e?this[0].innerHTML:(n="object"==typeof e?t(e)[0].outerHTML:e,this.each(function(t){return t.innerHTML=""+n}),this)},insertAfter:function(e){return t(e)[0].insertAdjacentHTML("afterend",this[0].outerHTML),this},insertBefore:function(e){return t(e)[0].insertAdjacentHTML("beforebegin",this[0].outerHTML),this},prepend:function(e){return t(this)[0].insertAdjacentHTML("afterBegin",t(e)[0].outerHTML),this},prependTo:function(e){return t(e)[0].insertAdjacentHTML("afterBegin",this[0].outerHTML),this},remove:function(){this.each(function(t){return t.parentNode.removeChild(t)})},text:function(t){return t?(this.each(function(e){return e.textContent=t}),this):this[0].textContent}}),d.extend({children:function(e){return e?t(this[0].children).filter(function(n){return t.matches(n,e)}):t.fn.extend(this[0].children,t.fn)},closest:function(e){return!e||t.matches(this[0],e)?this:this.parent().closest(e)},is:function(e){return e?e.cash?this[0]===e[0]:"string"==typeof e?t.matches(this[0],e):!1:!1},find:function(e){return t.fn.extend(this[0].querySelectorAll(e),t.fn)},has:function(e){return h.call(this,function(n){return 0!==t(n).find(e).length})},next:function(){return t(this[0].nextElementSibling)},not:function(e){return h.call(this,function(n){return!t.matches(n,e)})},parent:function(){var e=c.map.call(this,function(t){return t.parentElement||s.body.parentNode});return t.unique(e)},parents:function(e){var n,i=[],r=0;return this.each(function(u){for(n=u;n!==s.body.parentNode;)n=n.parentElement,(!e||e&&t.matches(n,e))&&(i[r]=n,r++)}),t.unique(i)},prev:function(){return t(this[0].previousElementSibling)},siblings:function(){var t=this.parent().children(),e=this[0];return h.call(t,function(t){return t!==e})}}),t});
"use strict";!function(t,n){"function"==typeof define&&define.amd?define(n):"undefined"!=typeof exports?module.exports=n():t.cash=t.$=n()}(this,function(){function t(t,n){n=n||A;var e=$.test(t)?n.getElementsByClassName(t.slice(1)):D.test(t)?n.getElementsByTagName(t):n.querySelectorAll(t);return e}function n(t){return b=b||A.createDocumentFragment(),E=E||b.appendChild(A.createElement("div")),E.innerHTML=t,E.childNodes}function e(t){"loading"!==A.readyState?t():A.addEventListener("DOMContentLoaded",t)}function r(r,i){if(!r)return this;if(r.cash&&r!==w)return r;var u,o=r,s=0;if(R(r))o=q.test(r)?A.getElementById(r.slice(1)):k.test(r)?n(r):t(r,i);else if(O(r))return e(r),this;if(!o)return this;if(o.nodeType||o===w)this[0]=o,this.length=1;else for(u=this.length=o.length;u>s;s++)this[s]=o[s];return this}function i(t,n){return new r(t,n)}function u(t,n){for(var e=t.length,r=0;e>r&&n.call(t[r],t[r],r,t)!==!1;r++);}function o(t,n){return(t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector).call(t,n)}function s(t){return i(S.call(t).filter(function(t,n,e){return e.indexOf(t)===n}))}function c(t){return t[I]=t[I]||{}}function a(t,n,e){return c(t)[n]=e}function f(t,n){var e=c(t);return void 0===e[n]&&(e[n]=t.dataset?t.dataset[n]:i(t).attr("data-"+n)),e[n]}function h(t,n){var e=c(t);e?delete e[n]:t.dataset?delete t.dataset[n]:i(t).removeAttr("data-"+name)}function l(t,n){return t.classList?t.classList.contains(n):new RegExp("(^| )"+n+"( |$)","gi").test(t.className)}function d(t,n,e){t.classList?t.classList.add(n):e.indexOf(" "+n+" ")&&(t.className+=" "+n)}function p(t,n){t.classList?t.classList.remove(n):t.className=t.className.replace(n,"")}function v(t,n){return parseInt(w.getComputedStyle(t[0],null)[n],10)||0}function m(t,n,e){var r=f(t,"_cashEvents")||a(t,"_cashEvents",{});r[n]=r[n]||[],r[n].push(e),t.addEventListener(n,e)}function g(t,n,e){var r=f(t,"_cashEvents")[n];e?t.removeEventListener(n,e):(u(r,function(e){t.removeEventListener(n,e)}),r=[])}function y(t,n){return"&"+encodeURIComponent(t)+"="+encodeURIComponent(n).replace(/%20/g,"+")}function x(t){return"radio"===t.type||"checkbox"===t.type}function C(t,n,e){if(e){var r=t.childNodes[0];t.insertBefore(n,r)}else t.appendChild(n)}function L(t,n,e){var r=R(n);return!r&&n.length?void u(n,function(n){return L(t,n,e)}):void u(t,r?function(t){return t.insertAdjacentHTML(e?"afterbegin":"beforeend",n)}:function(t,r){return C(t,0===r?n:n.cloneNode(!0),e)})}function N(t,n){return t===n}var b,E,A=document,w=window,T=Array.prototype,S=T.slice,M=T.filter,B=T.push,H=function(){},O=function(t){return typeof t==typeof H},R=function(t){return"string"==typeof t},q=/^#[\w-]*$/,$=/^\.[\w-]*$/,k=/<.+>/,D=/^\w+$/,F=i.fn=i.prototype=r.prototype={constructor:i,cash:!0,length:0,push:B,splice:T.splice,map:T.map,init:r};i.parseHTML=n,i.noop=H,i.isFunction=O,i.isString=R,i.extend=F.extend=function(t){t=t||{};var n=S.call(arguments),e=n.length,r=1;for(1===n.length&&(t=this,r=0);e>r;r++)if(n[r])for(var i in n[r])n[r].hasOwnProperty(i)&&(t[i]=n[r][i]);return t},i.extend({merge:function(t,n){for(var e=+n.length,r=t.length,i=0;e>i;r++,i++)t[r]=n[i];return t.length=r,t},each:u,matches:o,unique:s,isArray:Array.isArray,isNumeric:function(t){return!isNaN(parseFloat(t))&&isFinite(t)}});var I=i.uid="_cash"+Date.now();F.extend({data:function(t,n){return n?this.each(function(e){return a(e,t,n)}):f(this[0],t)},removeData:function(t){return this.each(function(n){return h(n,t)})}});var P=/\S+/g;F.extend({addClass:function(t){var n=t.match(P);return this.each(function(t){var e=" "+t.className+" ";u(n,function(n){d(t,n,e)})})},attr:function(t,n){return n?this.each(function(e){e.setAttribute?e.setAttribute(t,n):e[t]=n}):this[0].getAttribute?this[0].getAttribute(t):this[0][t]},hasClass:function(t){var n=!1;return this.each(function(e){return n=l(e,t),!n}),n},prop:function(t,n){return n?this.each(function(e){e[t]=n}):this[0][t]},removeAttr:function(t){return this.each(function(n){n.removeAttribute?n.removeAttribute(t):delete n[t]})},removeClass:function(t){var n=t.match(P);return this.each(function(t){u(n,function(n){p(t,n)})})},removeProp:function(t){return this.each(function(n){delete n[t]})},toggleClass:function(t,n){if(void 0!==n)return this[n?"addClass":"removeClass"](t);var e=t.match(P);return this.each(function(t){var n=" "+t.className+" ";u(e,function(e){l(t,e)?p(t,e):d(t,e,n)})})}}),F.extend({add:function(t,n){return s(i.merge(this,i(t,n)))},each:function(t){return u(this,t),this},eq:function(t){return i(this.get(t))},filter:function(t){return M.call(this,R(t)?function(n){return o(n,t)}:t)},first:function(){return this.eq(0)},get:function(t){return void 0===t?S.call(this):0>t?this[t+this.length]:this[t]},index:function(t){var n=this[0];return S.call(t?i(t):i(n).parent().children()).indexOf(n)},last:function(){return this.eq(-1)}});var U=function(){function t(t){return t.replace(i,function(t,n){return t[0===n?"toLowerCase":"toUpperCase"]()}).replace(o,"")}var n={},e=A.createElement("div"),r=e.style,i=/(?:^\w|[A-Z]|\b\w)/g,o=/\s+/g;return function(e){if(e=t(e),n[e])return n[e];var i=e.charAt(0).toUpperCase()+e.slice(1),o=["webkit","moz","ms","o"],s=(e+" "+o.join(i+" ")+i).split(" ");return u(s,function(t){return t in r?(n[t]=e=n[e]=t,!1):void 0}),n[e]}}();F.extend({css:function(t,n){if(R(t))return t=U(t),n?this.each(function(e){return e.style[t]=n}):w.getComputedStyle(this[0])[t];for(var e in t)this.css(e,t[e]);return this}}),u(["Width","Height"],function(t){var n=t.toLowerCase();F[n]=function(){return this[0].getBoundingClientRect()[n]},F["inner"+t]=function(){return this[0]["client"+t]},F["outer"+t]=function(n){return this[0]["offset"+t]+(n?v(this,"margin"+("Width"===t?"Left":"Top"))+v(this,"margin"+("Width"===t?"Right":"Bottom")):0)}}),F.extend({off:function(t,n){return this.each(function(e){return g(e,t,n)})},on:function(t,n,r,i){var u;if(!R(t)){for(var s in t)this.on(s,n,t[s]);return this}return O(n)&&(r=n,n=null),"ready"===t?(e(r),this):(n&&(u=r,r=function(t){var e=t.target;if(o(e,n))u.call(e);else{for(;!o(e,n);){if(e===this)return e=!1;e=e.parentNode}e&&u.call(e)}}),this.each(function(n){var e=r;i&&(e=function(){r.apply(this,arguments),g(n,t,e)}),m(n,t,e)}))},one:function(t,n,e){return this.on(t,n,e,!0)},ready:e,trigger:function(t){var n=A.createEvent("HTMLEvents");return n.initEvent(t,!0,!1),this.each(function(t){return t.dispatchEvent(n)})}});var _=["file","reset","submit","button"];F.extend({serialize:function(){var t=this[0].elements,n="";return u(t,function(t){t.name&&_.indexOf(t.type)<0&&("select-multiple"===t.type?u(t.options,function(e){e.selected&&(n+=y(t.name,e.value))}):(!x(t)||x(t)&&t.checked)&&(n+=y(t.name,t.value)))}),n.substr(1)},val:function(t){return void 0===t?this[0].value:this.each(function(n){return n.value=t})}}),F.extend({after:function(t){return i(t).insertAfter(this),this},append:function(t){return L(this,t),this},appendTo:function(t){return L(i(t),this),this},before:function(t){return i(t).insertBefore(this),this},clone:function(){return i(this.map(function(t){return t.cloneNode(!0)}))},empty:function(){return this.html(""),this},html:function(t){if(void 0===t)return this[0].innerHTML;var n=t.nodeType?t[0].outerHTML:t;return this.each(function(t){return t.innerHTML=n})},insertAfter:function(t){var n=this;return i(t).each(function(t,e){var r=t.parentNode,i=t.nextSibling;n.each(function(t){r.insertBefore(0===e?t:t.cloneNode(!0),i)})}),this},insertBefore:function(t){var n=this;return i(t).each(function(t,e){var r=t.parentNode;n.each(function(n){r.insertBefore(0===e?n:n.cloneNode(!0),t)})}),this},prepend:function(t){return L(this,t,!0),this},prependTo:function(t){return L(i(t),this,!0),this},remove:function(){return this.each(function(t){return t.parentNode.removeChild(t)})},text:function(t){return t?this.each(function(n){return n.textContent=t}):this[0].textContent}});var z=A.documentElement;return F.extend({position:function(){var t=this[0];return{left:t.offsetLeft,top:t.offsetTop}},offset:function(){var t=this[0].getBoundingClientRect();return{top:t.top+w.pageYOffset-z.clientTop,left:t.left+w.pageXOffset-z.clientLeft}},offsetParent:function(){return i(this[0].offsetParent)}}),F.extend({children:function(t){var n=[];return this.each(function(t){B.apply(n,t.children)}),n=s(n),t?n.filter(function(n){return o(n,t)}):n},closest:function(t){return!t||o(this[0],t)?this:this.parent().closest(t)},is:function(t){if(!t)return!1;var n=!1,e=R(t)?o:t.cash?function(n){return t.is(n)}:N;return this.each(function(r,i){return n=e(r,t,i),!n}),n},find:function(n){if(!n)return i();var e=[];return this.each(function(r){B.apply(e,t(n,r))}),s(e)},has:function(t){return M.call(this,function(n){return 0!==i(n).find(t).length})},next:function(){return i(this[0].nextElementSibling)},not:function(t){return M.call(this,function(n){return!o(n,t)})},parent:function(){var t=this.map(function(t){return t.parentElement||A.body.parentNode});return s(t)},parents:function(t){var n,e=[];return this.each(function(r){for(n=r;n!==A.body.parentNode;)n=n.parentElement,(!t||t&&o(n,t))&&e.push(n)}),s(e)},prev:function(){return i(this[0].previousElementSibling)},siblings:function(){var t=this.parent().children(),n=this[0];return M.call(t,function(t){return t!==n})}}),i});

@@ -29,6 +29,11 @@ 'use strict';

gulp.task('test', function() {
return gulp.src('./test/index.html')
.pipe($.qunit());
});
gulp.task('default', ['build', 'minify', 'lint']);
gulp.task('watch', function() {
gulp.watch(['src/*.js', 'test/src/*.js'], ['build', 'minify', 'lint']);
gulp.watch(['src/*.js', 'test/src/*.js'], ['default']);
});
{
"name": "cash-dom",
"version": "1.0.0",
"version": "1.2.0",
"description": "An absurdly small jQuery alternative for modern browsers.",

@@ -24,13 +24,12 @@ "main": "./dist/cash.js",

"gulp-6to5": "^1.0.2",
"gulp-connect": "~1.0.0",
"gulp-jshint": "~1.8.4",
"gulp-load-plugins": "~0.3.0",
"gulp-preprocess": "^1.1.1",
"gulp-qunit": "^1.4.0",
"gulp-rename": "^1.2.0",
"gulp-size": "~0.1.2",
"gulp-uglify": "~1.0.1",
"gulp-util": "~2.2.9",
"gulp-wrap": "~0.3.0"
"gulp-util": "~2.2.9"
},
"dependencies": {}
}

@@ -1,16 +0,4 @@

Cash
====
#Cash
*An absurdly small jQuery alternative for modern browsers*
An absurdly small jQuery alternative for modern browsers
## Usage
Add cash to your project via the jsDelivr CDN:
```html
<script type="text/javascript" src="//cdn.jsdelivr.net/cash/0.0.3/cash.min.js"></script>
```
### What is Cash?
Cash is a small library for modern browsers that provides jQuery style syntax

@@ -22,52 +10,47 @@ to wrap modern Vanilla JS features. It allows developers to use the jQuery

## Documentation
---
### $()
## Usage
This is the main selector method for cash. It returns an actionable collection
of nodes.
Add cash to your project via the jsDelivr CDN, and use cash to manipulate the DOM!
```js
$(selector,[context]) // => collection
$(collection) // => self
$(DOM elements) // => collection
$(HTML) // => collection
```
```html
<script src="https://cdn.jsdelivr.net/cash/1.0.0/cash.min.js"></script>
<script>
$(function(){
### $.each
$('html').addClass('dom-loaded');
Iterates through a collection and calls the callback method on each.
$('<footer>Appended with cash</footer>').appendTo(document.body);
```js
$.each(collection, callback) // => collection
});
</script>
```
### $.extend
---
Extends target object with properties from the source object.
## Documentation
```js
$.extend(target,source) // => object
```
#### $()
### $.matches
This is the main selector method for cash. It returns an actionable collection
of nodes. If a function is provided, the function will be run once the DOM is ready.
Checks a selector against an element, returning a boolean value for match.
```js
$.matches(element, selector) // => boolean
$(selector,[context]) // => collection
$(node) // => collection
$(nodeList) // => collection
$(htmlString) // => collection
$(collection) // => self
$(function) // => document ready callback
```
### $.parseHTML
----
Returns a collection from an HTML string.
## Collection Methods
```js
$.parseHTML(htmlString) // => Collection
```
#### $.fn
### $.fn
The main prototype. Adding properties and methods will add it to all collections.
The main prototype. Adding properties and methods will add it to all collections
```js

@@ -77,6 +60,5 @@ $.fn // => cash.prototype

### $.fn.add
#### $.fn.add()
Returns a new collection with the element added to the end, will accept any
amount of arguments and add them all in sequence.
Returns a new collection with the element(s) added to the end.

@@ -86,5 +68,6 @@ ```js

$(element).add(selector) // => collection
$(element).add(collection) // => collection
```
### $.fn.addClass
#### $.fn.addClass()

@@ -97,13 +80,22 @@ Adds the className argument to collection elements.

### $.fn.append
#### $.fn.after()
Appends the target element to the first element in the collection.
Inserts content or elements after the collection.
```js
$(element).after(element) // => collection
$(element).after(htmlString) // => collection
```
#### $.fn.append()
Appends the target element to the each element in the collection.
```js
$(element).append(element) // => collection
```
### $.fn.appendTo
#### $.fn.appendTo()
Adds the first element in a collection to the target element.
Adds the elements in a collection to the target element(s).

@@ -114,3 +106,3 @@ ```js

### $.fn.attr
#### $.fn.attr()

@@ -126,4 +118,13 @@ Without attrValue, returns the attribute value of the first element in the

### $.fn.children
#### $.fn.before()
Inserts content or elements before the collection.
```js
$(element).before(element) // => collection
$(element).before(htmlString) // => collection
```
#### $.fn.children()
Without a selector specified, returns a collection of child elements. With a

@@ -137,3 +138,3 @@ selector, returns child elements that match the selector.

### $.fn.closest
#### $.fn.closest()

@@ -147,3 +148,3 @@ Returns the closest matching selector up the DOM tree.

### $.fn.clone
#### $.fn.clone()

@@ -156,7 +157,7 @@ Returns a clone of the collection.

### $.fn.css
#### $.fn.css()
Returns a CSS property value when just property is supplied. Sets a CSS property
when property and value are supplied, and set multiple properties when an object
is supplied.
is supplied. Properties will be autoprefixed if needed for the user's browser.

@@ -169,6 +170,6 @@ ```js

### $.fn.data
#### $.fn.data()
Returns data attribute value when key is supplied. Sets data attribute value
when both key and value are supplied.
Link some data (string, object, array, etc.) to an element when both key and value are supplied.
If only a key is supplied, returns the linked data and falls back to data attribute value if no data is already linked.

@@ -180,3 +181,3 @@ ```js

### $.fn.each
#### $.fn.each()

@@ -189,3 +190,3 @@ Iterates over a collection with callback(value, index, array).

### $.fn.empty
#### $.fn.empty()

@@ -198,3 +199,3 @@ Empties an elements interior markup.

### $.fn.eq
#### $.fn.eq()

@@ -207,4 +208,12 @@ Returns a collection with the element at index.

### $.fn.filter
#### $.fn.extend()
Adds properties to the cash collection prototype.
```js
$.fn.extend(source) // => object
```
#### $.fn.filter()
Returns the collection that results from applying the filter method.

@@ -216,3 +225,3 @@

### $.fn.find
#### $.fn.find()

@@ -225,3 +234,3 @@ Returns selector match descendants from the first element in the collection.

### $.fn.first
#### $.fn.first()

@@ -234,3 +243,3 @@ Returns the first element in the collection.

### $.fn.get
#### $.fn.get()

@@ -243,3 +252,3 @@ Returns the element at the index.

### $.fn.has
#### $.fn.has()

@@ -252,3 +261,3 @@ Returns boolean result of the selector argument against the collection.

### $.fn.hasClass
#### $.fn.hasClass()

@@ -262,3 +271,3 @@ Returns the boolean result of checking if the first element in the collection

### $.fn.height
#### $.fn.height()

@@ -271,3 +280,3 @@ Returns the height of the element.

### $.fn.html
#### $.fn.html()

@@ -282,3 +291,3 @@ Returns the HTML text of the first element in the collection, sets the HTML if

### $.fn.index
#### $.fn.index()

@@ -293,3 +302,3 @@ Returns the index of the element in its parent if an element or selector isn't

### $.fn.innerHeight
#### $.fn.innerHeight()

@@ -302,3 +311,3 @@ Returns the height of the element + padding.

### $.fn.innerWidth
#### $.fn.innerWidth()

@@ -311,6 +320,7 @@ Returns the width of the element + padding.

### $.fn.insertAfter
#### $.fn.insertAfter()
Inserts collection after specified element.
```js

@@ -320,3 +330,3 @@ $(element).insertAfter(element) // => collection

### $.fn.insertBefore
#### $.fn.insertBefore()

@@ -329,5 +339,5 @@ Inserts collection before specified element.

### $.fn.is
#### $.fn.is()
Returns whether the provided selector matches the first element in the collection.
Returns whether the provided selector, element or collection matches any element in the collection.

@@ -338,3 +348,3 @@ ```js

### $.fn.last
#### $.fn.last()

@@ -347,3 +357,3 @@ Returns last element in the collection.

### $.fn.next
#### $.fn.next()

@@ -356,3 +366,3 @@ Returns next sibling.

### $.fn.not
#### $.fn.not()

@@ -365,5 +375,5 @@ Filters collection by false match on selector.

### $.fn.off
#### $.fn.off()
Removes event listener from collection elments.
Removes event listener from collection elements.

@@ -374,5 +384,5 @@ ```js

### $.fn.on
#### $.fn.on()
Adds event listener to collection elments. Event is delegated if delegate is
Adds event listener to collection elements. Event is delegated if delegate is
supplied.

@@ -385,4 +395,14 @@

### $.fn.outerHeight
#### $.fn.one()
Adds event listener to collection elements that only triggers once for each element.
Event is delegated if delegate is supplied.
```js
$(element).one(eventName, eventHandler) // => collection
$(element).one(eventName, delegate, eventHandler) // => collection
```
#### $.fn.outerHeight()
Returns the outer height of the element. Includes margins if margin is set to true.

@@ -395,3 +415,3 @@

### $.fn.outerWidth
#### $.fn.outerWidth()

@@ -405,3 +425,3 @@ Returns the outer width of the element. Includes margins if margin is set to true.

### $.fn.parent
#### $.fn.parent()

@@ -414,3 +434,3 @@ Returns parent element.

### $.fn.parents
#### $.fn.parents()

@@ -424,5 +444,5 @@ Returns collection of elements who are parents of element. Optionally filtering by selector.

### $.fn.prepend
#### $.fn.prepend()
Prepends element to the first element in collection.
Prepends element to the each element in collection.

@@ -433,5 +453,5 @@ ```js

### $.fn.prependTo
#### $.fn.prependTo()
Prepends first element in collection to the element.
Prepends elements in a collection to the target element(s).

@@ -442,3 +462,3 @@ ```js

### $.fn.prev
#### $.fn.prev()

@@ -451,12 +471,4 @@ Returns the previous adjacent element.

### $.fn.prepend
#### $.fn.prop()
Prepends element to the first element in collection.
```js
$(element).prepend(element) // => collection
```
### $.fn.prop
Returns property value.

@@ -468,3 +480,3 @@

### $.fn.ready
#### $.fn.ready()

@@ -477,3 +489,3 @@ Calls callback method on DOMContentLoaded.

### $.fn.remove
#### $.fn.remove()

@@ -486,3 +498,3 @@ Removes collection elements from the DOM.

### $.fn.removeAttr
#### $.fn.removeAttr()

@@ -495,5 +507,6 @@ Removes attribute from collection elements.

### $.fn.removeClass
#### $.fn.removeClass()
Removes className from collection elements. Accepts space-separated classNames for removing multiple classes.
Removes className from collection elements. Accepts space-separated classNames
for removing multiple classes.

@@ -504,5 +517,5 @@ ```js

### $.fn.removeData
#### $.fn.removeData()
Removes data attribute from collection elements.
Removes linked data and data-attributes from collection elements.

@@ -513,3 +526,3 @@ ```js

### $.fn.serialize
#### $.fn.serialize

@@ -522,3 +535,3 @@ When called on a form, serializes and returns form data.

### $.fn.siblings
#### $.fn.siblings

@@ -531,3 +544,3 @@ Returns a collection of sibling elements.

### $.fn.text
#### $.fn.text

@@ -542,4 +555,15 @@ Returns the inner text of the first element in the collection, sets the text if

### $.fn.trigger
#### $.fn.toggleClass
Adds or removes className from collection elements based on if the element already has the class.
Accepts space-separated classNames for toggling multiple classes, and an optional `force` boolean
to ensure classes are added (`true`) or removed (`false`).
```js
$(element).toggleClass(className) // => collection
$(element).toggleClass(className,force) // => collection
```
#### $.fn.trigger
Triggers supplied event on elements in collection.

@@ -551,3 +575,3 @@

### $.fn.val
#### $.fn.val

@@ -562,3 +586,3 @@ Returns an inputs value. If value is supplied, sets all inputs in collection's

### $.fn.width
#### $.fn.width

@@ -570,1 +594,76 @@ Returns the width of the element.

```
---
### Utilities
#### $.each()
Iterates through a collection and calls the callback method on each.
```js
$.each(collection, callback) // => collection
```
#### $.extend()
Extends target object with properties from the source object. If no target is provided,
cash itself will be extended.
```js
$.extend(target,source) // => object
```
#### $.matches()
Checks a selector against an element, returning a boolean value for match.
```js
$.matches(element, selector) // => boolean
```
#### $.parseHTML()
Returns a collection from an HTML string.
```js
$.parseHTML(htmlString) // => Collection
```
---
### Type Checking
#### $.isFunction()
Check if the argument is a function.
```js
var func = function(){};
$.isFunction(func) // => true
```
#### $.isString()
Check if the argument is a string.
```js
$.isString('hello') // => true
```
#### $.isArray()
Check if the argument is an array.
```js
$.isString([1,2,3]) // => true
```
#### $.isNumeric(n)
Check if the argument is numeric.
```js
$.isNumeric(57) // => true
```

@@ -15,10 +15,11 @@ (function(root, factory) {

slice = ArrayProto.slice,
filter = ArrayProto.filter;
filter = ArrayProto.filter,
push = ArrayProto.push;
// @include ./core.js
// @include ./util.js
// @include ./data.js
// @include ./attributes.js
// @include ./collection.js
// @include ./css.js
// @include ./data.js
// @include ./dimensions.js

@@ -28,4 +29,6 @@ // @include ./events.js

// @include ./manipulation.js
// @include ./offset.js
// @include ./traversal.js
return cash;
});
var notWhiteMatch = /\S+/g;
fn.extend({
function hasClass(v,c) {
return ( v.classList ?
v.classList.contains(c) :
new RegExp('(^| )' + c + '( |$)', 'gi').test(v.className)
);
}
addClass(className) { // TODO: tear out into module for IE9
var classes = className.match(notWhiteMatch),
spacedName, l;
function addClass(v,c,spacedName){
if (v.classList) { v.classList.add(c); }
else if ( spacedName.indexOf(` ${c} `) ) { v.className += ' ' + c; }
}
this.each(v => {
l = classes.length;
function removeClass(v,c){
if (v.classList) { v.classList.remove(c); }
else { v.className = v.className.replace(c,''); }
}
if (v.classList) {
while (l--) {
v.classList.add(classes[l]);
}
} else {
while (l--) {
spacedName = ` ${v.className} `;
fn.extend({
if (spacedName.indexOf(` ${classes[l]} `) === -1) {
v.className += ' ' + classes[l];
}
}
}
addClass(c){
var classes = c.match(notWhiteMatch);
return this.each(v => {
var spacedName = ` ${v.className} `;
each(classes,c => { addClass(v,c,spacedName); });
});
return this;
},
attr(name, value) {
if (!value) {
return this[0].getAttribute(name);
} else {
this.each(v => v.setAttribute(name, value));
return this;
}
if ( !value ) { return ( this[0].getAttribute ? this[0].getAttribute(name) : this[0][name] ); }
return this.each(v => {
if ( v.setAttribute ) { v.setAttribute(name, value); }
else { v[name] = value; }
});
},
hasClass(className) { // TODO: tear out into module for IE9
if (this[0].classList) {
return this[0].classList.contains(className);
} else {
return this[0].className.indexOf(className) !== -1;
}
hasClass(c) {
var check = false;
this.each(v => {
check = hasClass(v,c);
return !check;
});
return check;
},
prop(name) {
return this[0][name];
prop(name,value) {
if ( !value ) { return this[0][name]; }
return this.each(v => { v[name] = value; });
},
removeAttr(name) {
this.each(v => v.removeAttribute(name));
return this;
return this.each(v => {
if ( v.removeAttribute ) { v.removeAttribute(name); }
else { delete v[name]; }
});
},
removeClass(className) { // TODO: tear out into module for IE9
var classes = className.match(notWhiteMatch),
l, newClassName;
removeClass(c){
var classes = c.match(notWhiteMatch);
this.each(v => {
l = classes.length;
return this.each(v => {
each(classes,c => { removeClass(v,c); });
});
},
if (v.classList) {
while (l--) {
v.classList.remove(classes[l]);
}
} else {
newClassName = ` ${v.className} `;
removeProp(name){
return this.each(v => { delete v[name]; });
},
while (l--) {
newClassName = newClassName.replace(` ${classes[l]} `, ' ');
}
toggleClass(c, state){
if ( state !== undefined ) { return this[state ? 'addClass' : 'removeClass' ](c); }
var classes = c.match(notWhiteMatch);
v.className = newClassName.trim();
}
return this.each(v => {
var spacedName = ` ${v.className} `;
each(classes,c => {
if ( hasClass(v,c) ) { removeClass(v,c); } else { addClass(v,c,spacedName); }
});
});
},
return this;
}
});
fn.extend({
add() {
var arr = slice.call(this),
i = 0, l;
for (l = arguments.length; i < l; i++) {
arr = arr.concat(slice.call(cash(arguments[i])));
}
return cash.unique(arr);
add(selector, context) {
return unique(cash.merge(this, cash(selector, context)));
},
each(callback) {
cash.each(this, callback);
each(this, callback);
return this;
},
eq(index) {
return cash(this[index]);
return cash(this.get(index));
},
filter(selector) {
if (typeof selector === 'string') {
return filter.call(this, e => cash.matches(e, selector));
} else {
return filter.call(this, selector);
}
return filter.call(this, ( isString(selector) ? e => matches(e, selector) : selector ));
},
first() {
return cash(this[0]);
return this.eq(0);
},
get(num) {
return this[num];
get(index) {
if ( index === undefined ) { return slice.call(this); }
return ( index < 0 ? this[index + this.length] : this[index] );
},
index(elem) {
if (!elem) {
return slice.call(cash(this[0]).parent().children()).indexOf(this[0]);
} else {
return slice.call(cash(elem).children()).indexOf(this[0]);
}
var f = this[0];
return slice.call( elem ? cash(elem) : cash(f).parent().children() ).indexOf(f);
},
last() {
return cash(this[this.length - 1]);
return this.eq(-1);
}
});

@@ -0,61 +1,93 @@

var noop = function(){},
isFunction = function(item){ return typeof item === typeof noop; },
isString = function(item) { return typeof item === typeof ''; };
var idMatch = /^#[\w-]*$/,
classMatch = /^\.[\w-]*$/,
singlet = /^[\w-]*$/;
htmlMatch = /<.+>/,
singlet = /^\w+$/;
function cash(selector, context) {
return new cash.fn.init(selector, context);
function find(selector,context) {
context = context || doc;
var elems = (
classMatch.test(selector) ?
context.getElementsByClassName(selector.slice(1)) :
singlet.test(selector) ?
context.getElementsByTagName(selector) :
context.querySelectorAll(selector)
);
return elems;
}
var fn = cash.fn = cash.prototype = {
cash: true,
length: 0
};
var frag, tmp;
function parseHTML(str) {
frag = frag || doc.createDocumentFragment();
tmp = tmp || frag.appendChild(doc.createElement('div'));
tmp.innerHTML = str;
return tmp.childNodes;
}
fn.init = function(selector, context) {
var result = [],
matcher, elem;
function onReady(fn) {
if ( doc.readyState !== 'loading' ) { fn(); }
else { doc.addEventListener('DOMContentLoaded', fn); }
}
if (!selector) {
return this;
}
function Init(selector,context){
this.length = 1;
if ( !selector ) { return this; }
if (typeof selector !== 'string') {
if (selector.cash) {
return selector;
}
// If already a cash collection, don't do any further processing
if ( selector.cash && selector !== win ) { return selector; }
this[0] = selector;
return this;
}
var elems = selector,
i = 0,
length;
if (selector.charAt(0) === '<' &&
selector.charAt(selector.length - 1) === '>' &&
selector.length >= 3) {
result = cash.parseHTML(selector);
} else {
matcher = idMatch.test(selector);
elem = selector.slice(1);
if ( isString(selector) ) {
elems = (
idMatch.test(selector) ?
// If an ID use the faster getElementById check
doc.getElementById(selector.slice(1)) :
htmlMatch.test(selector) ?
// If HTML, parse it into real elements
parseHTML(selector) :
// else use `find`
find(selector,context)
);
if (!context && matcher) {
this[0] = doc.getElementById(elem);
return this;
} else {
context = (cash(context)[0] || doc);
// If function, use as shortcut for DOM ready
} else if ( isFunction(selector) ) { onReady(selector); return this; }
result = slice.call(
singlet.test(elem) ?
classMatch.test(selector) ? doc.getElementsByClassName(elem) :
doc.getElementsByTagName(selector) :
context.querySelectorAll(selector)
);
}
if ( !elems ) { return this; }
// If a single DOM element is passed in or received via ID, return the single element
if ( elems.nodeType || elems === win ) {
this[0] = elems;
this.length = 1;
} else {
// Treat like an array and loop through each item.
length = this.length = elems.length;
for( ; i < length; i++ ) { this[i] = elems[i]; }
}
this.length = 0;
cash.merge(this, result);
return this;
}
function cash(selector,context) {
return new Init(selector,context);
}
var fn = cash.fn = cash.prototype = Init.prototype = {
constructor: cash,
cash: true,
length: 0,
push: push,
splice: ArrayProto.splice,
map: ArrayProto.map,
init: Init
};
fn.init.prototype = fn;
cash.parseHTML = parseHTML;
cash.noop = noop;
cash.isFunction = isFunction;
cash.isString = isString;

@@ -0,20 +1,51 @@

var getPrefixedProp = (function() {
var cache = {},
div = doc.createElement('div'),
style = div.style,
camelRegex = /(?:^\w|[A-Z]|\b\w)/g,
whiteSpace = /\s+/g;
function camelCase(str) {
return str.replace(camelRegex, function(letter, index) {
return letter[ index === 0 ? 'toLowerCase' : 'toUpperCase' ]();
}).replace(whiteSpace, '');
}
return function(prop) {
prop = camelCase(prop);
if ( cache[prop] ) { return cache[prop]; }
var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1),
prefixes = ['webkit', 'moz', 'ms', 'o'],
props = (prop + ' ' + (prefixes).join(ucProp + ' ') + ucProp).split(' ');
each(props,p => {
if ( p in style ) {
cache[p] = prop = cache[prop] = p;
return false;
}
});
return cache[prop];
};
}());
fn.extend({
css(prop, value) {
if (typeof prop === 'object') {
this.each(v => {
for (var key in prop) {
if (prop.hasOwnProperty(key)) {
v.style[key] = prop[key];
}
}
});
} else if (value) {
this.each(v => v.style[prop] = value);
return this;
} else {
return win.getComputedStyle(this[0], null)[prop];
css(prop,value){
if ( isString(prop) ) {
prop = getPrefixedProp(prop);
return ( value ?
this.each(v => v.style[prop] = value ) :
win.getComputedStyle(this[0])[prop]
);
}
for (var key in prop) {
this.css(key,prop[key]);
}
return this;
}
});

@@ -0,31 +1,37 @@

var uid = cash.uid = '_cash'+Date.now();
function getDataCache(node) {
return (node[uid] = node[uid] || {});
}
function setData(node, key, value) {
return (getDataCache(node)[key] = value);
}
function getData(node, key) {
var c = getDataCache(node);
if ( c[key] === undefined ) {
c[key] = node.dataset ? node.dataset[key] : cash(node).attr('data-'+key);
}
return c[key];
}
function removeData(node, key) {
var c = getDataCache(node);
if ( c ) { delete c[key]; }
else if ( node.dataset ) { delete node.dataset[key]; }
else { cash(node).removeAttr('data-' + name); }
}
fn.extend({
data(key, value) { // TODO: tear out into module for IE9
if (!value) {
return this[0].dataset ? this[0].dataset[key] : cash(this[0]).attr('data-' + key);
} else {
this.each(v => {
if (v.dataset) {
v.dataset[key] = value;
} else {
cash(v).attr('data-' + key, value);
}
});
return this;
}
if (!value) { return getData(this[0],key); }
return this.each(v => setData(v,key,value) );
},
removeData(name) { // TODO: tear out into module for IE9
this.each(v => {
if (v.dataset) {
delete v.dataset[name];
} else {
cash(v).removeAttr('data-' + name);
}
});
return this;
removeData(key) { // TODO: tear out into module for IE9
return this.each(v => removeData(v,key) );
}
});
function compute(el, prop) {
return parseInt(win.getComputedStyle(el[0], null)[prop], 10);
return parseInt(win.getComputedStyle(el[0], null)[prop], 10) || 0;
}
fn.extend({
each(['Width','Height'],v => {
height() {
return this[0].getBoundingClientRect().height;
},
var lower = v.toLowerCase();
innerWidth() {
return this[0].clientWidth;
},
fn[lower] = function(){ return this[0].getBoundingClientRect()[lower]; };
innerHeight() {
return this[0].clientHeight;
},
fn['inner'+v] = function(){ return this[0]['client'+v]; };
outerWidth(margins) {
if (margins === true) {
return this[0].offsetWidth +
(compute(this, 'margin-left') || compute(this, 'marginLeft') || 0) +
(compute(this, 'margin-right') || compute(this, 'marginRight') || 0);
}
fn['outer'+v] = function(margins) {
return this[0]['offset'+v] + ( margins ?
compute(this, 'margin'+( v === 'Width' ? 'Left' : 'Top' )) +
compute(this, 'margin'+( v === 'Width' ? 'Right' : 'Bottom' )) :
0 );
};
return this[0].offsetWidth;
},
outerHeight(margins) {
if (margins === true) {
return this[0].offsetHeight +
(compute(this, 'margin-top') || compute(this, 'marginTop') || 0) +
(compute(this, 'margin-bottom') || compute(this, 'marginBottom') || 0);
}
return this[0].offsetHeight;
},
width() {
return this[0].getBoundingClientRect().width;
}
});

@@ -1,26 +0,16 @@

var _eventCache = {};
function guid() {
function _p8(s) {
var p = (Math.random().toString(16) + '000000000').substr(2, 8);
return s ? '-' + p.substr(0, 4) + '-' + p.substr(4, 4) : p ;
}
return _p8() + _p8(true) + _p8(true) + _p8();
function registerEvent(node, eventName, callback) {
var eventCache = getData(node,'_cashEvents') || setData(node, '_cashEvents', {});
eventCache[eventName] = eventCache[eventName] || [];
eventCache[eventName].push(callback);
node.addEventListener(eventName, callback);
}
function registerEvent(node, eventName, callback) {
var nid = cash(node).data('cshid') || guid();
cash(node).data('cshid', nid);
if (!(nid in _eventCache)) {
_eventCache[nid] = {};
function removeEvent(node, eventName, callback){
var eventCache = getData(node,'_cashEvents')[eventName];
if (callback) {
node.removeEventListener(eventName, callback);
} else {
each(eventCache, event => { node.removeEventListener(eventName, event); });
eventCache = [];
}
if (!(eventName in _eventCache[nid])) {
_eventCache[nid][eventName] = [];
}
_eventCache[nid][eventName].push(callback);
}

@@ -31,64 +21,69 @@

off(eventName, callback) {
this.each(v => {
if (callback) {
v.removeEventListener(eventName, callback);
} else {
for (var i in _eventCache[cash(v).data('cshid')][eventName]) {
v.removeEventListener(eventName, _eventCache[cash(v).data('cshid')][eventName][i]);
}
}
});
return this;
return this.each(v => removeEvent(v, eventName, callback) );
},
on(eventName, delegate, callback) {
if (typeof delegate === 'function') {
callback = delegate;
on(eventName, delegate, callback, runOnce) {
this.each(v => {
registerEvent(cash(v), eventName, callback);
v.addEventListener(eventName, callback);
});
var originalCallback;
if ( !isString(eventName) ) {
for (var key in eventName) {
this.on(key,delegate,eventName[key]);
}
return this;
} else {
this.each(v => {
function handler(e) {
var t = e.target;
}
if (cash.matches(t, delegate)) {
callback.call(t);
} else {
while (!cash.matches(t, delegate)) {
if (t === v) {
return (t = false);
}
t = t.parentNode;
}
if ( isFunction(delegate) ) {
callback = delegate;
delegate = null;
}
if (t) {
callback.call(t);
if ( eventName === 'ready' ) { onReady(callback); return this; }
if ( delegate ) {
originalCallback = callback;
callback = function(e) {
var t = e.target;
if (matches(t, delegate)) {
originalCallback.call(t);
} else {
while (!matches(t, delegate)) {
if (t === this) {
return (t = false);
}
t = t.parentNode;
}
if (t) {
originalCallback.call(t);
}
}
};
}
registerEvent(cash(v), eventName, handler);
v.addEventListener(eventName, handler);
});
return this;
}
return this.each(v => {
var finalCallback = callback;
if ( runOnce ) {
finalCallback = function(){
callback.apply(this,arguments);
removeEvent(v, eventName, finalCallback);
};
}
registerEvent(v, eventName, finalCallback);
});
},
ready(callback) {
this[0].addEventListener('DOMContentLoaded', callback);
one(eventName, delegate, callback) {
return this.on(eventName, delegate, callback, true);
},
ready: onReady,
trigger(eventName) {
var evt = doc.createEvent('HTMLEvents');
evt.initEvent(eventName, true, false);
this.each(v => v.dispatchEvent(evt));
return this;
return this.each(v => v.dispatchEvent(evt));
}
});

@@ -1,25 +0,29 @@

var encode = encodeURIComponent;
function encode(name,value) {
return '&' + encodeURIComponent(name) + '=' + encodeURIComponent(value).replace(/%20/g, '+');
}
function isCheckable(field){
return field.type === 'radio' || field.type === 'checkbox';
}
var formExcludes = ['file','reset','submit','button'];
fn.extend({
serialize() {
var form = this[0],
query = '',
field, i, j;
var formEl = this[0].elements,
query = '';
for (i = form.elements.length - 1; i >= 0; i--) {
field = form.elements[i];
if (field.name && field.type !== 'file' && field.type !== 'reset') {
if (field.type === 'select-multiple') {
for (j = form.elements[i].options.length - 1; j >= 0; j--) {
if (field.options[j].selected) {
query += '&' + field.name + '=' + encode(field.options[j].value).replace(/%20/g, '+');
each(formEl,field => {
if (field.name && formExcludes.indexOf(field.type) < 0) {
if ( field.type === 'select-multiple') {
each(field.options, o => {
if ( o.selected) {
query += encode(field.name,o.value);
}
}
} else if ((field.type !== 'submit' && field.type !== 'button')) {
query += '&' + field.name + '=' + encode(field.value).replace(/%20/g, '+');
});
} else if ( !isCheckable(field) || (isCheckable(field) && field.checked) ) {
query += encode(field.name,field.value);
}
}
}
});

@@ -33,4 +37,3 @@ return query.substr(1);

} else {
this.each(v => v.value = value);
return this;
return this.each(v => v.value = value);
}

@@ -37,0 +40,0 @@ }

@@ -0,19 +1,52 @@

function insertElement(el, child, prepend){
if ( prepend ) {
var first = el.childNodes[0];
el.insertBefore(child,first);
} else {
el.appendChild(child);
}
}
function insertContent(parent, child, prepend){
var str = isString(child);
if ( !str && child.length ) {
each(child, v => insertContent(parent, v, prepend) );
return;
}
each(parent,
str ? v => v.insertAdjacentHTML( prepend ? 'afterbegin' : 'beforeend', child) :
(v,i) => insertElement(v,( i === 0 ? child : child.cloneNode(true) ), prepend)
);
}
fn.extend({
after(selector) {
cash(selector).insertAfter(this);
return this;
},
append(content) {
this[0].appendChild(cash(content)[0]);
insertContent(this,content);
return this;
},
appendTo(content) {
cash(content)[0].appendChild(this[0]);
appendTo(parent) {
insertContent(cash(parent),this);
return this;
},
before(selector) {
cash(selector).insertBefore(this);
return this;
},
clone() {
return cash(this[0].cloneNode(true));
return cash(this.map(v => { return v.cloneNode(true); }));
},
empty() {
this.each(v => v.innerHTML = '');
this.html('');
return this;

@@ -23,15 +56,15 @@ },

html(content) {
var source;
if (content === 'undefined') {
return this[0].innerHTML;
} else {
source = typeof content === 'object' ? cash(content)[0].outerHTML : content;
this.each(v => v.innerHTML = `${source}`);
return this;
}
if ( content === undefined ) { return this[0].innerHTML; }
var source = ( content.nodeType ? content[0].outerHTML : content );
return this.each(v => v.innerHTML = source);
},
insertAfter(selector) {
cash(selector)[0].insertAdjacentHTML('afterend', this[0].outerHTML);
cash(selector).each((el,i) => {
var parent = el.parentNode,
sibling = el.nextSibling;
this.each(v => { parent.insertBefore(( i === 0 ? v : v.cloneNode(true) ),sibling); });
});
return this;

@@ -41,13 +74,16 @@ },

insertBefore(selector) {
cash(selector)[0].insertAdjacentHTML('beforebegin', this[0].outerHTML);
cash(selector).each((el,i) => {
var parent = el.parentNode;
this.each(v => { parent.insertBefore(( i === 0 ? v : v.cloneNode(true) ),el); });
});
return this;
},
prepend(selector) {
cash(this)[0].insertAdjacentHTML('afterBegin', cash(selector)[0].outerHTML);
prepend(content) {
insertContent(this,content,true);
return this;
},
prependTo(selector) {
cash(selector)[0].insertAdjacentHTML('afterBegin', this[0].outerHTML);
prependTo(parent) {
insertContent(cash(parent),this,true);
return this;

@@ -57,14 +93,10 @@ },

remove() {
this.each(v => v.parentNode.removeChild(v));
return this.each(v => v.parentNode.removeChild(v));
},
text(content) {
if (!content) {
return this[0].textContent;
} else {
this.each(v => v.textContent = content);
return this;
}
if (!content) { return this[0].textContent; }
return this.each(v => v.textContent = content);
}
});

@@ -0,35 +1,45 @@

function directCompare(el,selector){ return el === selector; }
fn.extend({
children(selector) {
if (!selector) {
return cash.fn.extend(this[0].children, cash.fn);
} else {
return cash(this[0].children).filter(v => {
return cash.matches(v, selector);
});
}
var elems = [];
this.each(el => { push.apply(elems,el.children); });
elems = unique(elems);
return ( !selector ? elems : elems.filter(v => {
return matches(v, selector);
}) );
},
closest(selector) {
if (!selector || cash.matches(this[0], selector)) {
return this;
} else {
return this.parent().closest(selector);
}
if (!selector || matches(this[0], selector)) { return this; }
return this.parent().closest(selector);
},
is(selector) {
if (!selector) {
return false;
}
if ( !selector ) { return false; }
if (selector.cash) {
return this[0] === selector[0];
}
var match = false,
comparator = (
isString(selector) ? matches :
selector.cash ? el => { return selector.is(el); } :
directCompare
);
return typeof selector === 'string' ? cash.matches(this[0], selector) : false;
this.each((el,i) => {
match = comparator(el,selector,i);
return !match;
});
return match;
},
find(selector) {
return cash.fn.extend(this[0].querySelectorAll(selector), cash.fn);
if ( !selector ) { return cash(); }
var elems = [];
this.each(el => { push.apply(elems,find(selector,el)); });
return unique(elems);
},

@@ -49,3 +59,3 @@

return filter.call(this, el => {
return !cash.matches(el, selector);
return !matches(el, selector);
});

@@ -55,7 +65,7 @@ },

parent() {
var result = ArrayProto.map.call(this, item => {
var result = this.map(item => {
return item.parentElement || doc.body.parentNode;
});
return cash.unique(result);
return unique(result);
},

@@ -65,4 +75,3 @@

var last,
result = [],
count = 0;
result = [];

@@ -75,5 +84,4 @@ this.each(item => {

if (!selector || (selector && cash.matches(last, selector))) {
result[count] = last;
count++;
if (!selector || (selector && matches(last, selector))) {
result.push(last);
}

@@ -83,3 +91,3 @@ }

return cash.unique(result);
return unique(result);
},

@@ -86,0 +94,0 @@

@@ -1,28 +0,17 @@

function buildFragment(str) {
var fragment = fragment || doc.createDocumentFragment(),
tmp = tmp || fragment.appendChild(doc.createElement('div'));
tmp.innerHTML = str;
return tmp;
}
cash.extend = fn.extend = function(target) {
target = target || {};
cash.each = function(collection, callback) {
var l = collection.length,
i = 0;
var args = slice.call(arguments),
length = args.length,
i = 1;
for (; i < l; i++) {
callback.call(collection[i], collection[i], i, collection);
}
};
cash.extend = fn.extend = function(target, source) {
var prop;
if (!source) {
source = target;
if ( args.length === 1) {
target = this;
i = 0;
}
for (prop in source) {
if (source.hasOwnProperty(prop)) {
target[prop] = source[prop];
for (; i < length; i++) {
if (!args[i]) { continue; }
for (var key in args[i]) {
if ( args[i].hasOwnProperty(key) ) { target[key] = args[i][key]; }
}

@@ -34,41 +23,48 @@ }

cash.matches = function(el, selector) {
function each(collection, callback) {
var l = collection.length,
i = 0;
for (; i < l; i++) {
if ( callback.call(collection[i], collection[i], i, collection) === false ) { break; }
}
}
function matches(el, selector) {
return (
el.matches ||
el.matchesSelector ||
el.webkitMatchesSelector ||
el.mozMatchesSelector ||
el.msMatchesSelector ||
el.mozMatchesSelector ||
el.webkitMatchesSelector ||
el.oMatchesSelector
).call(el, selector);
};
}
cash.merge = function(first, second) {
var len = +second.length,
i = first.length,
j = 0;
function unique(collection) {
return cash(slice.call(collection).filter((item, index, self) => {
return self.indexOf(item) === index;
}));
}
for (; j < len; i++, j++) {
first[i] = second[j];
}
cash.extend({
first.length = i;
return first;
};
merge(first, second) {
var len = +second.length,
i = first.length,
j = 0;
cash.parseHTML = function(str) {
var parsed = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/).exec(str);
for (; j < len; i++, j++) {
first[i] = second[j];
}
if (parsed) {
return [doc.createElement(parsed[1])];
}
first.length = i;
return first;
},
parsed = buildFragment(str);
return slice.call(parsed.childNodes);
};
each: each,
matches: matches,
unique: unique,
isArray: Array.isArray,
isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); }
cash.unique = function(collection) {
return cash.merge(cash(), slice.call(collection).filter((item, index, self) => {
return self.indexOf(item) === index;
}));
};
});

@@ -27,2 +27,13 @@ // Core

QUnit.test( "tagName which doesnt exist Query", function( assert ) {
assert.equal($('foo').length, 0, "tagName which doenst exist Passed!" );
});
QUnit.test( "id Query for non-existing element", function( assert ) {
assert.equal($('#i-dont-exist').length, 0, "id for non-existing element Passed!" );
});
QUnit.test( "className Query for non-existing element", function( assert ) {
assert.equal($('.i-dont-exist').length, 0, "className for non-existing element Passed!" );
});
//Attributes

@@ -53,5 +64,18 @@

var hasClass = $('.attr-fixture').hasClass('has-class');
assert.equal(hasClass, true, "hasClass Passed!" );
assert.equal(hasClass, true, "hasClass (true) Passed!" );
var hasClass = $('.attr-fixture').hasClass('not-a-real-class');
assert.equal(hasClass, false, "hasClass (false) Passed!" );
});
QUnit.test( "toggleClass", function( assert ) {
var hasClass = $('.attr-fixture').toggleClass('toggle-class-force',true).hasClass('toggle-class-force');
assert.equal(hasClass, true, "toggleClass (force add) Passed!" );
var hasClass = $('.attr-fixture').toggleClass('toggle-class-force',false).hasClass('toggle-class-force');
assert.equal(hasClass, false, "toggleClass (force remove) Passed!" );
var hasClass = $('.attr-fixture').toggleClass('toggle-class').hasClass('toggle-class');
assert.equal(hasClass, true, "toggleClass (add) Passed!" );
var hasClass = $('.attr-fixture').toggleClass('toggle-class').hasClass('toggle-class');
assert.equal(hasClass, false, "toggleClass (remove) Passed!" );
});
QUnit.test( "prop", function( assert ) {

@@ -80,8 +104,12 @@ assert.equal($('.prop-fixture').prop('checked'), true, "prop Passed!" );

assert.equal(addFixture.length, 2, "add(one) Passed!" );
addFixture = $('#id-fixture').add( $('a').eq(0) , $('a').eq(1) );
addFixture = $('#id-fixture').add( $('a').eq(0) ).add( $('a').eq(1) );
assert.equal(addFixture.length, 3, "add(two) Passed!" );
addFixture = $('#id-fixture').add( $('#qunit-fixture a') , $('#qunit-fixture input') );
assert.equal(addFixture.length, 9, "add(collections) Passed!" );
addFixture = $('#id-fixture').add( $('#qunit-fixture a') ).add( $('#qunit-fixture input') );
assert.equal(addFixture.length, 13, "add(collections) Passed!" );
addFixture = $('#qunit-fixture a').first().add( $('#qunit-fixture a') );
assert.equal(addFixture.length, 4, "add(no duplicates) Passed!" );
addFixture = $('#id-fixture').add( "#qunit-fixture a" );

@@ -132,3 +160,8 @@ assert.equal(addFixture.length, 5, "add(allow selector string) Passed!" );

QUnit.test( "map", function( assert ) {
var result = $('#id-fixture').map(function(e){ return e.id; });
assert.deepEqual(result, ['id-fixture'], "map Passed!" );
});
//CSS

@@ -230,3 +263,3 @@

var data = $('.form-fixture').serialize();
assert.equal(data, "text=text&hidden=5", "serialize Passed!" );
assert.equal(data, "hidden=5&text=text&checkbox-yes=yes&radio=yes&select=selected&select-multiple=option-1&select-multiple=option-2", "serialize Passed!" );
});

@@ -292,2 +325,3 @@

assert.equal($('#id-fixture').is($('#id-fixture')), true, "is Passed!" );
assert.equal($('#id-fixture').is($('div')), true, "is Passed!" );
assert.equal($('#id-fixture').is($('#class-fixture')), false, "is Passed!" );

@@ -337,4 +371,4 @@ });

QUnit.test( "insertBefore", function( assert ) {
$('<div class="test"></div>').insertBefore('input[type=submit]');
assert.equal($('.test').index(), 2, "insertBefore Passed!" );
$('<div class="test"></div>').insertBefore('input[type=hidden]');
assert.equal($('.test').index(), 0, "insertBefore Passed!" );
});

@@ -341,0 +375,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc