Comparing version 0.3.0 to 0.3.1
@@ -1,1 +0,1 @@ | ||
!function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return e[i].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";var i=n(1);i.keys().forEach(i)},function(e,t,n){function i(e){return n(r(e))}function r(e){return s[e]||function(){throw new Error("Cannot find module '"+e+"'.")}()}var s={"./components/form":2,"./components/form.js":2,"./components/lazy-load":3,"./components/lazy-load.js":3,"./components/validation":6,"./components/validation.js":6,"./components/validation/confirm":11,"./components/validation/confirm.js":11,"./components/validation/defaults":9,"./components/validation/defaults.js":9,"./components/validation/email":14,"./components/validation/email.js":14,"./components/validation/maxlength":13,"./components/validation/maxlength.js":13,"./components/validation/minlength":12,"./components/validation/minlength.js":12,"./components/validation/required":10,"./components/validation/required.js":10};i.keys=function(){return Object.keys(s)},i.resolve=r,e.exports=i,i.id=1},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){var t="form",r={events:"change",selectors:".input, select, .select, .textarea"},s=function(){function t(i,s){n(this,t),s=e.extend({},r,s||{}),this._element=e(i),this._options=s,this.bindListeners(),this.toggleFieldsActiveClass()}return i(t,[{key:"bindListeners",value:function(){e(document).on(this._options.events,this._options.selectors,this.onFieldChange.bind(this))}},{key:"onFieldChange",value:function(e){this.toggleActiveClass(e.target)}},{key:"shouldInputBeActive",value:function(e){return!(!e.value&&!e.placeholder)}},{key:"toggleActiveClass",value:function(t){var n=e(t),i=n.parents(".field");if(i.length)return!i.hasClass("active")&&this.shouldInputBeActive(t)?i.addClass("active"):i.hasClass("active")&&!this.shouldInputBeActive(t)?i.removeClass("active"):void 0}},{key:"toggleFieldsActiveClass",value:function(){Array.prototype.forEach.call(this._element.find(this._options.selectors),this.toggleActiveClass.bind(this))}}]),t}();return e.fn[t]=function(n){return n=n||{},this.each(function(){e.data(this,t)||e.data(this,t,new s(this,n))})},s}(jQuery)},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=n(4),a=i(o),l=n(5),u=i(l);t["default"]=function(e){var t="lazyload",n={throttle:1e3,offset:200,selector:"data-lazy"},i=function(){function t(i,s){r(this,t),s=e.extend({},n,s||{}),this._element=i,this._options=s}return s(t,[{key:"init",value:function(){return this.bindListeners(),this.checkVisiblePlaceholders(),this}},{key:"bindListeners",value:function(){this.onScrollHandler=(0,a["default"])(this.onScroll.bind(this),this._options.throttle),e(window).on("scroll",this.onScrollHandler)}},{key:"onScroll",value:function(){return this._element.length?this.checkVisiblePlaceholders():e(window).off("scroll",this.onScrollHandler)}},{key:"checkVisiblePlaceholders",value:function(){this.windowHeight=e(window).height(),this.windowWidth=e(window).width(),Array.prototype.forEach.call(this._element,this.checkPlaceholder.bind(this))}},{key:"checkPlaceholder",value:function(e){this.isPlaceholderVisible(e)&&(this.renderImage(e),(0,u["default"])(this._element,e))}},{key:"isPlaceholderVisible",value:function(e){return e.getBoundingClientRect().top<=this.windowHeight+this._options.offset}},{key:"renderImage",value:function(e){e.parentNode.replaceChild(this.createImage(e),e)}},{key:"createImage",value:function(e){var t=document.createElement("img");return this.parseAttributes(t,e.attributes),t.removeAttribute("data-lazy"),e.getAttribute("data-srcset")?(this.parseBreakpoints(t,e.getAttribute("data-srcset")),t):(t.src=e.getAttribute("data-src"),t)}},{key:"parseAttributes",value:function(e,t){var n=this;return Array.prototype.forEach.call(t,function(t){(t.name!==n._options.selector||"data-srcset"!==t.name||"data-src"!==t.name)&&e.setAttribute(t.name,t.value)}),e}},{key:"parseBreakpoints",value:function(e,t){e.removeAttribute("data-srcset"),t=t.split(",").map(function(e){return e=e.trim().split(" "),{src:e[0],width:e[1]}}).sort(function(e,t){return t.width-e.width});for(var n=0;n<t.length;n++){var i=t[n];if(i.width<=this.windowWidth){e.src=i.src;break}}return e}},{key:"destroy",value:function(){e(window).off("scroll",this.onScrollHandler)}}]),t}();return e.fn[t]=function(n){return n=n||{},this.each(function(){e.data(this,t)||e.data(this,t,new i(this,n).init())})},i}(jQuery)},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){var n=!0;return function(){if(n){for(var i=arguments.length,r=Array(i),s=0;i>s;s++)r[s]=arguments[s];e.apply(this,r),n=!1,setTimeout(function(){return n=!0},t)}}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){Array.prototype.splice.call(e,Array.prototype.indexOf.call(e,t))}},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=n(7),a=i(o),l=n(9),u=i(l);t["default"]=function(e){var t="validation",n={events:"blur",selector:"[data-required]"},i=function(){function t(i,s){r(this,t),this._element=i,this._options=e.extend({},n,s||{})}return s(t,[{key:"init",value:function(){this._fields=this._element.find(this._options.selector),this.bindListeners()}},{key:"bindListeners",value:function(){var e=this;this.handler=function(t){e.validate(t.target)},this._element.off(this._options.events,this._options.selector,this.handler),this._element.on(this._options.events,this._options.selector,this.handler)}},{key:"validate",value:function(e){var t=this,n=e.getAttribute("data-validate");return n?(n=n.split(" ").reduce(function(n,i){return t.rules[i].call(t,e,t._element)||n.push(i),n},[]),a["default"].emit("validation:"+(n.length?"error":"success"),e,n),!n.length):void 0}},{key:"validateAll",value:function(){return Array.prototype.map.call(this._element.find(this._options.selector),this.validate,this).every(function(e){return e})}}]),t}();return i.prototype.rules=u["default"],e.fn[t]=function(n){return n=n||{},this.each(function(){e.data(this,t)||e.data(this,t,new i(this,n).init())})},i}(jQuery)},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(8),s=i(r);t["default"]=new s["default"]},function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function r(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!r(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,r,a,l,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],o(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(s(n))for(a=Array.prototype.slice.call(arguments,1),u=n.slice(),r=u.length,l=0;r>l;l++)u[l].apply(this,a);return!0},n.prototype.addListener=function(e,t){var r;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,r,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=o;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],i(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(10),s=i(r),o=n(11),a=i(o),l=n(12),u=i(l),c=n(13),h=i(c),f=n(14),d=i(f);t["default"]={required:s["default"],confirm:a["default"],minlength:u["default"],maxlength:h["default"],email:d["default"]}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){return"checkbox"===e.type?e.checked:"radio"===e.type?t.find('[name="'+e.name+'"]:checked').length:!!e.value.trim()}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){return e.value===t.find('[name="'+e.getAttribute("data-confirm")+"]").val()}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return e.value.length>=e.getAttribute("data-minlength")}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return e.value.length<=e.getAttribute("maxlength")}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e.value)}}]); | ||
var Garden=function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return e[i].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";var i=n(1);i.keys().forEach(i)},function(e,t,n){function i(e){return n(r(e))}function r(e){return s[e]||function(){throw new Error("Cannot find module '"+e+"'.")}()}var s={"./components/form":2,"./components/form.js":2,"./components/lazy-load":4,"./components/lazy-load.js":4,"./components/validation":7,"./components/validation.js":7,"./components/validation/confirm":12,"./components/validation/confirm.js":12,"./components/validation/defaults":10,"./components/validation/defaults.js":10,"./components/validation/email":15,"./components/validation/email.js":15,"./components/validation/maxlength":14,"./components/validation/maxlength.js":14,"./components/validation/minlength":13,"./components/validation/minlength.js":13,"./components/validation/required":11,"./components/validation/required.js":11};i.keys=function(){return Object.keys(s)},i.resolve=r,e.exports=i,i.id=1},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),a=i(o),l="form",u={events:"change",selectors:".input, select, .select, .textarea"},c=function(){function e(t,n){r(this,e),n=a["default"].extend({},u,n||{}),this._element=(0,a["default"])(t),this._options=n,this.bindListeners(),this.toggleFieldsActiveClass()}return s(e,[{key:"bindListeners",value:function(){(0,a["default"])(document).on(this._options.events,this._options.selectors,this.onFieldChange.bind(this))}},{key:"onFieldChange",value:function(e){this.toggleActiveClass(e.target)}},{key:"shouldInputBeActive",value:function(e){return!(!e.value&&!e.placeholder)}},{key:"toggleActiveClass",value:function(e){var t=(0,a["default"])(e),n=t.parents(".field");if(n.length)return!n.hasClass("active")&&this.shouldInputBeActive(e)?n.addClass("active"):n.hasClass("active")&&!this.shouldInputBeActive(e)?n.removeClass("active"):void 0}},{key:"toggleFieldsActiveClass",value:function(){Array.prototype.forEach.call(this._element.find(this._options.selectors),this.toggleActiveClass.bind(this))}}]),e}();a["default"].fn[l]=function(e){return e=e||{},this.each(function(){a["default"].data(this,l)||a["default"].data(this,l,new c(this,e))})},t["default"]=c},function(e,t){e.exports=$},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),a=i(o),l=n(5),u=i(l),c=n(6),f=i(c),h="lazyload",d={throttle:1e3,offset:200,selector:"data-lazy"},v=function(){function e(t,n){r(this,e),n=a["default"].extend({},d,n||{}),this._element=t,this._options=n}return s(e,[{key:"init",value:function(){return this.bindListeners(),this.checkVisiblePlaceholders(),this}},{key:"bindListeners",value:function(){this.onScrollHandler=(0,u["default"])(this.onScroll.bind(this),this._options.throttle),(0,a["default"])(window).on("scroll",this.onScrollHandler)}},{key:"onScroll",value:function(){return this._element.length?this.checkVisiblePlaceholders():(0,a["default"])(window).off("scroll",this.onScrollHandler)}},{key:"checkVisiblePlaceholders",value:function(){this.windowHeight=(0,a["default"])(window).height(),this.windowWidth=(0,a["default"])(window).width(),Array.prototype.forEach.call(this._element,this.checkPlaceholder.bind(this))}},{key:"checkPlaceholder",value:function(e){this.isPlaceholderVisible(e)&&(this.renderImage(e),(0,f["default"])(this._element,e))}},{key:"isPlaceholderVisible",value:function(e){return e.getBoundingClientRect().top<=this.windowHeight+this._options.offset}},{key:"renderImage",value:function(e){e.parentNode.replaceChild(this.createImage(e),e)}},{key:"createImage",value:function(e){var t=document.createElement("img");return this.parseAttributes(t,e.attributes),t.removeAttribute("data-lazy"),e.getAttribute("data-srcset")?(this.parseBreakpoints(t,e.getAttribute("data-srcset")),t):(t.src=e.getAttribute("data-src"),t)}},{key:"parseAttributes",value:function(e,t){var n=this;return Array.prototype.forEach.call(t,function(t){(t.name!==n._options.selector||"data-srcset"!==t.name||"data-src"!==t.name)&&e.setAttribute(t.name,t.value)}),e}},{key:"parseBreakpoints",value:function(e,t){e.removeAttribute("data-srcset"),t=t.split(",").map(function(e){return e=e.trim().split(" "),{src:e[0],width:e[1]}}).sort(function(e,t){return t.width-e.width});for(var n=0;n<t.length;n++){var i=t[n];if(i.width<=this.windowWidth){e.src=i.src;break}}return e}},{key:"destroy",value:function(){(0,a["default"])(window).off("scroll",this.onScrollHandler)}}]),e}();a["default"].fn[h]=function(e){return e=e||{},this.each(function(){a["default"].data(this,h)||a["default"].data(this,h,new v(this,e).init())})},t["default"]=v},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){var n=!0;return function(){if(n){for(var i=arguments.length,r=Array(i),s=0;i>s;s++)r[s]=arguments[s];e.apply(this,r),n=!1,setTimeout(function(){return n=!0},t)}}}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){Array.prototype.splice.call(e,Array.prototype.indexOf.call(e,t))}},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),a=i(o),l=n(8),u=i(l),c=n(10),f=i(c),h="validation",d={events:"blur",selector:"[data-required]"},v=function(){function e(t,n){r(this,e),this._element=t,this._options=a["default"].extend({},d,n||{})}return s(e,[{key:"init",value:function(){this._fields=this._element.find(this._options.selector),this.bindListeners()}},{key:"bindListeners",value:function(){var e=this;this.handler=function(t){e.validate(t.target)},this._element.off(this._options.events,this._options.selector,this.handler),this._element.on(this._options.events,this._options.selector,this.handler)}},{key:"validate",value:function(e){var t=this,n=e.getAttribute("data-validate");return n?(n=n.split(" ").reduce(function(n,i){return t.rules[i].call(t,e,t._element)||n.push(i),n},[]),u["default"].emit("validation:"+(n.length?"error":"success"),e,n),!n.length):void 0}},{key:"validateAll",value:function(){return Array.prototype.map.call(this._element.find(this._options.selector),this.validate,this).every(function(e){return e})}}]),e}();v.prototype.rules=f["default"],a["default"].fn[h]=function(e){return e=e||{},this.each(function(){a["default"].data(this,h)||a["default"].data(this,h,new v(this,e).init())})},t["default"]=v},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(9),s=i(r);t["default"]=new s["default"]},function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function r(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!r(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,r,a,l,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],o(n))return!1;if(i(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(s(n))for(a=Array.prototype.slice.call(arguments,1),u=n.slice(),r=u.length,l=0;r>l;l++)u[l].apply(this,a);return!0},n.prototype.addListener=function(e,t){var r;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,r,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=o;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],i(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(11),s=i(r),o=n(12),a=i(o),l=n(13),u=i(l),c=n(14),f=i(c),h=n(15),d=i(h);t["default"]={required:s["default"],confirm:a["default"],minlength:u["default"],maxlength:f["default"],email:d["default"]}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){return"checkbox"===e.type?e.checked:"radio"===e.type?t.find('[name="'+e.name+'"]:checked').length:!!e.value.trim()}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){return e.value===t.find('[name="'+e.getAttribute("data-confirm")+"]").val()}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return e.value.length>=e.getAttribute("data-minlength")}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return e.value.length<=e.getAttribute("maxlength")}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e.value)}}]); |
{ | ||
"name": "garden", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "A styleguide based on Leroy Merlin needs", | ||
@@ -5,0 +5,0 @@ "main": "dist/js/garden.min.js", |
@@ -1,72 +0,72 @@ | ||
export default (($) => { | ||
const NAME = 'form'; | ||
const DEFAULTS = { | ||
events: 'change', | ||
selectors: '.input, select, .select, .textarea' | ||
}; | ||
import $ from 'jquery'; | ||
class Form { | ||
constructor(element, options) { | ||
options = $.extend({}, DEFAULTS, options || {}); | ||
const NAME = 'form'; | ||
const DEFAULTS = { | ||
events: 'change', | ||
selectors: '.input, select, .select, .textarea' | ||
}; | ||
this._element = $(element); | ||
this._options = options; | ||
class Form { | ||
constructor(element, options) { | ||
options = $.extend({}, DEFAULTS, options || {}); | ||
this.bindListeners(); | ||
this._element = $(element); | ||
this._options = options; | ||
this.toggleFieldsActiveClass(); | ||
} | ||
this.bindListeners(); | ||
bindListeners() { | ||
$(document).on( | ||
this._options.events, this._options.selectors, | ||
this.onFieldChange.bind(this) | ||
); | ||
} | ||
this.toggleFieldsActiveClass(); | ||
} | ||
onFieldChange(event) { | ||
this.toggleActiveClass(event.target); | ||
} | ||
bindListeners() { | ||
$(document).on( | ||
this._options.events, this._options.selectors, | ||
this.onFieldChange.bind(this) | ||
); | ||
} | ||
shouldInputBeActive(input) { | ||
return !!(input.value || input.placeholder); | ||
} | ||
onFieldChange(event) { | ||
this.toggleActiveClass(event.target); | ||
} | ||
toggleActiveClass(input) { | ||
let $input = $(input), | ||
$field = $input.parents('.field'); | ||
shouldInputBeActive(input) { | ||
return !!(input.value || input.placeholder); | ||
} | ||
if(!$field.length) { | ||
return; | ||
} | ||
toggleActiveClass(input) { | ||
let $input = $(input), | ||
$field = $input.parents('.field'); | ||
if (!$field.hasClass('active') && this.shouldInputBeActive(input)) { | ||
return $field.addClass('active'); | ||
} | ||
if(!$field.length) { | ||
return; | ||
} | ||
if ($field.hasClass('active') && !this.shouldInputBeActive(input)) { | ||
return $field.removeClass('active'); | ||
} | ||
if (!$field.hasClass('active') && this.shouldInputBeActive(input)) { | ||
return $field.addClass('active'); | ||
} | ||
toggleFieldsActiveClass() { | ||
Array.prototype.forEach.call( | ||
this._element.find(this._options.selectors), | ||
this.toggleActiveClass.bind(this) | ||
); | ||
if ($field.hasClass('active') && !this.shouldInputBeActive(input)) { | ||
return $field.removeClass('active'); | ||
} | ||
} | ||
/* istanbul ignore next */ | ||
$.fn[NAME] = function(options) { | ||
options = options || {}; | ||
toggleFieldsActiveClass() { | ||
Array.prototype.forEach.call( | ||
this._element.find(this._options.selectors), | ||
this.toggleActiveClass.bind(this) | ||
); | ||
} | ||
} | ||
return this.each(function() { | ||
if (!$.data(this, NAME)) { | ||
$.data(this, NAME, new Form(this, options)); | ||
} | ||
}); | ||
}; | ||
/* istanbul ignore next */ | ||
$.fn[NAME] = function(options) { | ||
options = options || {}; | ||
return Form; | ||
})(jQuery); | ||
return this.each(function() { | ||
if (!$.data(this, NAME)) { | ||
$.data(this, NAME, new Form(this, options)); | ||
} | ||
}); | ||
}; | ||
export default Form; |
@@ -0,128 +1,128 @@ | ||
import $ from 'jquery'; | ||
import throttle from '../utils/throttle'; | ||
import removeFromArray from '../utils/remove-array-like'; | ||
export default (($) => { | ||
const NAME = 'lazyload'; | ||
const DEFAULTS = { | ||
throttle: 1000, | ||
offset: 200, | ||
selector: 'data-lazy' | ||
}; | ||
const NAME = 'lazyload'; | ||
const DEFAULTS = { | ||
throttle: 1000, | ||
offset: 200, | ||
selector: 'data-lazy' | ||
}; | ||
class LazyLoad { | ||
constructor(element, options) { | ||
options = $.extend({}, DEFAULTS, options || {}); | ||
class LazyLoad { | ||
constructor(element, options) { | ||
options = $.extend({}, DEFAULTS, options || {}); | ||
this._element = element; | ||
this._options = options; | ||
} | ||
this._element = element; | ||
this._options = options; | ||
} | ||
init() { | ||
this.bindListeners(); | ||
this.checkVisiblePlaceholders(); | ||
init() { | ||
this.bindListeners(); | ||
this.checkVisiblePlaceholders(); | ||
return this; | ||
} | ||
return this; | ||
} | ||
bindListeners() { | ||
this.onScrollHandler = throttle(this.onScroll.bind(this), this._options.throttle); | ||
$(window).on('scroll', this.onScrollHandler); | ||
} | ||
bindListeners() { | ||
this.onScrollHandler = throttle(this.onScroll.bind(this), this._options.throttle); | ||
$(window).on('scroll', this.onScrollHandler); | ||
} | ||
onScroll() { | ||
return this._element.length ? this.checkVisiblePlaceholders() : $(window).off('scroll', this.onScrollHandler); | ||
} | ||
onScroll() { | ||
return this._element.length ? this.checkVisiblePlaceholders() : $(window).off('scroll', this.onScrollHandler); | ||
} | ||
checkVisiblePlaceholders() { | ||
this.windowHeight = $(window).height(); | ||
this.windowWidth = $(window).width(); | ||
checkVisiblePlaceholders() { | ||
this.windowHeight = $(window).height(); | ||
this.windowWidth = $(window).width(); | ||
Array.prototype.forEach.call(this._element, this.checkPlaceholder.bind(this)); | ||
} | ||
Array.prototype.forEach.call(this._element, this.checkPlaceholder.bind(this)); | ||
} | ||
checkPlaceholder(placeholder) { | ||
if (this.isPlaceholderVisible(placeholder)) { | ||
this.renderImage(placeholder); | ||
removeFromArray(this._element, placeholder); | ||
} | ||
checkPlaceholder(placeholder) { | ||
if (this.isPlaceholderVisible(placeholder)) { | ||
this.renderImage(placeholder); | ||
removeFromArray(this._element, placeholder); | ||
} | ||
} | ||
isPlaceholderVisible(placeholder) { | ||
return placeholder.getBoundingClientRect().top <= (this.windowHeight + this._options.offset); | ||
} | ||
isPlaceholderVisible(placeholder) { | ||
return placeholder.getBoundingClientRect().top <= (this.windowHeight + this._options.offset); | ||
} | ||
renderImage(placeholder) { | ||
placeholder.parentNode.replaceChild(this.createImage(placeholder), placeholder); | ||
} | ||
renderImage(placeholder) { | ||
placeholder.parentNode.replaceChild(this.createImage(placeholder), placeholder); | ||
} | ||
createImage(placeholder) { | ||
let image = document.createElement('img'); | ||
createImage(placeholder) { | ||
let image = document.createElement('img'); | ||
this.parseAttributes(image, placeholder.attributes); | ||
this.parseAttributes(image, placeholder.attributes); | ||
image.removeAttribute('data-lazy'); | ||
image.removeAttribute('data-lazy'); | ||
if (placeholder.getAttribute('data-srcset')) { | ||
this.parseBreakpoints(image, placeholder.getAttribute('data-srcset')); | ||
if (placeholder.getAttribute('data-srcset')) { | ||
this.parseBreakpoints(image, placeholder.getAttribute('data-srcset')); | ||
return image; | ||
} | ||
image.src = placeholder.getAttribute('data-src'); | ||
return image; | ||
} | ||
parseAttributes(image, attributes) { | ||
Array.prototype.forEach.call(attributes, (attr) => { | ||
if (attr.name !== this._options.selector || attr.name !== 'data-srcset' || attr.name !== 'data-src') { | ||
image.setAttribute(attr.name, attr.value); | ||
} | ||
}); | ||
image.src = placeholder.getAttribute('data-src'); | ||
return image; | ||
} | ||
return image; | ||
} | ||
parseBreakpoints(image, breakpoints) { | ||
image.removeAttribute('data-srcset'); | ||
parseAttributes(image, attributes) { | ||
Array.prototype.forEach.call(attributes, (attr) => { | ||
if (attr.name !== this._options.selector || attr.name !== 'data-srcset' || attr.name !== 'data-src') { | ||
image.setAttribute(attr.name, attr.value); | ||
} | ||
}); | ||
breakpoints = breakpoints.split(',').map(breakpoint => { | ||
breakpoint = breakpoint.trim().split(' '); | ||
return image; | ||
} | ||
return { | ||
src: breakpoint[0], | ||
width: breakpoint[1] | ||
}; | ||
}) | ||
.sort((a, b) => b.width - a.width); | ||
parseBreakpoints(image, breakpoints) { | ||
image.removeAttribute('data-srcset'); | ||
for (let i = 0; i < breakpoints.length; i++) { | ||
let breakpoint = breakpoints[i]; | ||
breakpoints = breakpoints.split(',').map(breakpoint => { | ||
breakpoint = breakpoint.trim().split(' '); | ||
if (breakpoint.width <= this.windowWidth) { | ||
image.src = breakpoint.src; | ||
break; | ||
} | ||
return { | ||
src: breakpoint[0], | ||
width: breakpoint[1] | ||
}; | ||
}) | ||
.sort((a, b) => b.width - a.width); | ||
for (let i = 0; i < breakpoints.length; i++) { | ||
let breakpoint = breakpoints[i]; | ||
if (breakpoint.width <= this.windowWidth) { | ||
image.src = breakpoint.src; | ||
break; | ||
} | ||
return image; | ||
} | ||
destroy() { | ||
$(window).off('scroll', this.onScrollHandler); | ||
} | ||
return image; | ||
} | ||
/* istanbul ignore next */ | ||
$.fn[NAME] = function(options) { | ||
options = options || {}; | ||
destroy() { | ||
$(window).off('scroll', this.onScrollHandler); | ||
} | ||
} | ||
return this.each(function() { | ||
if (!$.data(this, NAME)) { | ||
$.data(this, NAME, new LazyLoad(this, options).init()); | ||
} | ||
}); | ||
}; | ||
/* istanbul ignore next */ | ||
$.fn[NAME] = function(options) { | ||
options = options || {}; | ||
return LazyLoad; | ||
})(jQuery); | ||
return this.each(function() { | ||
if (!$.data(this, NAME)) { | ||
$.data(this, NAME, new LazyLoad(this, options).init()); | ||
} | ||
}); | ||
}; | ||
export default LazyLoad; |
@@ -0,1 +1,3 @@ | ||
import $ from 'jquery'; | ||
import emitter from '../utils/emitter'; | ||
@@ -5,70 +7,67 @@ | ||
export default (($) => { | ||
const NAME = 'validation'; | ||
const DEFAULTS = { | ||
events: 'blur', | ||
selector: '[data-required]' | ||
}; | ||
const NAME = 'validation'; | ||
const DEFAULTS = { | ||
events: 'blur', | ||
selector: '[data-required]' | ||
}; | ||
class Validation { | ||
constructor(element, options) { | ||
this._element = element; | ||
this._options = $.extend({}, DEFAULTS, (options || {})); | ||
} | ||
class Validation { | ||
constructor(element, options) { | ||
this._element = element; | ||
this._options = $.extend({}, DEFAULTS, (options || {})); | ||
} | ||
init() { | ||
this._fields = this._element.find(this._options.selector); | ||
init() { | ||
this._fields = this._element.find(this._options.selector); | ||
this.bindListeners(); | ||
} | ||
this.bindListeners(); | ||
} | ||
bindListeners() { | ||
this.handler = (e) => { | ||
this.validate(e.target); | ||
}; | ||
bindListeners() { | ||
this.handler = (e) => { | ||
this.validate(e.target); | ||
}; | ||
this._element.off(this._options.events, this._options.selector, this.handler); | ||
this._element.on(this._options.events, this._options.selector, this.handler); | ||
this._element.off(this._options.events, this._options.selector, this.handler); | ||
this._element.on(this._options.events, this._options.selector, this.handler); | ||
} | ||
validate(field) { | ||
let rules = field.getAttribute('data-validate'); | ||
if (!rules) { | ||
return; | ||
} | ||
validate(field) { | ||
let rules = field.getAttribute('data-validate'); | ||
if (!rules) { | ||
return; | ||
rules = rules.split(' ').reduce((errors, rule) => { | ||
if (!this.rules[rule].call(this, field, this._element)) { | ||
errors.push(rule); | ||
} | ||
rules = rules.split(' ').reduce((errors, rule) => { | ||
if (!this.rules[rule].call(this, field, this._element)) { | ||
errors.push(rule); | ||
} | ||
return errors; | ||
}, []); | ||
return errors; | ||
}, []); | ||
emitter.emit(`validation:${!rules.length ? 'success' : 'error'}`, field, rules); | ||
emitter.emit(`validation:${!rules.length ? 'success' : 'error'}`, field, rules); | ||
return !rules.length; | ||
} | ||
return !rules.length; | ||
} | ||
validateAll() { | ||
return Array.prototype.map.call(this._element.find(this._options.selector), this.validate, this).every(validation => validation); | ||
} | ||
validateAll() { | ||
return Array.prototype.map.call(this._element.find(this._options.selector), this.validate, this).every(validation => validation); | ||
} | ||
} | ||
Validation.prototype.rules = rules; | ||
Validation.prototype.rules = rules; | ||
/* istanbul ignore next */ | ||
$.fn[NAME] = function(options) { | ||
options = options || {}; | ||
/* istanbul ignore next */ | ||
$.fn[NAME] = function(options) { | ||
options = options || {}; | ||
return this.each(function() { | ||
if (!$.data(this, NAME)) { | ||
$.data(this, NAME, new Validation(this, options).init()); | ||
} | ||
}); | ||
}; | ||
return this.each(function() { | ||
if (!$.data(this, NAME)) { | ||
$.data(this, NAME, new Validation(this, options).init()); | ||
} | ||
}); | ||
}; | ||
return Validation; | ||
})(jQuery); | ||
export default Validation; |
112363
76
1090