diff --git a/dist/carty.js b/dist/carty.js index c6eb58e..7bcfccf 100644 --- a/dist/carty.js +++ b/dist/carty.js @@ -1,5 +1,5 @@ /*! - * Carty - v0.5.0 - 2016-01-05 + * Carty - v0.5.1 - 2016-01-07 * http://sorgalla.com/carty/ * Copyright (c) 2015-2016 Jan Sorgalla; Licensed MIT */ @@ -133,9 +133,9 @@ return /******/ (function(modules) { // webpackBootstrap var _items = []; var _ready; - cart.on(['load', 'add', 'update', 'remove', 'clear'], emit.bind(undefined, 'change')); - cart.on(['loaded', 'added', 'updated', 'removed', 'cleared'], emit.bind(undefined, 'changed')); - cart.on(['loadfailed', 'addfailed', 'updatefailed', 'removefailed', 'clearfailed'], emit.bind(undefined, 'changefailed')); + cart.on(['load', 'add', 'update', 'remove', 'clear', 'checkout'], emit.bind(undefined, 'change')); + cart.on(['loaded', 'added', 'updated', 'removed', 'cleared', 'checkedout'], emit.bind(undefined, 'changed')); + cart.on(['loadfailed', 'addfailed', 'updatefailed', 'removefailed', 'clearfailed', 'checkoutfailed'], emit.bind(undefined, 'changefailed')); cart.options = options.bind(cart, _options); @@ -189,6 +189,12 @@ return /******/ (function(modules) { // webpackBootstrap return cart; }; + cart.checkout = function(data) { + ready(checkout.bind(cart, data)); + + return cart; + }; + cart.load = function() { if (!_ready) { _ready = load(); @@ -429,6 +435,21 @@ return /******/ (function(modules) { // webpackBootstrap }); } + function checkout(data) { + return emit('checkout').then(function() { + return resolve( + _options.storage && _options.storage.checkout && _options.storage.checkout(data, cart) + ).then(emit.bind(cart, 'checkedout'), function(e) { + emit('checkoutfailed', e); + return reject(e); + })['catch'](function() { + // Catch checkedout event listener rejections + }); + }, function() { + // Catch checkout event listener rejections + }); + } + function normalize(attr) { if (type(attr) === 'function') { attr = attr(cart); diff --git a/dist/carty.min.js b/dist/carty.min.js index 7622e9d..8e44385 100644 --- a/dist/carty.min.js +++ b/dist/carty.min.js @@ -1,6 +1,6 @@ /*! - * Carty - v0.5.0 - 2016-01-05 + * Carty - v0.5.1 - 2016-01-07 * http://sorgalla.com/carty/ * Copyright (c) 2015-2016 Jan Sorgalla; Licensed MIT */ -!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],n):"object"==typeof exports?exports.carty=n(require("jquery")):t.carty=n(t.jQuery)}(this,function(t){return function(t){function n(r){if(e[r])return e[r].exports;var i=e[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};return n.m=t,n.c=e,n.p="/",n(0)}([function(t,n,e){"use strict";var r=e(1);r.format={currency:e(8),number:e(10)},r.storage={localStorage:e(12)},r.ui={jquery:e(13)},t.exports=r},function(t,n,e){"use strict";function r(t){function n(){return{size:n.size(),quantity:n.quantity(),subtotal:n.subtotal(),shipping:n.shipping(),tax:n.tax(),total:n.total(),items:O.map(function(t){return t()})}}function e(t){j||(j=x()),j["catch"](function(t){setTimeout(function(){throw t})}),j=j.then(function(){return t(n)})}function r(t){j||(j=x()),j=j["catch"](function(e){return t(e,n)})}function x(){return $("load").then(function(){return s(S.storage&&S.storage.load()).then(function(t){"array"===c(t)&&(O=t.map(function(t){return D(t)}))}).then($.bind(n,"loaded"),function(t){return $("loadfailed",t),p(t)})},function(){})}function m(t){var n,e=!1;try{n=D(t).call()}catch(r){return!1}return O.every(function(t,r){return t.equals(n)&&(e={item:t,index:r}),!e}),e}function v(t){return $("update",t).then(function(){var e=m(t);if(e){var r=e.item.merge(t),i=r();return i.quantity<1?h(i):(O[e.index]=r,s(S.storage&&S.storage.put(i,n)).then($.bind(n,"updated",i),function(t){return $("updatefailed",t,i),p(t)})["catch"](function(){}))}},function(){})}function g(t){return $("add",t).then(function(){var e=D(t),r=m(t);r&&(t=i({},t,{quantity:r.item().quantity+e().quantity}),e=r.item.merge(t));var u=e();return u.quantity<1?h(u):(r?O[r.index]=e:O.push(e),s(S.storage&&S.storage.put(u,n)).then($.bind(n,"added",u),function(t){return $("addfailed",t,u),p(t)})["catch"](function(){}))},function(){})}function h(t){return $("remove",t).then(function(){var e=m(t);if(e){O.splice(e.index,1);var r=e.item();return s(S.storage&&S.storage.remove(r,n)).then($.bind(n,"removed",r),function(t){return $("removefailed",t,r),p(t)})["catch"](function(){})}},function(){})}function b(){return $("clear").then(function(){return O.length=0,s(S.storage&&S.storage.clear()).then($.bind(n,"cleared"),function(t){return $("clearfailed",t),p(t)})["catch"](function(){})},function(){})}function y(t){return"function"===c(t)&&(t=t(n)),"object"!==c(t)?{id:t}:t}function D(t){function n(){return i({},r,{id:r.id,label:r.label||r.id,quantity:o(r.quantity,S),price:o(r.price,S),variant:e()})}function e(){return null==r.variant?{}:"object"!==c(r.variant)?{variant:r.variant}:r.variant}var r=i({},l,y(t));if(!r.id)throw"Item must be a string or an object with at least an id property.";return n.merge=function(t){return D(i({},r,y(t)))},n.equals=function(t){function n(t){return f[t]===o[t]}try{var i=D(t).call()}catch(u){return!1}if(i.id!==r.id)return!1;var o=e(),f=i.variant;return Object.keys(o).every(n)&&Object.keys(f).every(n)},n}var j,$=u(n),S=i({},d,t),O=[];return n.on(["load","add","update","remove","clear"],$.bind(void 0,"change")),n.on(["loaded","added","updated","removed","cleared"],$.bind(void 0,"changed")),n.on(["loadfailed","addfailed","updatefailed","removefailed","clearfailed"],$.bind(void 0,"changefailed")),n.options=f.bind(n,S),n.ready=function(t){return e(t),n},n.error=function(t){return r(t),n},n.size=function(){return O.length},n.has=function(t){return!!m(t)},n.get=function(t){var n=m(t);return n?n.item():null},n.add=function(t){return e(g.bind(n,t)),n},n.update=function(t){return e(v.bind(n,t)),n},n.remove=function(t){return e(h.bind(n,t)),n},n.clear=function(){return e(b),n},n.load=function(){return j?e(x):j=x(),n},n.changed=function(){return j?e($.bind(void 0,"changed")):j=$("changed"),n},n.each=function(t,e){return O.every(function(r,i){return!1!==t.call(e,r(),i,n)}),n},n.quantity=function(){return O.reduce(function(t,n){return t+n().quantity},0)},n.subtotal=function(){var t=O.map(function(t){return t()});return o(a(S.subtotal,void 0,[t,n]),S)},n.shipping=function(){return n.size()?o(a(S.shipping,void 0,[n]),S):0},n.tax=function(){return n.size()?o(a(S.tax,void 0,[n]),S):0},n.total=function(){return n.subtotal()+n.tax()+n.shipping()},n.item=function(t){return D(t)},n}t.exports=r;var i=e(2),u=e(3),o=e(5),f=e(6),a=e(7),c=e(4),s=Promise.resolve.bind(Promise),p=Promise.reject.bind(Promise),d={storage:null,subtotal:function(t){return t.reduce(function(t,n){return t+n.price*n.quantity},0)},shipping:null,tax:null},l={quantity:1};r.options=f.bind(r,d)},function(t,n){"use strict";var e=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===r.call(t)},u=function(t){if(!t||"[object Object]"!==r.call(t))return!1;var n=e.call(t,"constructor"),i=t.constructor&&t.constructor.prototype&&e.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!n&&!i)return!1;var u;for(u in t);return"undefined"==typeof u||e.call(t,u)};t.exports=function o(){var t,n,e,r,f,a,c=arguments[0],s=1,p=arguments.length,d=!1;for("boolean"==typeof c?(d=c,c=arguments[1]||{},s=2):("object"!=typeof c&&"function"!=typeof c||null==c)&&(c={});p>s;++s)if(t=arguments[s],null!=t)for(n in t)e=c[n],r=t[n],c!==r&&(d&&r&&(u(r)||(f=i(r)))?(f?(f=!1,a=e&&i(e)?e:[]):a=e&&u(e)?e:{},c[n]=o(d,a,r)):"undefined"!=typeof r&&(c[n]=r));return c}},function(t,n,e){"use strict";function r(t){return"array"===u(t)}function i(t){var n={};return t.on=function(e,i){return r(e)?e.forEach(function(n){t.on(n,i)}):(n["$"+e]=n["$"+e]||[]).push(i),t},t.once=function(n,e){function i(){t.off(n,i),e.apply(t,arguments)}return r(n)?(n.forEach(function(n){t.once(n,e)}),t):(i.fn=e,t.on(n,i),t)},t.off=function(e,i){if(0==arguments.length)return n={},t;if(r(e))return e.forEach(function(n){t.off(n,i)}),t;var u=n["$"+e];if(!u)return t;if(1==arguments.length)return delete n["$"+e],t;for(var o,f=0;f-1)if(u>-1&&o>u)e=",";else if(-1===u){var f=r.substr(o+1).length;f>0&&3>f&&(e=",")}u>-1&&o>-1&&o>u?e=",":-1===u&&o>-1&&r.substr(o+1).length<3&&(e=",");var a=new RegExp("[^0-9-"+e+"]",["g"]);return parseFloat(r.replace(/\(([^-]+)\)/,"-$1").replace(a,"").replace(e,"."))||0}t.exports=e;var i=Number.isFinite||function(t){return"number"==typeof t&&isFinite(t)};e.configure=function(t){return r.bind(void 0,t)}},function(t,n,e){"use strict";function r(t,n,e){if(1===arguments.length)return i(!0,{},t);if("string"===u(n)){if("undefined"===u(e))return"undefined"===u(t[n])?null:t[n];t[n]=e}else i(t,n);return this}t.exports=r;var i=e(2),u=e(4)},function(t,n,e){"use strict";function r(t,n,e){return"function"===i(t)?t.apply(n,e||[]):t}t.exports=r;var i=e(4)},function(t,n,e){"use strict";function r(t,n){return i(n,t)}function i(t,n){t=t||{};var e=t.currency,r=t.currencies||o,i=r[e]||{suffix:e?" "+e:""},a=u({precision:2},i,t);return f(n,a)}t.exports=r;var u=e(2),o=e(9),f=e(10);r.configure=function(t){return i.bind(void 0,t)}},function(t,n){"use strict";t.exports={AED:{prefix:"ج"},ANG:{prefix:"ƒ"},ARS:{prefix:"$",suffix:" ARS"},AUD:{prefix:"$",suffix:" AUD"},AWG:{prefix:"ƒ"},BBD:{prefix:"$",suffix:" BBD"},BGN:{prefix:"лв"},BTC:{suffix:" BTC",precision:4},BMD:{prefix:"$",suffix:" BMD"},BND:{prefix:"$",suffix:" BND"},BRL:{prefix:"R$"},BSD:{prefix:"$",suffix:" BSD"},CAD:{prefix:"$",suffix:" CAD"},CHF:{suffix:" CHF"},CLP:{prefix:"$",suffix:" CLP"},CNY:{prefix:"¥"},COP:{prefix:"$",suffix:" COP"},CRC:{prefix:"₡"},CZK:{prefix:"Kc"},DKK:{prefix:"kr"},DOP:{prefix:"$",suffix:" DOP"},EEK:{prefix:"kr"},EUR:{prefix:"€"},GBP:{prefix:"£"},GTQ:{prefix:"Q"},HKD:{prefix:"$",suffix:" HKD"},HRK:{prefix:"kn"},HUF:{prefix:"Ft"},IDR:{prefix:"Rp"},ILS:{prefix:"₪"},INR:{prefix:"Rs."},ISK:{prefix:"kr"},JMD:{prefix:"J$"},JPY:{prefix:"¥",precision:0},KRW:{prefix:"₩"},KYD:{prefix:"$",suffix:" KYD"},LTL:{prefix:"Lt"},LVL:{prefix:"Ls"},MXN:{prefix:"$",suffix:" MXN"},MYR:{prefix:"RM"},NOK:{prefix:"kr"},NZD:{prefix:"$",suffix:" NZD"},PEN:{prefix:"S/"},PHP:{prefix:"Php"},PLN:{prefix:"z"},QAR:{prefix:"﷼"},RON:{prefix:"lei"},RUB:{prefix:"руб"},SAR:{prefix:"﷼"},SEK:{prefix:"kr"},SGD:{prefix:"$",suffix:" SGD"},THB:{prefix:"฿"},TRY:{prefix:"TL"},TTD:{prefix:"TT$"},TWD:{prefix:"NT$"},UAH:{prefix:"₴"},USD:{prefix:"$"},UYU:{prefix:"$U"},VEF:{prefix:"Bs"},VND:{prefix:"₫"},XCD:{prefix:"$",suffix:" XCD"},ZAR:{prefix:"R"}}},function(t,n,e){"use strict";function r(t,n){return i(n,t)}function i(t,n){var e=u(n);t=t||{};var r,i,a,c,s=0>e,p=e+"",d=t.precision,l=t.decimalSeparator||".",x=t.groupingSeparator,m="number"===f(t.groupingSize)?t.groupingSize:3;if("number"===f(d)&&(p=o(e,d)),"."!==l&&(p=p.replace(".",l)),x){for(r=p.lastIndexOf(l),r=r>-1?r:p.length,i=p.substring(r),a=0,c=r;c>0;c--)a%m===0&&c!==r&&(!s||c>1)&&(i=x+i),i=p.charAt(c-1)+i,a++;p=i}return(t.prefix||"")+p+(t.suffix||"")}t.exports=r;var u=e(5),o=e(11),f=e(4);r.configure=function(t){return i.bind(void 0,t)}},function(t,n){"use strict";function e(t,n,e){return r(e,t,n)}function r(t,n,e){var r=t&&t.roundingFunction||Math.round,i=Math.pow(10,e||0);return(r(n*i)/i).toFixed(e)}t.exports=e,e.configure=function(t){return r.bind(void 0,t)}},function(t,n){"use strict";function e(t,n){function e(e,r){n.setItem(t,JSON.stringify(r().items))}return t=t||"carty",n=n||window.localStorage,{load:function(){try{return JSON.parse(n.getItem(t))}catch(e){return[]}},put:e,remove:e,clear:function(){n.removeItem(t)}}}t.exports=e},function(t,n,e){"use strict";function r(t,n){function e(t){return x.namespace+"-"+t}function r(t){return"data-"+e(t)}function a(t){return"["+r(t)+"]"}function c(t){return"object"!==i.type(t)?{}:t}function s(t,n){t.filter(o).val(n).end().filter("a").attr("href",n).end().filter("img").attr("src",n).end().not(o).not("img").not("a").text(n)}function p(t,n){return t.data(n)||t.val()||t.attr("href")||t.attr("src")||i.trim(t.text())||null}function d(t,n){function e(){var t=i(this);(!t.is(":checkbox,:radio")||t.is(":checked"))&&i.each(this.attributes,function(){if(!(this.name.indexOf(g)<0)){var n=t.attr("name"),e=p(t,this.name.substr(f));this.name.indexOf(h)>-1?(n||this.name.indexOf(b)>=0?a[n||this.name.substr(b.length)]=e:i.extend(a,e),s=!0):u[n||this.name.substr(g.length)]=e}})}var r=t,u={},a={},s=!1;if(r.is(m)||(r=t.closest(m)),r.each(e),r.find("*").each(e),s&&i.extend(u,{variant:a}),n=c(n),t.is(o)){var d=t.attr("name");d&&(n[d]=t.val())}return i.extend(u,c(r.data(v)),n)}function l(){i.each(["size","quantity"],function(n,e){s(i(a(e)),x.numberFormatter(t[e]()))}),i.each(["subtotal","shipping","tax","total"],function(n,e){s(i(a(e)),x.currencyFormatter(t[e]()))})}var x=i.extend({},u,n),m=a("item"),v=e("item"),g=r("item-"),h=r("item-variant"),b=r("item-variant-"),y=e("add"),D=a("add"),j=a("add")+":not("+o+")",$=a("add")+o,S=e("update"),O=a("update"),P=a("update")+":not("+o+")",R=a("update")+o,q=a("remove"),A=e("remove"),N=a("clear"),B=function(n){var e=i(n.target);e.is(D)&&t.add(d(e,e.data(y)))},C=function(n){var e=i(n.target);e.is(O)&&t.update(d(e,e.data(S)))};return i(document).on("click",j,B).on("change",$,B).on("click",P,C).on("change",R,C).on("click",q,function(n){var e=i(n.target);e.is(q)&&t.remove(d(e,e.data(A)))}).on("click",N,function(){t.clear()}),i(function(){t.ready(function(){l(),t.on("changed",l)})}),l}t.exports=r;var i=e(14),u={namespace:"carty",numberFormatter:function(t){return t},currencyFormatter:function(t){return t}},o="input,select,textarea",f="data-".length},function(n,e){n.exports=t}])}); \ No newline at end of file +!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],n):"object"==typeof exports?exports.carty=n(require("jquery")):t.carty=n(t.jQuery)}(this,function(t){return function(t){function n(r){if(e[r])return e[r].exports;var i=e[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var e={};return n.m=t,n.c=e,n.p="/",n(0)}([function(t,n,e){"use strict";var r=e(1);r.format={currency:e(8),number:e(10)},r.storage={localStorage:e(12)},r.ui={jquery:e(13)},t.exports=r},function(t,n,e){"use strict";function r(t){function n(){return{size:n.size(),quantity:n.quantity(),subtotal:n.subtotal(),shipping:n.shipping(),tax:n.tax(),total:n.total(),items:O.map(function(t){return t()})}}function e(t){$||($=x()),$["catch"](function(t){setTimeout(function(){throw t})}),$=$.then(function(){return t(n)})}function r(t){$||($=x()),$=$["catch"](function(e){return t(e,n)})}function x(){return k("load").then(function(){return s(S.storage&&S.storage.load()).then(function(t){"array"===a(t)&&(O=t.map(function(t){return j(t)}))}).then(k.bind(n,"loaded"),function(t){return k("loadfailed",t),p(t)})},function(){})}function h(t){var n,e=!1;try{n=j(t).call()}catch(r){return!1}return O.every(function(t,r){return t.equals(n)&&(e={item:t,index:r}),!e}),e}function m(t){return k("update",t).then(function(){var e=h(t);if(e){var r=e.item.merge(t),i=r();return i.quantity<1?g(i):(O[e.index]=r,s(S.storage&&S.storage.put(i,n)).then(k.bind(n,"updated",i),function(t){return k("updatefailed",t,i),p(t)})["catch"](function(){}))}},function(){})}function v(t){return k("add",t).then(function(){var e=j(t),r=h(t);r&&(t=i({},t,{quantity:r.item().quantity+e().quantity}),e=r.item.merge(t));var u=e();return u.quantity<1?g(u):(r?O[r.index]=e:O.push(e),s(S.storage&&S.storage.put(u,n)).then(k.bind(n,"added",u),function(t){return k("addfailed",t,u),p(t)})["catch"](function(){}))},function(){})}function g(t){return k("remove",t).then(function(){var e=h(t);if(e){O.splice(e.index,1);var r=e.item();return s(S.storage&&S.storage.remove(r,n)).then(k.bind(n,"removed",r),function(t){return k("removefailed",t,r),p(t)})["catch"](function(){})}},function(){})}function b(){return k("clear").then(function(){return O.length=0,s(S.storage&&S.storage.clear()).then(k.bind(n,"cleared"),function(t){return k("clearfailed",t),p(t)})["catch"](function(){})},function(){})}function y(t){return k("checkout").then(function(){return s(S.storage&&S.storage.checkout&&S.storage.checkout(t,n)).then(k.bind(n,"checkedout"),function(t){return k("checkoutfailed",t),p(t)})["catch"](function(){})},function(){})}function D(t){return"function"===a(t)&&(t=t(n)),"object"!==a(t)?{id:t}:t}function j(t){function n(){return i({},r,{id:r.id,label:r.label||r.id,quantity:o(r.quantity,S),price:o(r.price,S),variant:e()})}function e(){return null==r.variant?{}:"object"!==a(r.variant)?{variant:r.variant}:r.variant}var r=i({},l,D(t));if(!r.id)throw"Item must be a string or an object with at least an id property.";return n.merge=function(t){return j(i({},r,D(t)))},n.equals=function(t){function n(t){return c[t]===o[t]}try{var i=j(t).call()}catch(u){return!1}if(i.id!==r.id)return!1;var o=e(),c=i.variant;return Object.keys(o).every(n)&&Object.keys(c).every(n)},n}var $,k=u(n),S=i({},d,t),O=[];return n.on(["load","add","update","remove","clear","checkout"],k.bind(void 0,"change")),n.on(["loaded","added","updated","removed","cleared","checkedout"],k.bind(void 0,"changed")),n.on(["loadfailed","addfailed","updatefailed","removefailed","clearfailed","checkoutfailed"],k.bind(void 0,"changefailed")),n.options=c.bind(n,S),n.ready=function(t){return e(t),n},n.error=function(t){return r(t),n},n.size=function(){return O.length},n.has=function(t){return!!h(t)},n.get=function(t){var n=h(t);return n?n.item():null},n.add=function(t){return e(v.bind(n,t)),n},n.update=function(t){return e(m.bind(n,t)),n},n.remove=function(t){return e(g.bind(n,t)),n},n.clear=function(){return e(b),n},n.checkout=function(t){return e(y.bind(n,t)),n},n.load=function(){return $?e(x):$=x(),n},n.changed=function(){return $?e(k.bind(void 0,"changed")):$=k("changed"),n},n.each=function(t,e){return O.every(function(r,i){return!1!==t.call(e,r(),i,n)}),n},n.quantity=function(){return O.reduce(function(t,n){return t+n().quantity},0)},n.subtotal=function(){var t=O.map(function(t){return t()});return o(f(S.subtotal,void 0,[t,n]),S)},n.shipping=function(){return n.size()?o(f(S.shipping,void 0,[n]),S):0},n.tax=function(){return n.size()?o(f(S.tax,void 0,[n]),S):0},n.total=function(){return n.subtotal()+n.tax()+n.shipping()},n.item=function(t){return j(t)},n}t.exports=r;var i=e(2),u=e(3),o=e(5),c=e(6),f=e(7),a=e(4),s=Promise.resolve.bind(Promise),p=Promise.reject.bind(Promise),d={storage:null,subtotal:function(t){return t.reduce(function(t,n){return t+n.price*n.quantity},0)},shipping:null,tax:null},l={quantity:1};r.options=c.bind(r,d)},function(t,n){"use strict";var e=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===r.call(t)},u=function(t){if(!t||"[object Object]"!==r.call(t))return!1;var n=e.call(t,"constructor"),i=t.constructor&&t.constructor.prototype&&e.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!n&&!i)return!1;var u;for(u in t);return"undefined"==typeof u||e.call(t,u)};t.exports=function o(){var t,n,e,r,c,f,a=arguments[0],s=1,p=arguments.length,d=!1;for("boolean"==typeof a?(d=a,a=arguments[1]||{},s=2):("object"!=typeof a&&"function"!=typeof a||null==a)&&(a={});p>s;++s)if(t=arguments[s],null!=t)for(n in t)e=a[n],r=t[n],a!==r&&(d&&r&&(u(r)||(c=i(r)))?(c?(c=!1,f=e&&i(e)?e:[]):f=e&&u(e)?e:{},a[n]=o(d,f,r)):"undefined"!=typeof r&&(a[n]=r));return a}},function(t,n,e){"use strict";function r(t){return"array"===u(t)}function i(t){var n={};return t.on=function(e,i){return r(e)?e.forEach(function(n){t.on(n,i)}):(n["$"+e]=n["$"+e]||[]).push(i),t},t.once=function(n,e){function i(){t.off(n,i),e.apply(t,arguments)}return r(n)?(n.forEach(function(n){t.once(n,e)}),t):(i.fn=e,t.on(n,i),t)},t.off=function(e,i){if(0==arguments.length)return n={},t;if(r(e))return e.forEach(function(n){t.off(n,i)}),t;var u=n["$"+e];if(!u)return t;if(1==arguments.length)return delete n["$"+e],t;for(var o,c=0;c-1)if(u>-1&&o>u)e=",";else if(-1===u){var c=r.substr(o+1).length;c>0&&3>c&&(e=",")}u>-1&&o>-1&&o>u?e=",":-1===u&&o>-1&&r.substr(o+1).length<3&&(e=",");var f=new RegExp("[^0-9-"+e+"]",["g"]);return parseFloat(r.replace(/\(([^-]+)\)/,"-$1").replace(f,"").replace(e,"."))||0}t.exports=e;var i=Number.isFinite||function(t){return"number"==typeof t&&isFinite(t)};e.configure=function(t){return r.bind(void 0,t)}},function(t,n,e){"use strict";function r(t,n,e){if(1===arguments.length)return i(!0,{},t);if("string"===u(n)){if("undefined"===u(e))return"undefined"===u(t[n])?null:t[n];t[n]=e}else i(t,n);return this}t.exports=r;var i=e(2),u=e(4)},function(t,n,e){"use strict";function r(t,n,e){return"function"===i(t)?t.apply(n,e||[]):t}t.exports=r;var i=e(4)},function(t,n,e){"use strict";function r(t,n){return i(n,t)}function i(t,n){t=t||{};var e=t.currency,r=t.currencies||o,i=r[e]||{suffix:e?" "+e:""},f=u({precision:2},i,t);return c(n,f)}t.exports=r;var u=e(2),o=e(9),c=e(10);r.configure=function(t){return i.bind(void 0,t)}},function(t,n){"use strict";t.exports={AED:{prefix:"ج"},ANG:{prefix:"ƒ"},ARS:{prefix:"$",suffix:" ARS"},AUD:{prefix:"$",suffix:" AUD"},AWG:{prefix:"ƒ"},BBD:{prefix:"$",suffix:" BBD"},BGN:{prefix:"лв"},BTC:{suffix:" BTC",precision:4},BMD:{prefix:"$",suffix:" BMD"},BND:{prefix:"$",suffix:" BND"},BRL:{prefix:"R$"},BSD:{prefix:"$",suffix:" BSD"},CAD:{prefix:"$",suffix:" CAD"},CHF:{suffix:" CHF"},CLP:{prefix:"$",suffix:" CLP"},CNY:{prefix:"¥"},COP:{prefix:"$",suffix:" COP"},CRC:{prefix:"₡"},CZK:{prefix:"Kc"},DKK:{prefix:"kr"},DOP:{prefix:"$",suffix:" DOP"},EEK:{prefix:"kr"},EUR:{prefix:"€"},GBP:{prefix:"£"},GTQ:{prefix:"Q"},HKD:{prefix:"$",suffix:" HKD"},HRK:{prefix:"kn"},HUF:{prefix:"Ft"},IDR:{prefix:"Rp"},ILS:{prefix:"₪"},INR:{prefix:"Rs."},ISK:{prefix:"kr"},JMD:{prefix:"J$"},JPY:{prefix:"¥",precision:0},KRW:{prefix:"₩"},KYD:{prefix:"$",suffix:" KYD"},LTL:{prefix:"Lt"},LVL:{prefix:"Ls"},MXN:{prefix:"$",suffix:" MXN"},MYR:{prefix:"RM"},NOK:{prefix:"kr"},NZD:{prefix:"$",suffix:" NZD"},PEN:{prefix:"S/"},PHP:{prefix:"Php"},PLN:{prefix:"z"},QAR:{prefix:"﷼"},RON:{prefix:"lei"},RUB:{prefix:"руб"},SAR:{prefix:"﷼"},SEK:{prefix:"kr"},SGD:{prefix:"$",suffix:" SGD"},THB:{prefix:"฿"},TRY:{prefix:"TL"},TTD:{prefix:"TT$"},TWD:{prefix:"NT$"},UAH:{prefix:"₴"},USD:{prefix:"$"},UYU:{prefix:"$U"},VEF:{prefix:"Bs"},VND:{prefix:"₫"},XCD:{prefix:"$",suffix:" XCD"},ZAR:{prefix:"R"}}},function(t,n,e){"use strict";function r(t,n){return i(n,t)}function i(t,n){var e=u(n);t=t||{};var r,i,f,a,s=0>e,p=e+"",d=t.precision,l=t.decimalSeparator||".",x=t.groupingSeparator,h="number"===c(t.groupingSize)?t.groupingSize:3;if("number"===c(d)&&(p=o(e,d)),"."!==l&&(p=p.replace(".",l)),x){for(r=p.lastIndexOf(l),r=r>-1?r:p.length,i=p.substring(r),f=0,a=r;a>0;a--)f%h===0&&a!==r&&(!s||a>1)&&(i=x+i),i=p.charAt(a-1)+i,f++;p=i}return(t.prefix||"")+p+(t.suffix||"")}t.exports=r;var u=e(5),o=e(11),c=e(4);r.configure=function(t){return i.bind(void 0,t)}},function(t,n){"use strict";function e(t,n,e){return r(e,t,n)}function r(t,n,e){var r=t&&t.roundingFunction||Math.round,i=Math.pow(10,e||0);return(r(n*i)/i).toFixed(e)}t.exports=e,e.configure=function(t){return r.bind(void 0,t)}},function(t,n){"use strict";function e(t,n){function e(e,r){n.setItem(t,JSON.stringify(r().items))}return t=t||"carty",n=n||window.localStorage,{load:function(){try{return JSON.parse(n.getItem(t))}catch(e){return[]}},put:e,remove:e,clear:function(){n.removeItem(t)}}}t.exports=e},function(t,n,e){"use strict";function r(t,n){function e(t){return x.namespace+"-"+t}function r(t){return"data-"+e(t)}function f(t){return"["+r(t)+"]"}function a(t){return"object"!==i.type(t)?{}:t}function s(t,n){t.filter(o).val(n).end().filter("a").attr("href",n).end().filter("img").attr("src",n).end().not(o).not("img").not("a").text(n)}function p(t,n){return t.data(n)||t.val()||t.attr("href")||t.attr("src")||i.trim(t.text())||null}function d(t,n){function e(){var t=i(this);(!t.is(":checkbox,:radio")||t.is(":checked"))&&i.each(this.attributes,function(){if(!(this.name.indexOf(v)<0)){var n=t.attr("name"),e=p(t,this.name.substr(c));this.name.indexOf(g)>-1?(n||this.name.indexOf(b)>=0?f[n||this.name.substr(b.length)]=e:i.extend(f,e),s=!0):u[n||this.name.substr(v.length)]=e}})}var r=t,u={},f={},s=!1;if(r.is(h)||(r=t.closest(h)),r.each(e),r.find("*").each(e),s&&i.extend(u,{variant:f}),n=a(n),t.is(o)){var d=t.attr("name");d&&(n[d]=t.val())}return i.extend(u,a(r.data(m)),n)}function l(){i.each(["size","quantity"],function(n,e){s(i(f(e)),x.numberFormatter(t[e]()))}),i.each(["subtotal","shipping","tax","total"],function(n,e){s(i(f(e)),x.currencyFormatter(t[e]()))})}var x=i.extend({},u,n),h=f("item"),m=e("item"),v=r("item-"),g=r("item-variant"),b=r("item-variant-"),y=e("add"),D=f("add"),j=f("add")+":not("+o+")",$=f("add")+o,k=e("update"),S=f("update"),O=f("update")+":not("+o+")",P=f("update")+o,R=f("remove"),q=e("remove"),A=f("clear"),N=function(n){var e=i(n.target);e.is(D)&&t.add(d(e,e.data(y)))},B=function(n){var e=i(n.target);e.is(S)&&t.update(d(e,e.data(k)))};return i(document).on("click",j,N).on("change",$,N).on("click",O,B).on("change",P,B).on("click",R,function(n){var e=i(n.target);e.is(R)&&t.remove(d(e,e.data(q)))}).on("click",A,function(){t.clear()}),i(function(){t.ready(function(){l(),t.on("changed",l)})}),l}t.exports=r;var i=e(14),u={namespace:"carty",numberFormatter:function(t){return t},currencyFormatter:function(t){return t}},o="input,select,textarea",c="data-".length},function(n,e){n.exports=t}])}); \ No newline at end of file diff --git a/package.json b/package.json index 96c73c8..1ed28aa 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "email": "jsorgalla@gmail.com", "url": "http://sorgalla.com" }, - "version": "0.5.0", + "version": "0.5.1", "dependencies": { "extend": "^3.0.0" },