Socket
Socket
Sign inDemoInstall

cash-dom

Package Overview
Dependencies
0
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.4 to 1.3.5

192

dist/cash.js
"use strict";
/*! cash-dom 1.3.4, https://github.com/kenwheeler/cash @license MIT */
(function (root, factory) {
/*! cash-dom 1.3.5, https://github.com/kenwheeler/cash @license MIT */
;(function (root, factory) {
if (typeof define === "function" && define.amd) {

@@ -16,3 +16,4 @@ define(factory);

var noop = function () {}, isFunction = function (item) {
return typeof item === typeof noop;
// @see https://crbug.com/568448
return typeof item === typeof noop && item.call;
}, isString = function (item) {

@@ -30,8 +31,14 @@ return typeof item === typeof "";

var frag, tmp;
var frag;
function parseHTML(str) {
frag = frag || doc.createDocumentFragment();
tmp = tmp || frag.appendChild(doc.createElement("div"));
tmp.innerHTML = str;
return tmp.childNodes;
if (!frag) {
frag = doc.implementation.createHTMLDocument();
var base = frag.createElement("base");
base.href = doc.location.href;
frag.head.appendChild(base);
}
frag.body.innerHTML = str;
return frag.body.childNodes;
}

@@ -97,3 +104,2 @@

var fn = cash.fn = cash.prototype = Init.prototype = { // jshint ignore:line
constructor: cash,
cash: true,

@@ -107,2 +113,4 @@ length: 0,

Object.defineProperty(fn, "constructor", { value: cash });
cash.parseHTML = parseHTML;

@@ -152,2 +160,16 @@ cash.noop = noop;

function getCompareFunction(selector) {
return (
/* Use browser's `matches` function if string */
isString(selector) ? matches :
/* Match a cash element */
selector.cash ? function (el) {
return selector.is(el);
} :
/* Direct comparison */
function (el, selector) {
return el === selector;
});
}
function unique(collection) {

@@ -382,5 +404,11 @@ return cash(slice.call(collection).filter(function (item, index, self) {

filter: function (selector) {
return cash(filter.call(this, (isString(selector) ? function (e) {
return matches(e, selector);
} : selector)));
if (!selector) {
return this;
}
var comparator = (isFunction(selector) ? selector : getCompareFunction(selector));
return cash(filter.call(this, function (e) {
return comparator(e, selector);
}));
},

@@ -490,5 +518,14 @@

function removeEvent(node, eventName, callback) {
var eventCache = getData(node, "_cashEvents")[eventName];
var events = getData(node, "_cashEvents"), eventCache = (events && events[eventName]), index;
if (!eventCache) {
return;
}
if (callback) {
node.removeEventListener(eventName, callback);
index = eventCache.indexOf(callback);
if (index >= 0) {
eventCache.splice(index, 1);
}
} else {

@@ -581,24 +618,66 @@ each(eventCache, function (event) {

}
function isCheckable(field) {
return field.type === "radio" || field.type === "checkbox";
function getSelectMultiple_(el) {
var values = [];
each(el.options, function (o) {
if (o.selected) {
values.push(o.value);
}
});
return values.length ? values : null;
}
var formExcludes = ["file", "reset", "submit", "button"];
function getSelectSingle_(el) {
var selectedIndex = el.selectedIndex;
return selectedIndex >= 0 ? el.options[selectedIndex].value : null;
}
function getValue(el) {
var type = el.type;
if (!type) {
return null;
}
switch (type.toLowerCase()) {
case "select-one":
return getSelectSingle_(el);
case "select-multiple":
return getSelectMultiple_(el);
case "radio":
return (el.checked) ? el.value : null;
case "checkbox":
return (el.checked) ? el.value : null;
default:
return el.value ? el.value : null;
}
}
fn.extend({
serialize: function () {
var formEl = this[0].elements, query = "";
var query = "";
each(formEl, function (field) {
if (field.name && formExcludes.indexOf(field.type) < 0) {
if (field.type === "select-multiple") {
each(field.options, function (o) {
if (o.selected) {
query += encode(field.name, o.value);
}
});
} else if (!isCheckable(field) || (isCheckable(field) && field.checked)) {
query += encode(field.name, field.value);
}
each(this[0].elements || this, function (el) {
if (el.disabled || el.tagName === "FIELDSET") {
return;
}
var name = el.name;
switch (el.type.toLowerCase()) {
case "file":
case "reset":
case "submit":
case "button":
break;
case "select-multiple":
var values = getValue(el);
if (values !== null) {
each(values, function (value) {
query += encode(name, value);
});
}
break;
default:
var value = getValue(el);
if (value !== null) {
query += encode(name, value);
}
}
});

@@ -611,3 +690,3 @@

if (value === undefined) {
return this[0].value;
return getValue(this[0]);
} else {

@@ -767,6 +846,2 @@ return this.each(function (v) {

function directCompare(el, selector) {
return el === selector;
}
fn.extend({

@@ -786,5 +861,8 @@ children: function (selector) {

closest: function (selector) {
if (!selector || matches(this[0], selector)) {
return this;
if (!selector || this.length < 1) {
return cash();
}
if (this.is(selector)) {
return this.filter(selector);
}
return this.parent().closest(selector);

@@ -798,8 +876,6 @@ },

var match = false, comparator = (isString(selector) ? matches : selector.cash ? function (el) {
return selector.is(el);
} : directCompare);
var match = false, comparator = getCompareFunction(selector);
this.each(function (el, i) {
match = comparator(el, selector, i);
this.each(function (el) {
match = comparator(el, selector);
return !match;

@@ -812,4 +888,4 @@ });

find: function (selector) {
if (!selector) {
return cash();
if (!selector || selector.nodeType) {
return cash(selector && this.has(selector).length ? selector : null);
}

@@ -826,5 +902,9 @@

has: function (selector) {
return filter.call(this, function (el) {
return cash(el).find(selector).length !== 0;
var comparator = (isString(selector) ? function (el) {
return find(selector, el).length !== 0;
} : function (el) {
return el.contains(selector);
});
return this.filter(comparator);
},

@@ -837,4 +917,10 @@

not: function (selector) {
return filter.call(this, function (el) {
return !matches(el, selector);
if (!selector) {
return this;
}
var comparator = getCompareFunction(selector);
return this.filter(function (el) {
return !comparator(el, selector);
});

@@ -844,4 +930,8 @@ },

parent: function () {
var result = this.map(function (item) {
return item.parentElement || doc.body.parentNode;
var result = [];
this.each(function (item) {
if (item && item.parentNode) {
result.push(item.parentNode);
}
});

@@ -858,4 +948,4 @@

while (last !== doc.body.parentNode) {
last = last.parentElement;
while (last && last.parentNode && last !== doc.body.parentNode) {
last = last.parentNode;

@@ -878,3 +968,3 @@ if (!selector || (selector && matches(last, selector))) {

return filter.call(collection, function (i) {
return collection.filter(function (i) {
return i !== el;

@@ -881,0 +971,0 @@ });

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

"use strict";/*! cash-dom 1.3.4, https://github.com/kenwheeler/cash @license MIT */
!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||w;var e=$.test(t)?n.getElementsByClassName(t.slice(1)):k.test(t)?n.getElementsByTagName(t):n.querySelectorAll(t);return e}function n(t){return E=E||w.createDocumentFragment(),A=A||E.appendChild(w.createElement("div")),A.innerHTML=t,A.childNodes}function e(t){"loading"!==w.readyState?t():w.addEventListener("DOMContentLoaded",t)}function r(r,i){if(!r)return this;if(r.cash&&r!==T)return r;var o,u=r,s=0;if(q(r))u=P.test(r)?w.getElementById(r.slice(1)):_.test(r)?n(r):t(r,i);else if(R(r))return e(r),this;if(!u)return this;if(u.nodeType||u===T)this[0]=u,this.length=1;else for(o=this.length=u.length;o>s;s++)this[s]=u[s];return this}function i(t,n){return new r(t,n)}function o(t,n){for(var e=t.length,r=0;e>r&&n.call(t[r],t[r],r,t)!==!1;r++);}function u(t,n){var e=t&&(t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector);return!!e&&e.call(t,n)}function s(t){return i(M.call(t).filter(function(t,n,e){return e.indexOf(t)===n}))}function c(t){return t[F]=t[F]||{}}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){return q(t)&&t.match(I)}function d(t,n){return t.classList?t.classList.contains(n):new RegExp("(^| )"+n+"( |$)","gi").test(t.className)}function p(t,n,e){t.classList?t.classList.add(n):e.indexOf(" "+n+" ")&&(t.className+=" "+n)}function v(t,n){t.classList?t.classList.remove(n):t.className=t.className.replace(n,"")}function m(t,n){return parseInt(T.getComputedStyle(t[0],null)[n],10)||0}function g(t,n,e){var r=f(t,"_cashEvents")||a(t,"_cashEvents",{});r[n]=r[n]||[],r[n].push(e),t.addEventListener(n,e)}function y(t,n,e){var r=f(t,"_cashEvents")[n];e?t.removeEventListener(n,e):(o(r,function(e){t.removeEventListener(n,e)}),r=[])}function x(t,n){return"&"+encodeURIComponent(t)+"="+encodeURIComponent(n).replace(/%20/g,"+")}function C(t){return"radio"===t.type||"checkbox"===t.type}function L(t,n,e){if(e){var r=t.childNodes[0];t.insertBefore(n,r)}else t.appendChild(n)}function N(t,n,e){var r=q(n);return!r&&n.length?void o(n,function(n){return N(t,n,e)}):void o(t,r?function(t){return t.insertAdjacentHTML(e?"afterbegin":"beforeend",n)}:function(t,r){return L(t,0===r?n:n.cloneNode(!0),e)})}function b(t,n){return t===n}var E,A,w=document,T=window,S=Array.prototype,M=S.slice,B=S.filter,H=S.push,O=function(){},R=function(t){return typeof t==typeof O},q=function(t){return"string"==typeof t},P=/^#[\w-]*$/,$=/^\.[\w-]*$/,_=/<.+>/,k=/^\w+$/,D=i.fn=i.prototype=r.prototype={constructor:i,cash:!0,length:0,push:H,splice:S.splice,map:S.map,init:r};i.parseHTML=n,i.noop=O,i.isFunction=R,i.isString=q,i.extend=D.extend=function(t){t=t||{};var n=M.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:o,matches:u,unique:s,isArray:Array.isArray,isNumeric:function(t){return!isNaN(parseFloat(t))&&isFinite(t)}});var F=i.uid="_cash"+Date.now();D.extend({data:function(t,n){if(q(t))return void 0===n?f(this[0],t):this.each(function(e){return a(e,t,n)});for(var e in t)this.data(e,t[e]);return this},removeData:function(t){return this.each(function(n){return h(n,t)})}});var I=/\S+/g;D.extend({addClass:function(t){var n=l(t);return n?this.each(function(t){var e=" "+t.className+" ";o(n,function(n){p(t,n,e)})}):this},attr:function(t,n){if(t){if(q(t))return void 0===n?this[0]?this[0].getAttribute?this[0].getAttribute(t):this[0][t]:void 0:this.each(function(e){e.setAttribute?e.setAttribute(t,n):e[t]=n});for(var e in t)this.attr(e,t[e]);return this}},hasClass:function(t){var n=!1,e=l(t);return e&&e.length&&this.each(function(t){return n=d(t,e[0]),!n}),n},prop:function(t,n){if(q(t))return void 0===n?this[0][t]:this.each(function(e){e[t]=n});for(var e in t)this.prop(e,t[e]);return this},removeAttr:function(t){return this.each(function(n){n.removeAttribute?n.removeAttribute(t):delete n[t]})},removeClass:function(t){if(!arguments.length)return this.attr("class","");var n=l(t);return n?this.each(function(t){o(n,function(n){v(t,n)})}):this},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=l(t);return e?this.each(function(t){var n=" "+t.className+" ";o(e,function(e){d(t,e)?v(t,e):p(t,e,n)})}):this}}),D.extend({add:function(t,n){return s(i.merge(this,i(t,n)))},each:function(t){return o(this,t),this},eq:function(t){return i(this.get(t))},filter:function(t){return i(B.call(this,q(t)?function(n){return u(n,t)}:t))},first:function(){return this.eq(0)},get:function(t){return void 0===t?M.call(this):0>t?this[t+this.length]:this[t]},index:function(t){var n=t?i(t)[0]:this[0],e=t?this:i(n).parent().children();return M.call(e).indexOf(n)},last:function(){return this.eq(-1)}});var U=function(){var t=/(?:^\w|[A-Z]|\b\w)/g,n=/[\s-_]+/g;return function(e){return e.replace(t,function(t,n){return t[0===n?"toLowerCase":"toUpperCase"]()}).replace(n,"")}}(),z=function(){var t={},n=document,e=n.createElement("div"),r=e.style;return function(n){if(n=U(n),t[n])return t[n];var e=n.charAt(0).toUpperCase()+n.slice(1),i=["webkit","moz","ms","o"],u=(n+" "+i.join(e+" ")+e).split(" ");return o(u,function(e){return e in r?(t[e]=n=t[n]=e,!1):void 0}),t[n]}}();i.prefixedProp=z,i.camelCase=U,D.extend({css:function(t,n){if(q(t))return t=z(t),arguments.length>1?this.each(function(e){return e.style[t]=n}):T.getComputedStyle(this[0])[t];for(var e in t)this.css(e,t[e]);return this}}),o(["Width","Height"],function(t){var n=t.toLowerCase();D[n]=function(){return this[0].getBoundingClientRect()[n]},D["inner"+t]=function(){return this[0]["client"+t]},D["outer"+t]=function(n){return this[0]["offset"+t]+(n?m(this,"margin"+("Width"===t?"Left":"Top"))+m(this,"margin"+("Width"===t?"Right":"Bottom")):0)}}),D.extend({off:function(t,n){return this.each(function(e){return y(e,t,n)})},on:function(t,n,r,i){var o;if(!q(t)){for(var s in t)this.on(s,n,t[s]);return this}return R(n)&&(r=n,n=null),"ready"===t?(e(r),this):(n&&(o=r,r=function(t){for(var e=t.target;!u(e,n);){if(e===this)return e=!1;e=e.parentNode}e&&o.call(e,t)}),this.each(function(n){var e=r;i&&(e=function(){r.apply(this,arguments),y(n,t,e)}),g(n,t,e)}))},one:function(t,n,e){return this.on(t,n,e,!0)},ready:e,trigger:function(t,n){var e=w.createEvent("HTMLEvents");return e.data=n,e.initEvent(t,!0,!1),this.each(function(t){return t.dispatchEvent(e)})}});var W=["file","reset","submit","button"];D.extend({serialize:function(){var t=this[0].elements,n="";return o(t,function(t){t.name&&W.indexOf(t.type)<0&&("select-multiple"===t.type?o(t.options,function(e){e.selected&&(n+=x(t.name,e.value))}):(!C(t)||C(t)&&t.checked)&&(n+=x(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})}}),D.extend({after:function(t){return i(t).insertAfter(this),this},append:function(t){return N(this,t),this},appendTo:function(t){return N(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 N(this,t,!0),this},prependTo:function(t){return N(i(t),this,!0),this},remove:function(){return this.each(function(t){return t.parentNode.removeChild(t)})},text:function(t){return void 0===t?this[0].textContent:this.each(function(n){return n.textContent=t})}});var j=w.documentElement;return D.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+T.pageYOffset-j.clientTop,left:t.left+T.pageXOffset-j.clientLeft}},offsetParent:function(){return i(this[0].offsetParent)}}),D.extend({children:function(t){var n=[];return this.each(function(t){H.apply(n,t.children)}),n=s(n),t?n.filter(function(n){return u(n,t)}):n},closest:function(t){return!t||u(this[0],t)?this:this.parent().closest(t)},is:function(t){if(!t)return!1;var n=!1,e=q(t)?u:t.cash?function(n){return t.is(n)}:b;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){H.apply(e,t(n,r))}),s(e)},has:function(t){return B.call(this,function(n){return 0!==i(n).find(t).length})},next:function(){return i(this[0].nextElementSibling)},not:function(t){return B.call(this,function(n){return!u(n,t)})},parent:function(){var t=this.map(function(t){return t.parentElement||w.body.parentNode});return s(t)},parents:function(t){var n,e=[];return this.each(function(r){for(n=r;n!==w.body.parentNode;)n=n.parentElement,(!t||t&&u(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 B.call(t,function(t){return t!==n})}}),i});
"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(t,e){e=e||T;var n=q.test(t)?e.getElementsByClassName(t.slice(1)):$.test(t)?e.getElementsByTagName(t):e.querySelectorAll(t);return n}function e(t){if(!A){A=T.implementation.createHTMLDocument();var e=A.createElement("base");e.href=T.location.href,A.head.appendChild(e)}return A.body.innerHTML=t,A.body.childNodes}function n(t){"loading"!==T.readyState?t():T.addEventListener("DOMContentLoaded",t)}function r(r,i){if(!r)return this;if(r.cash&&r!==S)return r;var u,o=r,s=0;if(P(r))o=R.test(r)?T.getElementById(r.slice(1)):D.test(r)?e(r):t(r,i);else if(I(r))return n(r),this;if(!o)return this;if(o.nodeType||o===S)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,e){return new r(t,e)}function u(t,e){for(var n=t.length,r=0;n>r&&e.call(t[r],t[r],r,t)!==!1;r++);}function o(t,e){var n=t&&(t.matches||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector||t.oMatchesSelector);return!!n&&n.call(t,e)}function s(t){return P(t)?o:t.cash?function(e){return t.is(e)}:function(t,e){return t===e}}function c(t){return i(B.call(t).filter(function(t,e,n){return n.indexOf(t)===e}))}function a(t){return t[F]=t[F]||{}}function f(t,e,n){return a(t)[e]=n}function h(t,e){var n=a(t);return void 0===n[e]&&(n[e]=t.dataset?t.dataset[e]:i(t).attr("data-"+e)),n[e]}function l(t,e){var n=a(t);n?delete n[e]:t.dataset?delete t.dataset[e]:i(t).removeAttr("data-"+name)}function d(t){return P(t)&&t.match(U)}function v(t,e){return t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)}function p(t,e,n){t.classList?t.classList.add(e):n.indexOf(" "+e+" ")&&(t.className+=" "+e)}function m(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(e,"")}function g(t,e){return parseInt(S.getComputedStyle(t[0],null)[e],10)||0}function y(t,e,n){var r=h(t,"_cashEvents")||f(t,"_cashEvents",{});r[e]=r[e]||[],r[e].push(n),t.addEventListener(e,n)}function x(t,e,n){var r,i=h(t,"_cashEvents"),o=i&&i[e];o&&(n?(t.removeEventListener(e,n),r=o.indexOf(n),r>=0&&o.splice(r,1)):(u(o,function(n){t.removeEventListener(e,n)}),o=[]))}function b(t,e){return"&"+encodeURIComponent(t)+"="+encodeURIComponent(e).replace(/%20/g,"+")}function L(t){var e=[];return u(t.options,function(t){t.selected&&e.push(t.value)}),e.length?e:null}function N(t){var e=t.selectedIndex;return e>=0?t.options[e].value:null}function C(t){var e=t.type;if(!e)return null;switch(e.toLowerCase()){case"select-one":return N(t);case"select-multiple":return L(t);case"radio":return t.checked?t.value:null;case"checkbox":return t.checked?t.value:null;default:return t.value?t.value:null}}function E(t,e,n){if(n){var r=t.childNodes[0];t.insertBefore(e,r)}else t.appendChild(e)}function w(t,e,n){var r=P(e);return!r&&e.length?void u(e,function(e){return w(t,e,n)}):void u(t,r?function(t){return t.insertAdjacentHTML(n?"afterbegin":"beforeend",e)}:function(t,r){return E(t,0===r?e:e.cloneNode(!0),n)})}var A,T=document,S=window,M=Array.prototype,B=M.slice,H=M.filter,O=M.push,k=function(){},I=function(t){return typeof t==typeof k&&t.call},P=function(t){return"string"==typeof t},R=/^#[\w-]*$/,q=/^\.[\w-]*$/,D=/<.+>/,$=/^\w+$/,_=i.fn=i.prototype=r.prototype={cash:!0,length:0,push:O,splice:M.splice,map:M.map,init:r};Object.defineProperty(_,"constructor",{value:i}),i.parseHTML=e,i.noop=k,i.isFunction=I,i.isString=P,i.extend=_.extend=function(t){t=t||{};var e=B.call(arguments),n=e.length,r=1;for(1===e.length&&(t=this,r=0);n>r;r++)if(e[r])for(var i in e[r])e[r].hasOwnProperty(i)&&(t[i]=e[r][i]);return t},i.extend({merge:function(t,e){for(var n=+e.length,r=t.length,i=0;n>i;r++,i++)t[r]=e[i];return t.length=r,t},each:u,matches:o,unique:c,isArray:Array.isArray,isNumeric:function(t){return!isNaN(parseFloat(t))&&isFinite(t)}});var F=i.uid="_cash"+Date.now();_.extend({data:function(t,e){if(P(t))return void 0===e?h(this[0],t):this.each(function(n){return f(n,t,e)});for(var n in t)this.data(n,t[n]);return this},removeData:function(t){return this.each(function(e){return l(e,t)})}});var U=/\S+/g;_.extend({addClass:function(t){var e=d(t);return e?this.each(function(t){var n=" "+t.className+" ";u(e,function(e){p(t,e,n)})}):this},attr:function(t,e){if(t){if(P(t))return void 0===e?this[0]?this[0].getAttribute?this[0].getAttribute(t):this[0][t]:void 0:this.each(function(n){n.setAttribute?n.setAttribute(t,e):n[t]=e});for(var n in t)this.attr(n,t[n]);return this}},hasClass:function(t){var e=!1,n=d(t);return n&&n.length&&this.each(function(t){return e=v(t,n[0]),!e}),e},prop:function(t,e){if(P(t))return void 0===e?this[0][t]:this.each(function(n){n[t]=e});for(var n in t)this.prop(n,t[n]);return this},removeAttr:function(t){return this.each(function(e){e.removeAttribute?e.removeAttribute(t):delete e[t]})},removeClass:function(t){if(!arguments.length)return this.attr("class","");var e=d(t);return e?this.each(function(t){u(e,function(e){m(t,e)})}):this},removeProp:function(t){return this.each(function(e){delete e[t]})},toggleClass:function(t,e){if(void 0!==e)return this[e?"addClass":"removeClass"](t);var n=d(t);return n?this.each(function(t){var e=" "+t.className+" ";u(n,function(n){v(t,n)?m(t,n):p(t,n,e)})}):this}}),_.extend({add:function(t,e){return c(i.merge(this,i(t,e)))},each:function(t){return u(this,t),this},eq:function(t){return i(this.get(t))},filter:function(t){if(!t)return this;var e=I(t)?t:s(t);return i(H.call(this,function(n){return e(n,t)}))},first:function(){return this.eq(0)},get:function(t){return void 0===t?B.call(this):0>t?this[t+this.length]:this[t]},index:function(t){var e=t?i(t)[0]:this[0],n=t?this:i(e).parent().children();return B.call(n).indexOf(e)},last:function(){return this.eq(-1)}});var j=function(){var t=/(?:^\w|[A-Z]|\b\w)/g,e=/[\s-_]+/g;return function(n){return n.replace(t,function(t,e){return t[0===e?"toLowerCase":"toUpperCase"]()}).replace(e,"")}}(),z=function(){var t={},e=document,n=e.createElement("div"),r=n.style;return function(e){if(e=j(e),t[e])return t[e];var n=e.charAt(0).toUpperCase()+e.slice(1),i=["webkit","moz","ms","o"],o=(e+" "+i.join(n+" ")+n).split(" ");return u(o,function(n){return n in r?(t[n]=e=t[e]=n,!1):void 0}),t[e]}}();i.prefixedProp=z,i.camelCase=j,_.extend({css:function(t,e){if(P(t))return t=z(t),arguments.length>1?this.each(function(n){return n.style[t]=e}):S.getComputedStyle(this[0])[t];for(var n in t)this.css(n,t[n]);return this}}),u(["Width","Height"],function(t){var e=t.toLowerCase();_[e]=function(){return this[0].getBoundingClientRect()[e]},_["inner"+t]=function(){return this[0]["client"+t]},_["outer"+t]=function(e){return this[0]["offset"+t]+(e?g(this,"margin"+("Width"===t?"Left":"Top"))+g(this,"margin"+("Width"===t?"Right":"Bottom")):0)}}),_.extend({off:function(t,e){return this.each(function(n){return x(n,t,e)})},on:function(t,e,r,i){var u;if(!P(t)){for(var s in t)this.on(s,e,t[s]);return this}return I(e)&&(r=e,e=null),"ready"===t?(n(r),this):(e&&(u=r,r=function(t){for(var n=t.target;!o(n,e);){if(n===this)return n=!1;n=n.parentNode}n&&u.call(n,t)}),this.each(function(e){var n=r;i&&(n=function(){r.apply(this,arguments),x(e,t,n)}),y(e,t,n)}))},one:function(t,e,n){return this.on(t,e,n,!0)},ready:n,trigger:function(t,e){var n=T.createEvent("HTMLEvents");return n.data=e,n.initEvent(t,!0,!1),this.each(function(t){return t.dispatchEvent(n)})}}),_.extend({serialize:function(){var t="";return u(this[0].elements||this,function(e){if(!e.disabled&&"FIELDSET"!==e.tagName){var n=e.name;switch(e.type.toLowerCase()){case"file":case"reset":case"submit":case"button":break;case"select-multiple":var r=C(e);null!==r&&u(r,function(e){t+=b(n,e)});break;default:var i=C(e);null!==i&&(t+=b(n,i))}}}),t.substr(1)},val:function(t){return void 0===t?C(this[0]):this.each(function(e){return e.value=t})}}),_.extend({after:function(t){return i(t).insertAfter(this),this},append:function(t){return w(this,t),this},appendTo:function(t){return w(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 e=t.nodeType?t[0].outerHTML:t;return this.each(function(t){return t.innerHTML=e})},insertAfter:function(t){var e=this;return i(t).each(function(t,n){var r=t.parentNode,i=t.nextSibling;e.each(function(t){r.insertBefore(0===n?t:t.cloneNode(!0),i)})}),this},insertBefore:function(t){var e=this;return i(t).each(function(t,n){var r=t.parentNode;e.each(function(e){r.insertBefore(0===n?e:e.cloneNode(!0),t)})}),this},prepend:function(t){return w(this,t,!0),this},prependTo:function(t){return w(i(t),this,!0),this},remove:function(){return this.each(function(t){return t.parentNode.removeChild(t)})},text:function(t){return void 0===t?this[0].textContent:this.each(function(e){return e.textContent=t})}});var W=T.documentElement;return _.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+S.pageYOffset-W.clientTop,left:t.left+S.pageXOffset-W.clientLeft}},offsetParent:function(){return i(this[0].offsetParent)}}),_.extend({children:function(t){var e=[];return this.each(function(t){O.apply(e,t.children)}),e=c(e),t?e.filter(function(e){return o(e,t)}):e},closest:function(t){return!t||this.length<1?i():this.is(t)?this.filter(t):this.parent().closest(t)},is:function(t){if(!t)return!1;var e=!1,n=s(t);return this.each(function(r){return e=n(r,t),!e}),e},find:function(e){if(!e||e.nodeType)return i(e&&this.has(e).length?e:null);var n=[];return this.each(function(r){O.apply(n,t(e,r))}),c(n)},has:function(e){var n=P(e)?function(n){return 0!==t(e,n).length}:function(t){return t.contains(e)};return this.filter(n)},next:function(){return i(this[0].nextElementSibling)},not:function(t){if(!t)return this;var e=s(t);return this.filter(function(n){return!e(n,t)})},parent:function(){var t=[];return this.each(function(e){e&&e.parentNode&&t.push(e.parentNode)}),c(t)},parents:function(t){var e,n=[];return this.each(function(r){for(e=r;e&&e.parentNode&&e!==T.body.parentNode;)e=e.parentNode,(!t||t&&o(e,t))&&n.push(e)}),c(n)},prev:function(){return i(this[0].previousElementSibling)},siblings:function(){var t=this.parent().children(),e=this[0];return t.filter(function(t){return t!==e})}}),i});
{
"name": "cash-dom",
"version": "1.3.4",
"version": "1.3.5",
"description": "An absurdly small jQuery alternative for modern browsers.",

@@ -5,0 +5,0 @@ "main": "./dist/cash.js",

@@ -14,7 +14,7 @@ #Cash

| Library | jQuery 1.12.2 | jQuery 2.2.2 | Cash |
| ------------------------- | -------------:| -------------:| ----------:|
| Uncompressed | 287K | 253K | 20.6K |
| Minified | 95K | 76K | 9.7K |
| **Minified & Gzipped** | **34K** | **30K** | **3.5K** |
| Library | **Cash** | jQuery 3.0 | jQuery 2.2 |
| ------------------------- | --------------:| -----------:| -----------:|
| Uncompressed | **20K** | 263K | 253K |
| Minified | **9.8K** | 86K | 76K |
| **Minified & Gzipped** | **3.5K** | 34K | 30K |

@@ -21,0 +21,0 @@ ---

// @echo header
(function(root, factory) {
;(function(root, factory) {
if (typeof define === 'function' && define.amd) {

@@ -4,0 +4,0 @@ define(factory);

@@ -17,3 +17,7 @@ fn.extend({

filter(selector) {
return cash(filter.call(this, ( isString(selector) ? e => matches(e, selector) : selector )));
if ( !selector ) { return this; }
var comparator = ( isFunction(selector) ? selector : getCompareFunction(selector ));
return cash( filter.call(this, e => comparator(e, selector) ) );
},

@@ -20,0 +24,0 @@

var noop = function(){},
isFunction = function(item){ return typeof item === typeof noop; },
isFunction = function(item) {
// @see https://crbug.com/568448
return typeof item === typeof noop && item.call;
},
isString = function(item) { return typeof item === typeof ''; };

@@ -22,8 +25,14 @@

var frag, tmp;
var frag;
function parseHTML(str) {
frag = frag || doc.createDocumentFragment();
tmp = tmp || frag.appendChild(doc.createElement('div'));
tmp.innerHTML = str;
return tmp.childNodes;
if (!frag) {
frag = doc.implementation.createHTMLDocument();
var base = frag.createElement('base');
base.href = doc.location.href;
frag.head.appendChild(base);
}
frag.body.innerHTML = str;
return frag.body.childNodes;
}

@@ -82,3 +91,2 @@

var fn = cash.fn = cash.prototype = Init.prototype = { // jshint ignore:line
constructor: cash,
cash: true,

@@ -92,2 +100,4 @@ length: 0,

Object.defineProperty(fn,'constructor',{ value: cash });
cash.parseHTML = parseHTML;

@@ -94,0 +104,0 @@ cash.noop = noop;

@@ -9,5 +9,12 @@ function registerEvent(node, eventName, callback) {

function removeEvent(node, eventName, callback){
var eventCache = getData(node,'_cashEvents')[eventName];
var events = getData(node,'_cashEvents'),
eventCache = (events && events[eventName]),
index;
if ( !eventCache ) { return; }
if (callback) {
node.removeEventListener(eventName, callback);
index = eventCache.indexOf(callback);
if ( index >= 0 ) { eventCache.splice( index, 1); }
} else {

@@ -14,0 +21,0 @@ each(eventCache, event => { node.removeEventListener(eventName, event); });

function encode(name,value) {
return '&' + encodeURIComponent(name) + '=' + encodeURIComponent(value).replace(/%20/g, '+');
return '&' + encodeURIComponent(name) + '=' +
encodeURIComponent(value).replace(/%20/g, '+');
}
function isCheckable(field){
return field.type === 'radio' || field.type === 'checkbox';
function getSelectMultiple_(el) {
var values = [];
each(el.options, o => {
if (o.selected) {
values.push(o.value);
}
});
return values.length ? values : null;
}
var formExcludes = ['file','reset','submit','button'];
function getSelectSingle_(el) {
var selectedIndex = el.selectedIndex;
return selectedIndex >= 0 ? el.options[selectedIndex].value :
null;
}
function getValue(el) {
var type = el.type;
if (!type) {
return null;
}
switch (type.toLowerCase()) {
case 'select-one':
return getSelectSingle_(el);
case 'select-multiple':
return getSelectMultiple_(el);
case 'radio':
return (el.checked) ? el.value : null;
case 'checkbox':
return (el.checked) ? el.value : null;
default:
return el.value ? el.value : null;
}
}
fn.extend({
serialize() {
var formEl = this[0].elements,
query = '';
var query = '';
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 ( !isCheckable(field) || (isCheckable(field) && field.checked) ) {
query += encode(field.name,field.value);
}
each(this[0].elements || this, el => {
if (el.disabled || el.tagName === 'FIELDSET') {
return;
}
var name = el.name;
switch (el.type.toLowerCase()) {
case 'file':
case 'reset':
case 'submit':
case 'button':
break;
case 'select-multiple':
var values = getValue(el);
if (values !== null) {
each(values, value => {
query += encode(name, value);
});
}
break;
default:
var value = getValue(el);
if (value !== null) {
query += encode(name, value);
}
}
});

@@ -35,3 +78,3 @@

if (value === undefined) {
return this[0].value;
return getValue(this[0]);
} else {

@@ -38,0 +81,0 @@ return this.each(v => v.value = value);

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

function directCompare(el,selector){ return el === selector; }
fn.extend({

@@ -10,9 +8,13 @@

return ( !selector ? elems : elems.filter(v => {
return (
!selector ? elems :
elems.filter(v => {
return matches(v, selector);
}) );
})
);
},
closest(selector) {
if (!selector || matches(this[0], selector)) { return this; }
if ( !selector || this.length < 1 ) { return cash(); }
if ( this.is(selector) ) { return this.filter(selector); }
return this.parent().closest(selector);

@@ -25,10 +27,6 @@ },

var match = false,
comparator = (
isString(selector) ? matches :
selector.cash ? el => { return selector.is(el); } :
directCompare
);
comparator = getCompareFunction(selector);
this.each((el,i) => {
match = comparator(el,selector,i);
this.each(el => {
match = comparator(el,selector);
return !match;

@@ -41,6 +39,8 @@ });

find(selector) {
if ( !selector ) { return cash(); }
if ( !selector || selector.nodeType ) {
return cash( selector && this.has(selector).length ? selector : null );
}
var elems = [];
this.each(el => { push.apply(elems,find(selector,el)); });
this.each(el => { push.apply(elems, find(selector,el) ); });

@@ -51,5 +51,9 @@ return unique(elems);

has(selector) {
return filter.call(this, el => {
return cash(el).find(selector).length !== 0;
});
var comparator = (
isString(selector) ? el => { return find(selector,el).length !== 0; } :
el => { return el.contains(selector); }
);
return this.filter(comparator);
},

@@ -62,4 +66,8 @@

not(selector) {
return filter.call(this, el => {
return !matches(el, selector);
if ( !selector ) { return this; }
var comparator = getCompareFunction(selector);
return this.filter(el => {
return !comparator(el, selector);
});

@@ -69,4 +77,6 @@ },

parent() {
var result = this.map(item => {
return item.parentElement || doc.body.parentNode;
var result = [];
this.each(item => {
if (item && item.parentNode) { result.push(item.parentNode); }
});

@@ -84,4 +94,4 @@

while (last !== doc.body.parentNode) {
last = last.parentElement;
while ( last && last.parentNode && last !== doc.body.parentNode ) {
last = last.parentNode;

@@ -105,5 +115,5 @@ if (!selector || (selector && matches(last, selector))) {

return filter.call(collection, i => i !== el);
return collection.filter(i => i !== el);
}
});

@@ -43,2 +43,13 @@ cash.extend = fn.extend = function(target) {

function getCompareFunction(selector){
return (
/* Use browser's `matches` function if string */
isString(selector) ? matches :
/* Match a cash element */
selector.cash ? el => { return selector.is(el); } :
/* Direct comparison */
function(el,selector){ return el === selector; }
);
}
function unique(collection) {

@@ -45,0 +56,0 @@ return cash(slice.call(collection).filter((item, index, self) => {

@@ -172,3 +172,3 @@ // Core

addFixture = $('#id-fixture').add( $('#qunit-fixture a') ).add( $('#qunit-fixture input') );
assert.equal(addFixture.length, 14, "add(collections) Passed!" );
assert.equal(addFixture.length, 16, "add(collections) Passed!" );

@@ -201,2 +201,5 @@ addFixture = $('#qunit-fixture a').first().add( $('#qunit-fixture a') );

assert.equal(arrayFixture.length, 2, "filter(fn) Passed!" );
arrayFixture = $('#qunit-fixture div').filter($('#qunit-fixture div').get(0));
assert.equal(arrayFixture.length, 1, "filter(element) Passed!" );
});

@@ -339,4 +342,12 @@

assert.equal(data, "hidden=5&text=text&checkbox-yes=yes&radio=yes&select=selected&select-multiple=option-1&select-multiple=option-2", "serialize Passed!" );
data = $( ".form-fixture input, .form-fixture textarea, .form-fixture select" ).serialize();
assert.equal(data, "hidden=5&text=text&checkbox-yes=yes&radio=yes&select=selected&select-multiple=option-1&select-multiple=option-2", "serialize Passed!" );
});
QUnit.test( "serialize control elements", function( assert ) {
var data = $('input[type=text]').serialize();
assert.equal(data, "text=text", "serialize elemnts passed!" );
});
QUnit.test( "val", function( assert ) {

@@ -356,3 +367,3 @@ assert.equal($('input[type=text]').val(), "text", "val get Passed!" );

QUnit.test( "closest", function( assert ) {
assert.equal($('input.prop-fixture').closest()[0].className, "prop-fixture", "closest Passed!" );
assert.equal($('input.prop-fixture').closest().length, 0, "closest Passed!" );
assert.equal($('input.prop-fixture').closest('div')[0].id, "qunit-fixture", "closest Passed!" );

@@ -359,0 +370,0 @@ });

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc