Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "cash", | ||
"main": ["dist/cash.min.js", "dist/cash.js"], | ||
"version": "1.2.0", | ||
"main": "dist/cash.js", | ||
"version": "1.3.0", | ||
"homepage": "https://github.com/kenwheeler/cash", | ||
@@ -6,0 +6,0 @@ "authors": [ |
138
dist/cash.js
"use strict"; | ||
/*! cash-dom 1.3.0, https://github.com/kenwheeler/cash @license MIT */ | ||
(function (root, factory) { | ||
@@ -93,3 +94,3 @@ if (typeof define === "function" && define.amd) { | ||
var fn = cash.fn = cash.prototype = Init.prototype = { | ||
var fn = cash.fn = cash.prototype = Init.prototype = { // jshint ignore:line | ||
constructor: cash, | ||
@@ -144,3 +145,4 @@ cash: true, | ||
function matches(el, selector) { | ||
return (el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector).call(el, selector); | ||
var m = el && (el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector); | ||
return !!m && m.call(el, selector); | ||
} | ||
@@ -206,14 +208,17 @@ | ||
fn.extend({ | ||
data: function (key, value) { | ||
// TODO: tear out into module for IE9 | ||
if (!value) { | ||
return getData(this[0], key); | ||
data: function (name, value) { | ||
if (isString(name)) { | ||
return (value === undefined ? getData(this[0], name) : this.each(function (v) { | ||
return setData(v, name, value); | ||
})); | ||
} | ||
return this.each(function (v) { | ||
return setData(v, key, value); | ||
}); | ||
for (var key in name) { | ||
this.data(key, name[key]); | ||
} | ||
return this; | ||
}, | ||
removeData: function (key) { | ||
// TODO: tear out into module for IE9 | ||
return this.each(function (v) { | ||
@@ -228,2 +233,6 @@ return removeData(v, key); | ||
function getClasses(c) { | ||
return isString(c) && c.match(notWhiteMatch); | ||
} | ||
function hasClass(v, c) { | ||
@@ -251,5 +260,5 @@ return (v.classList ? v.classList.contains(c) : new RegExp("(^| )" + c + "( |$)", "gi").test(v.className)); | ||
addClass: function (c) { | ||
var classes = c.match(notWhiteMatch); | ||
var classes = getClasses(c); | ||
return this.each(function (v) { | ||
return (classes ? this.each(function (v) { | ||
var spacedName = " " + v.className + " "; | ||
@@ -259,24 +268,39 @@ each(classes, function (c) { | ||
}); | ||
}); | ||
}) : this); | ||
}, | ||
attr: function (name, value) { | ||
if (!value) { | ||
return (this[0].getAttribute ? this[0].getAttribute(name) : this[0][name]); | ||
if (!name) { | ||
return undefined; | ||
} | ||
return this.each(function (v) { | ||
if (v.setAttribute) { | ||
v.setAttribute(name, value); | ||
} else { | ||
v[name] = value; | ||
if (isString(name)) { | ||
if (value === undefined) { | ||
return this[0] ? this[0].getAttribute ? this[0].getAttribute(name) : this[0][name] : undefined; | ||
} | ||
}); | ||
return this.each(function (v) { | ||
if (v.setAttribute) { | ||
v.setAttribute(name, value); | ||
} else { | ||
v[name] = value; | ||
} | ||
}); | ||
} | ||
for (var key in name) { | ||
this.attr(key, name[key]); | ||
} | ||
return this; | ||
}, | ||
hasClass: function (c) { | ||
var check = false; | ||
this.each(function (v) { | ||
check = hasClass(v, c); | ||
return !check; | ||
}); | ||
var check = false, classes = getClasses(c); | ||
if (classes && classes.length) { | ||
this.each(function (v) { | ||
check = hasClass(v, classes[0]); | ||
return !check; | ||
}); | ||
} | ||
return check; | ||
@@ -286,8 +310,13 @@ }, | ||
prop: function (name, value) { | ||
if (!value) { | ||
return this[0][name]; | ||
if (isString(name)) { | ||
return (value === undefined ? this[0][name] : this.each(function (v) { | ||
v[name] = value; | ||
})); | ||
} | ||
return this.each(function (v) { | ||
v[name] = value; | ||
}); | ||
for (var key in name) { | ||
this.prop(key, name[key]); | ||
} | ||
return this; | ||
}, | ||
@@ -306,9 +335,11 @@ | ||
removeClass: function (c) { | ||
var classes = c.match(notWhiteMatch); | ||
return this.each(function (v) { | ||
if (!arguments.length) { | ||
return this.attr("class", ""); | ||
} | ||
var classes = getClasses(c); | ||
return (classes ? this.each(function (v) { | ||
each(classes, function (c) { | ||
removeClass(v, c); | ||
}); | ||
}); | ||
}) : this); | ||
}, | ||
@@ -326,5 +357,4 @@ | ||
} | ||
var classes = c.match(notWhiteMatch); | ||
return this.each(function (v) { | ||
var classes = getClasses(c); | ||
return (classes ? this.each(function (v) { | ||
var spacedName = " " + v.className + " "; | ||
@@ -338,3 +368,3 @@ each(classes, function (c) { | ||
}); | ||
}); | ||
}) : this); | ||
} }); | ||
@@ -357,5 +387,5 @@ | ||
filter: function (selector) { | ||
return filter.call(this, (isString(selector) ? function (e) { | ||
return cash(filter.call(this, (isString(selector) ? function (e) { | ||
return matches(e, selector); | ||
} : selector)); | ||
} : selector))); | ||
}, | ||
@@ -478,2 +508,4 @@ | ||
on: function (eventName, delegate, callback, runOnce) { | ||
// jshint ignore:line | ||
var originalCallback; | ||
@@ -494,3 +526,4 @@ | ||
if (eventName === "ready") { | ||
onReady(callback);return this; | ||
onReady(callback); | ||
return this; | ||
} | ||
@@ -503,15 +536,11 @@ | ||
if (matches(t, delegate)) { | ||
originalCallback.call(t); | ||
} else { | ||
while (!matches(t, delegate)) { | ||
if (t === this) { | ||
return (t = false); | ||
} | ||
t = t.parentNode; | ||
while (!matches(t, delegate)) { | ||
if (t === this) { | ||
return (t = false); | ||
} | ||
t = t.parentNode; | ||
} | ||
if (t) { | ||
originalCallback.call(t); | ||
} | ||
if (t) { | ||
originalCallback.call(t, e); | ||
} | ||
@@ -539,4 +568,5 @@ }; | ||
trigger: function (eventName) { | ||
trigger: function (eventName, data) { | ||
var evt = doc.createEvent("HTMLEvents"); | ||
evt.data = data; | ||
evt.initEvent(eventName, true, false); | ||
@@ -543,0 +573,0 @@ return this.each(function (v) { |
@@ -1,1 +0,2 @@ | ||
"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}); | ||
"use strict";/*! cash-dom 1.3.0, 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=k.test(t)?n.getElementsByClassName(t.slice(1)):F.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=$.test(r)?w.getElementById(r.slice(1)):D.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[P]=t[P]||{}}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(U)}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},$=/^#[\w-]*$/,k=/^\.[\w-]*$/,D=/<.+>/,F=/^\w+$/,I=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=I.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 P=i.uid="_cash"+Date.now();I.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 U=/\S+/g;I.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}}),I.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=this[0];return M.call(t?i(t):i(n).parent().children()).indexOf(n)},last:function(){return this.eq(-1)}});var _=function(){function t(t){return t.replace(i,function(t,n){return t[0===n?"toLowerCase":"toUpperCase"]()}).replace(u,"")}var n={},e=w.createElement("div"),r=e.style,i=/(?:^\w|[A-Z]|\b\w)/g,u=/\s+/g;return function(e){if(e=t(e),n[e])return n[e];var i=e.charAt(0).toUpperCase()+e.slice(1),u=["webkit","moz","ms","o"],s=(e+" "+u.join(i+" ")+i).split(" ");return o(s,function(t){return t in r?(n[t]=e=n[e]=t,!1):void 0}),n[e]}}();I.extend({css:function(t,n){if(q(t))return t=_(t),n?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();I[n]=function(){return this[0].getBoundingClientRect()[n]},I["inner"+t]=function(){return this[0]["client"+t]},I["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)}}),I.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 z=["file","reset","submit","button"];I.extend({serialize:function(){var t=this[0].elements,n="";return o(t,function(t){t.name&&z.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})}}),I.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 t?this.each(function(n){return n.textContent=t}):this[0].textContent}});var W=w.documentElement;return I.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-W.clientTop,left:t.left+T.pageXOffset-W.clientLeft}},offsetParent:function(){return i(this[0].offsetParent)}}),I.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'; | ||
var gulp = require('gulp'); | ||
var pkg = require('./package.json'); | ||
var $ = require('gulp-load-plugins')(); | ||
@@ -8,6 +9,11 @@ | ||
return gulp.src('./src/_wrapper.js') | ||
.pipe($.preprocess()) | ||
.pipe($.preprocess({ | ||
context: { | ||
header: '/*! ' + pkg.name + ' '+pkg.version +', '+pkg.homepage +' @license '+ pkg.license +' */' | ||
} | ||
})) | ||
.pipe($.rename('cash.js')) | ||
.pipe($['6to5']()) | ||
.pipe($.size()) | ||
.pipe($.size({ gzip: true })) | ||
.pipe(gulp.dest('./dist/')); | ||
@@ -18,4 +24,7 @@ }); | ||
return gulp.src(['./dist/cash.js']) | ||
.pipe($.uglify()) | ||
.pipe($.uglify({ | ||
preserveComments: 'license' | ||
})) | ||
.pipe($.size()) | ||
.pipe($.size({ gzip: true })) | ||
.pipe($.rename('cash.min.js')) | ||
@@ -22,0 +31,0 @@ .pipe(gulp.dest('./dist/')); |
{ | ||
"name": "cash-dom", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "An absurdly small jQuery alternative for modern browsers.", | ||
@@ -30,3 +30,3 @@ "main": "./dist/cash.js", | ||
"gulp-size": "~0.1.2", | ||
"gulp-uglify": "~1.0.1", | ||
"gulp-uglify": "^1.5.3", | ||
"gulp-util": "~2.2.9" | ||
@@ -33,0 +33,0 @@ }, |
211
README.md
#Cash | ||
*An absurdly small jQuery alternative for modern browsers* | ||
*An absurdly small jQuery alternative for modern browsers (IE9+)* | ||
Cash is a small library for modern browsers that provides jQuery style syntax | ||
to wrap modern Vanilla JS features. It allows developers to use the jQuery | ||
syntax they already know, and utilizes modern browser features to minimize the | ||
codebase. 100% feature parity with jQuery isn't a goal, but cash comes helpfully | ||
close, covering most day to day use cases. | ||
![https://travis-ci.org/kenwheeler/cash.svg?branch=master](https://travis-ci.org/kenwheeler/cash.svg?branch=master) ![Minified](https://badge-size.herokuapp.com/kenwheeler/cash/master/dist/cash.min.js.svg?label=Size%20%28minified%29) ![GZIP](https://badge-size.herokuapp.com/kenwheeler/cash/master/dist/cash.min.js.svg?compression=gzip&label=Size%20%28gzipped%29) | ||
Cash is a small library for modern browsers (Chrome, Firefox, Safari and Internet | ||
Explorer 9+) that provides jQuery style syntax for manipulating the DOM. Utilizing | ||
modern browser features to minimize the codebase, developers can use the familiar | ||
chainable methods at a fraction of the file size. 100% feature parity with jQuery | ||
isn't a goal, but cash comes helpfully close, covering most day to day use cases. | ||
#### Size Comparison | ||
| 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** | | ||
--- | ||
@@ -14,6 +24,6 @@ | ||
Add cash to your project via the jsDelivr CDN, and use cash to manipulate the DOM! | ||
Add cash to your project on your server or using the [jsDelivr](https://cdn.jsdelivr.net/cash/1.2.0/cash.min.js) or [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/1.2.0/cash.min.js) CDNs, and use cash to manipulate the DOM! | ||
```html | ||
<script src="https://cdn.jsdelivr.net/cash/1.0.0/cash.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/cash/1.2.0/cash.min.js"></script> | ||
<script> | ||
@@ -30,2 +40,12 @@ $(function(){ | ||
Cash is also available through [NPM](http://npmjs.com) as the [`cash-dom`](https://www.npmjs.com/package/cash-dom) package: | ||
``` | ||
npm install cash-dom --save-dev | ||
``` | ||
And through [Bower](http://bower.io/) as `cash`: | ||
``` | ||
bower install cash | ||
``` | ||
--- | ||
@@ -35,4 +55,5 @@ | ||
#### $() | ||
### $() | ||
This is the main selector method for cash. It returns an actionable collection | ||
@@ -50,12 +71,59 @@ of nodes. If a function is provided, the function will be run once the DOM is ready. | ||
### Collection Methods | ||
These methods from the collection prototype ( [$.fn](#fn) ) are available once | ||
you create a collection with `$()` and are called like so: | ||
```js | ||
$(element).addClass(className) // => collection | ||
``` | ||
| Attributes | Collection | CSS | Data | Dimensions | Events | | ||
| ---------- | ---------- | --- | ---- | ---------- | ------ | | ||
| [$.fn.addClass()](#fnaddclass) | [$.fn](#fn) | [$.fn.css()](#fncss) | [$.fn.data()](#fndata) | [$.fn.height()](#fnheight) | [$.fn.off()](#fnoff) | | ||
| [$.fn.attr()](#fnattr) | [$.fn.add()](#fnadd) | | [$.fn.removeData()](#fnremovedata) | [$.fn.innerHeight()](#fninnerheight) | [$.fn.on()](#fnon) | | ||
| [$.fn.hasClass()](#fnhasclass) | [$.fn.each()](#fneach) | | | [$.fn.innerWidth()](#fninnerwidth) | [$.fn.one()](#fnone) | | ||
| [$.fn.prop()](#fnprop) | [$.fn.eq()](#fneq) | | | [$.fn.outerHeight()](#fnouterheight) | [$.fn.ready()](#fnready) | | ||
| [$.fn.removeAttr()](#fnremoveattr) | [$.fn.filter()](#fnfilter) | | | [$.fn.outerWidth()](#fnouterwidth) | [$.fn.trigger()](#fntrigger) | | ||
| [$.fn.removeClass()](#fnremoveclass) | [$.fn.first()](#fnfirst) | | | [$.fn.width()](#fnwidth) | | | ||
| [$.fn.removeProp()](#fnremoveprop) | [$.fn.get()](#fnget) | | | | | | ||
| [$.fn.toggleClass()](#fntoggleclass) | [$.fn.index()](#fnindex) | | | | | | ||
| | [$.fn.last()](#fnlast) | | | | | | ||
| Forms | Manipulation | Offset | Traversal | | ||
| ----- | ------------ | ------ | --------- | | ||
| [$.fn.serialize()](#fnserialize) | [$.fn.after()](#fnafter) | [$.fn.offset()](#fnoffset) | [$.fn.children()](#fnchildren) | | ||
| [$.fn.val()](#fnval) | [$.fn.append()](#fnappend) | [$.fn.offsetParent()](#fnoffsetparent) | [$.fn.closest()](#fnclosest) | | ||
| | [$.fn.appendTo()](#fnappendto) | [$.fn.position()](#fnposition) | [$.fn.find()](#fnfind) | | ||
| | [$.fn.before()](#fnbefore) | | [$.fn.has()](#fnhas) | | ||
| | [$.fn.clone()](#fnclone) | | [$.fn.is()](#fnis) | | ||
| | [$.fn.empty()](#fnempty) | | [$.fn.next()](#fnnext) | | ||
| | [$.fn.html()](#fnhtml) | | [$.fn.not()](#fnnot) | | ||
| | [$.fn.insertAfter()](#fninsertafter) | | [$.fn.parent()](#fnparent) | | ||
| | [$.fn.insertBefore()](#fninsertbefore) | | [$.fn.parents()](#fnparents) | | ||
| | [$.fn.prepend()](#fnprepend) | | [$.fn.prev()](#fnprev) | | ||
| | [$.fn.prependTo()](#fnprependto) | | [$.fn.siblings()](#fnsiblings) | | ||
| | [$.fn.remove()](#fnremove) | | | | ||
| | [$.fn.text()](#fntext) | | | | ||
### Utilities | ||
| Type Checking | Utilities | | ||
| ------------- | --------- | | ||
| [$.isArray()](#isarray) | [$.each()](#each) | | ||
| [$.isFunction()](#isfunction) | [$.extend()](#extend) | | ||
| [$.isNumeric()](#isnumeric) | [$.matches()](#matches) | | ||
| [$.isString()](#isstring) | [$.parseHTML()](#parsehtml) | | ||
---- | ||
## Collection Methods | ||
#### $.fn | ||
The main prototype. Adding properties and methods will add it to all collections. | ||
The main prototype for collections, allowing you to extend cash with plugins | ||
by adding methods to all collections. | ||
```js | ||
$.fn // => cash.prototype | ||
$.fn.myMethod = function(){ }; // Custom method added to all collections | ||
$.fn.extend(object); // Add multiple methods to the prototype. | ||
``` | ||
@@ -167,4 +235,6 @@ | ||
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. | ||
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. Multiple data can be set when | ||
an object is supplied. | ||
@@ -174,2 +244,3 @@ ```js | ||
$(element).data(key, value) // => collection | ||
$(element).data(object) // => collection | ||
``` | ||
@@ -359,2 +430,18 @@ | ||
#### $.fn.offset() | ||
Get the coordinates of the first element in a collection relative to the document. | ||
```js | ||
$(element).offset() // => Object | ||
``` | ||
#### $.fn.offsetParent() | ||
Get the first element's ancestor that's positioned. | ||
```js | ||
$(element).offsetParent() // => collection | ||
``` | ||
#### $.fn.on() | ||
@@ -415,2 +502,10 @@ | ||
#### $.fn.position() | ||
Get the coordinates of the first element in a collection relative to its `offsetParent`. | ||
```js | ||
$(element).position() // => object | ||
``` | ||
#### $.fn.prepend() | ||
@@ -442,6 +537,10 @@ | ||
Returns property value. | ||
Returns a property value when just property is supplied. Sets a property | ||
when property and value are supplied, and sets multiple properties when an object | ||
is supplied. | ||
```js | ||
$(element).prop(property) // => Property value | ||
$(element).prop(property) // => property value | ||
$(element).prop(property, value) // => collection | ||
$(element).prop(object) // => collection | ||
``` | ||
@@ -476,5 +575,6 @@ | ||
Removes className from collection elements. Accepts space-separated classNames | ||
for removing multiple classes. | ||
for removing multiple classes. Providing no arguments will remove all classes. | ||
```js | ||
$(element).removeClass() // => collection | ||
$(element).removeClass(className) // => collection | ||
@@ -491,4 +591,12 @@ ``` | ||
#### $.fn.serialize | ||
#### $.fn.removeProp() | ||
Removes property from collection elements. | ||
```js | ||
$(element).removeProp(propName) // => collection | ||
``` | ||
#### $.fn.serialize() | ||
When called on a form, serializes and returns form data. | ||
@@ -529,11 +637,12 @@ | ||
#### $.fn.trigger | ||
#### $.fn.trigger() | ||
Triggers supplied event on elements in collection. | ||
Triggers supplied event on elements in collection. Data can be passed along as the second parameter. | ||
```js | ||
$(element).trigger(eventName) // => collection | ||
$(element).trigger(eventName,data) // => collection | ||
``` | ||
#### $.fn.val | ||
#### $.fn.val() | ||
@@ -548,3 +657,3 @@ Returns an inputs value. If value is supplied, sets all inputs in collection's | ||
#### $.fn.width | ||
#### $.fn.width() | ||
@@ -559,35 +668,35 @@ Returns the width of the element. | ||
### Utilities | ||
### Type Checking | ||
#### $.each() | ||
#### $.isArray() | ||
Iterates through a collection and calls the callback method on each. | ||
Check if the argument is an array. | ||
```js | ||
$.each(collection, callback) // => collection | ||
$.isArray([1,2,3]) // => true | ||
``` | ||
#### $.extend() | ||
#### $.isFunction() | ||
Extends target object with properties from the source object. If no target is provided, | ||
cash itself will be extended. | ||
Check if the argument is a function. | ||
```js | ||
$.extend(target,source) // => object | ||
var func = function(){}; | ||
$.isFunction(func) // => true | ||
``` | ||
#### $.matches() | ||
#### $.isNumeric() | ||
Checks a selector against an element, returning a boolean value for match. | ||
Check if the argument is numeric. | ||
```js | ||
$.matches(element, selector) // => boolean | ||
$.isNumeric(57) // => true | ||
``` | ||
#### $.parseHTML() | ||
#### $.isString() | ||
Returns a collection from an HTML string. | ||
Check if the argument is a string. | ||
```js | ||
$.parseHTML(htmlString) // => Collection | ||
$.isString('hello') // => true | ||
``` | ||
@@ -597,36 +706,36 @@ | ||
### Type Checking | ||
### Utilities | ||
#### $.isFunction() | ||
#### $.each() | ||
Check if the argument is a function. | ||
Iterates through a collection and calls the callback method on each. | ||
```js | ||
var func = function(){}; | ||
$.isFunction(func) // => true | ||
$.each(collection, callback) // => collection | ||
``` | ||
#### $.isString() | ||
#### $.extend() | ||
Check if the argument is a string. | ||
Extends target object with properties from the source object. If no target is provided, | ||
cash itself will be extended. | ||
```js | ||
$.isString('hello') // => true | ||
$.extend(target,source) // => object | ||
``` | ||
#### $.isArray() | ||
#### $.matches() | ||
Check if the argument is an array. | ||
Checks a selector against an element, returning a boolean value for match. | ||
```js | ||
$.isString([1,2,3]) // => true | ||
$.matches(element, selector) // => boolean | ||
``` | ||
#### $.parseHTML() | ||
#### $.isNumeric(n) | ||
Returns a collection from an HTML string. | ||
Check if the argument is numeric. | ||
```js | ||
$.isNumeric(57) // => true | ||
$.parseHTML(htmlString) // => Collection | ||
``` | ||
@@ -0,1 +1,2 @@ | ||
// @echo header | ||
(function(root, factory) { | ||
@@ -2,0 +3,0 @@ if (typeof define === 'function' && define.amd) { |
var notWhiteMatch = /\S+/g; | ||
function getClasses(c){ | ||
return isString(c) && c.match(notWhiteMatch); | ||
} | ||
function hasClass(v,c) { | ||
@@ -23,24 +27,45 @@ return ( v.classList ? | ||
addClass(c){ | ||
var classes = c.match(notWhiteMatch); | ||
var classes = getClasses(c); | ||
return this.each(v => { | ||
var spacedName = ` ${v.className} `; | ||
each(classes,c => { addClass(v,c,spacedName); }); | ||
}); | ||
return ( classes ? | ||
this.each(v => { | ||
var spacedName = ` ${v.className} `; | ||
each(classes,c => { addClass(v,c,spacedName); }); | ||
}) : | ||
this | ||
); | ||
}, | ||
attr(name, value) { | ||
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; } | ||
}); | ||
if ( !name ) { return undefined; } | ||
if ( isString(name) ) { | ||
if ( value === undefined ) { | ||
return this[0] ? | ||
this[0].getAttribute ? this[0].getAttribute(name) : this[0][name] | ||
: undefined; | ||
} | ||
return this.each(v => { | ||
if ( v.setAttribute ) { v.setAttribute(name, value); } | ||
else { v[name] = value; } | ||
}); | ||
} | ||
for (var key in name) { | ||
this.attr(key,name[key]); | ||
} | ||
return this; | ||
}, | ||
hasClass(c) { | ||
var check = false; | ||
this.each(v => { | ||
check = hasClass(v,c); | ||
return !check; | ||
}); | ||
var check = false, | ||
classes = getClasses(c); | ||
if ( classes && classes.length ) { | ||
this.each(v => { | ||
check = hasClass(v,classes[0]); | ||
return !check; | ||
}); | ||
} | ||
return check; | ||
@@ -50,4 +75,15 @@ }, | ||
prop(name,value) { | ||
if ( !value ) { return this[0][name]; } | ||
return this.each(v => { v[name] = value; }); | ||
if ( isString(name) ) { | ||
return ( value === undefined ? | ||
this[0][name] : | ||
this.each(v => { v[name] = value; }) | ||
); | ||
} | ||
for (var key in name) { | ||
this.prop(key,name[key]); | ||
} | ||
return this; | ||
}, | ||
@@ -63,7 +99,12 @@ | ||
removeClass(c){ | ||
var classes = c.match(notWhiteMatch); | ||
return this.each(v => { | ||
each(classes,c => { removeClass(v,c); }); | ||
}); | ||
if(!arguments.length){ | ||
return this.attr('class',''); | ||
} | ||
var classes = getClasses(c); | ||
return ( classes ? | ||
this.each(v => { | ||
each(classes,c => { removeClass(v,c); }); | ||
}) : | ||
this | ||
); | ||
}, | ||
@@ -76,13 +117,17 @@ | ||
toggleClass(c, state){ | ||
if ( state !== undefined ) { return this[state ? 'addClass' : 'removeClass' ](c); } | ||
var classes = c.match(notWhiteMatch); | ||
return this.each(v => { | ||
var spacedName = ` ${v.className} `; | ||
each(classes,c => { | ||
if ( hasClass(v,c) ) { removeClass(v,c); } else { addClass(v,c,spacedName); } | ||
}); | ||
}); | ||
if ( state !== undefined ) { | ||
return this[ state ? 'addClass' : 'removeClass' ](c); | ||
} | ||
var classes = getClasses(c); | ||
return ( classes ? | ||
this.each(v => { | ||
var spacedName = ` ${v.className} `; | ||
each(classes,c => { | ||
if ( hasClass(v,c) ) { removeClass(v,c); } else { addClass(v,c,spacedName); } | ||
}); | ||
}) : | ||
this | ||
); | ||
}, | ||
}); |
@@ -17,3 +17,3 @@ fn.extend({ | ||
filter(selector) { | ||
return filter.call(this, ( isString(selector) ? e => matches(e, selector) : selector )); | ||
return cash(filter.call(this, ( isString(selector) ? e => matches(e, selector) : selector ))); | ||
}, | ||
@@ -20,0 +20,0 @@ |
@@ -80,3 +80,3 @@ var noop = function(){}, | ||
var fn = cash.fn = cash.prototype = Init.prototype = { | ||
var fn = cash.fn = cash.prototype = Init.prototype = { // jshint ignore:line | ||
constructor: cash, | ||
@@ -83,0 +83,0 @@ cash: true, |
@@ -28,8 +28,19 @@ var uid = cash.uid = '_cash'+Date.now(); | ||
data(key, value) { // TODO: tear out into module for IE9 | ||
if (!value) { return getData(this[0],key); } | ||
return this.each(v => setData(v,key,value) ); | ||
data(name, value) { | ||
if ( isString(name) ) { | ||
return ( value === undefined ? | ||
getData(this[0],name) : | ||
this.each(v => setData(v,name,value) ) | ||
); | ||
} | ||
for (var key in name) { | ||
this.data(key,name[key]); | ||
} | ||
return this; | ||
}, | ||
removeData(key) { // TODO: tear out into module for IE9 | ||
removeData(key) { | ||
return this.each(v => removeData(v,key) ); | ||
@@ -36,0 +47,0 @@ } |
@@ -24,3 +24,3 @@ function registerEvent(node, eventName, callback) { | ||
on(eventName, delegate, callback, runOnce) { | ||
on(eventName, delegate, callback, runOnce) { // jshint ignore:line | ||
@@ -41,3 +41,6 @@ var originalCallback; | ||
if ( eventName === 'ready' ) { onReady(callback); return this; } | ||
if ( eventName === 'ready' ) { | ||
onReady(callback); | ||
return this; | ||
} | ||
@@ -49,15 +52,11 @@ if ( delegate ) { | ||
if (matches(t, delegate)) { | ||
originalCallback.call(t); | ||
} else { | ||
while (!matches(t, delegate)) { | ||
if (t === this) { | ||
return (t = false); | ||
} | ||
t = t.parentNode; | ||
while (!matches(t, delegate)) { | ||
if (t === this) { | ||
return (t = false); | ||
} | ||
t = t.parentNode; | ||
} | ||
if (t) { | ||
originalCallback.call(t); | ||
} | ||
if (t) { | ||
originalCallback.call(t, e); | ||
} | ||
@@ -85,4 +84,5 @@ }; | ||
trigger(eventName) { | ||
trigger(eventName, data) { | ||
var evt = doc.createEvent('HTMLEvents'); | ||
evt.data = data; | ||
evt.initEvent(eventName, true, false); | ||
@@ -89,0 +89,0 @@ return this.each(v => v.dispatchEvent(evt)); |
@@ -33,3 +33,3 @@ cash.extend = fn.extend = function(target) { | ||
function matches(el, selector) { | ||
return ( | ||
var m = el && ( | ||
el.matches || | ||
@@ -40,3 +40,4 @@ el.webkitMatchesSelector || | ||
el.oMatchesSelector | ||
).call(el, selector); | ||
); | ||
return !!m && m.call(el, selector); | ||
} | ||
@@ -43,0 +44,0 @@ |
@@ -34,2 +34,3 @@ // Core | ||
}); | ||
QUnit.test( "className Query for non-existing element", function( assert ) { | ||
@@ -41,3 +42,11 @@ assert.equal($('.i-dont-exist').length, 0, "className for non-existing element Passed!" ); | ||
QUnit.test( "addClass", function( assert ) { | ||
QUnit.test( 'addClass', function( assert ) { | ||
$('.class-fixture').addClass( '' ); | ||
$('.class-fixture').addClass( undefined ); | ||
$('.class-fixture').addClass( null ); | ||
assert.equal( true, true, 'addClass doesn\'t die on falsey' ); | ||
$('.class-fixture').addClass( 4 ); | ||
assert.equal( true, true, 'addClass doesn\'t die on integer' ); | ||
$('.class-fixture').addClass('add-class'); | ||
@@ -58,11 +67,34 @@ assert.equal($('.add-class').length, 1, "addClass Passed!" ); | ||
assert.equal(testAttr, 'get', "attr get Passed!" ); | ||
$('.attr-fixture').attr('success','set'); | ||
testAttr = $('.attr-fixture').attr('success'); | ||
assert.equal(testAttr, 'set', "attr set Passed!" ); | ||
var testReturn = $('.attr-fixture').attr({ 'success': 'set', 'multi-success': 'set' }); | ||
testAttr = [$('.attr-fixture').attr('success'),$('.attr-fixture').attr('multi-success')].join(' '); | ||
assert.equal(testReturn instanceof cash, true, "attr set returns collection!" ); | ||
assert.equal(testAttr, 'set set', "attr set multiple Passed!" ); | ||
testAttr = $('.attr-fixture, .attr-fixture2').attr("nothing"); | ||
assert.equal( testAttr, undefined, "non-existing attribute returns undefined"); | ||
testAttr = $('.attr-fixture').attr(); | ||
assert.equal( testAttr, undefined, "no argument passed returns undefined"); | ||
}); | ||
QUnit.test( "hasClass", function( assert ) { | ||
$('.class-fixture').hasClass( '' ); | ||
$('.class-fixture').hasClass( ' ' ); | ||
$('.class-fixture').hasClass( undefined ); | ||
$('.class-fixture').hasClass( null ); | ||
assert.equal( true, true, 'hasClass doesn\'t die on falsey' ); | ||
$('.class-fixture').hasClass( 4 ); | ||
assert.equal( true, true, 'hasClass doesn\'t die on integer' ); | ||
var hasClass = $('.attr-fixture').hasClass('has-class'); | ||
assert.equal(hasClass, true, "hasClass (true) Passed!" ); | ||
var hasClass = $('.attr-fixture').hasClass('not-a-real-class'); | ||
hasClass = $('.attr-fixture').hasClass('not-a-real-class'); | ||
assert.equal(hasClass, false, "hasClass (false) Passed!" ); | ||
@@ -72,5 +104,14 @@ }); | ||
QUnit.test( "toggleClass", function( assert ) { | ||
$('.class-fixture').toggleClass( '' ); | ||
$('.class-fixture').toggleClass( ' ' ); | ||
$('.class-fixture').toggleClass( undefined ); | ||
$('.class-fixture').toggleClass( null ); | ||
assert.equal( true, true, 'toggleClass doesn\'t die on falsey' ); | ||
$('.class-fixture').toggleClass( 4 ); | ||
assert.equal( true, true, 'toggleClass doesn\'t die on integer' ); | ||
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'); | ||
hasClass = $('.attr-fixture').toggleClass('toggle-class-force',false).hasClass('toggle-class-force'); | ||
assert.equal(hasClass, false, "toggleClass (force remove) Passed!" ); | ||
@@ -84,3 +125,13 @@ var hasClass = $('.attr-fixture').toggleClass('toggle-class').hasClass('toggle-class'); | ||
QUnit.test( "prop", function( assert ) { | ||
assert.equal($('.prop-fixture').prop('checked'), true, "prop Passed!" ); | ||
assert.equal($('.prop-fixture').prop('checked'), true, "prop get Passed!" ); | ||
$('.prop-fixture').prop('checked',false); | ||
assert.equal($('.prop-fixture').prop('checked'), false, "prop set Passed!" ); | ||
$('.prop-fixture').prop({ | ||
'checked': true, | ||
'disabled': true | ||
}); | ||
var testProps = [$('.prop-fixture').prop('checked'),$('.prop-fixture').prop('disabled')].join(' '); | ||
assert.equal(testProps, 'true true', "prop set multiple Passed!" ); | ||
}); | ||
@@ -94,2 +145,12 @@ | ||
QUnit.test( "removeClass", function( assert ) { | ||
var $cf = $('.class-fixture'); | ||
$cf.removeClass( '' ); | ||
$cf.removeClass( ' ' ); | ||
$cf.removeClass( undefined ); | ||
$cf.removeClass( null ); | ||
assert.equal( true, true, 'removeClass doesn\'t die on falsey' ); | ||
$cf.removeClass( 4 ); | ||
assert.equal( true, true, 'removeClass doesn\'t die on integer' ); | ||
$('.attr-fixture').removeClass('has-class'); | ||
@@ -100,2 +161,6 @@ assert.equal( $('.attr-fixture')[0].className, "attr-fixture has-class-two has-class-three", "removeClass Passed!" ); | ||
assert.equal( $('.attr-fixture2')[0].className, "attr-fixture2", "removeClass Multiple Passed!" ); | ||
$cf.removeClass(); | ||
assert.equal( $cf.className, undefined, 'removing all classes passed!' ); | ||
$cf.addClass('class-fixture'); | ||
}); | ||
@@ -114,9 +179,9 @@ | ||
addFixture = $('#id-fixture').add( $('#qunit-fixture a') ).add( $('#qunit-fixture input') ); | ||
assert.equal(addFixture.length, 13, "add(collections) Passed!" ); | ||
assert.equal(addFixture.length, 14, "add(collections) Passed!" ); | ||
addFixture = $('#qunit-fixture a').first().add( $('#qunit-fixture a') ); | ||
assert.equal(addFixture.length, 4, "add(no duplicates) Passed!" ); | ||
assert.equal(addFixture.length, 5, "add(no duplicates) Passed!" ); | ||
addFixture = $('#id-fixture').add( "#qunit-fixture a" ); | ||
assert.equal(addFixture.length, 5, "add(allow selector string) Passed!" ); | ||
assert.equal(addFixture.length, 6, "add(allow selector string) Passed!" ); | ||
}); | ||
@@ -263,2 +328,12 @@ | ||
QUnit.test( "trigger(data)", function( assert ) { | ||
var i = 1; | ||
$('.trigger-data-fixture').on('custom', function(e){ | ||
i += e.data; | ||
this.textContent = i; | ||
}); | ||
$('.trigger-data-fixture').trigger('custom', 1); | ||
assert.equal($('.trigger-data-fixture')[0].textContent, 2, "trigger(data) Passed!" ); | ||
}); | ||
//Forms | ||
@@ -280,3 +355,3 @@ | ||
QUnit.test( "children", function( assert ) { | ||
assert.equal($('#qunit-fixture').children().length, 14, "children Passed!" ); | ||
assert.equal($('#qunit-fixture').children().length, 15, "children Passed!" ); | ||
assert.equal($('#qunit-fixture').children('div').length, 6, "children(selector) Passed!" ); | ||
@@ -322,3 +397,3 @@ }); | ||
QUnit.test( "siblings", function( assert ) { | ||
assert.equal($('#id-fixture').siblings().length, 13, "siblings Passed!" ); | ||
assert.equal($('#id-fixture').siblings().length, 14, "siblings Passed!" ); | ||
}); | ||
@@ -325,0 +400,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
91734
1825
727
0