diff --git a/bower.json b/bower.json index 54f86fb..30c3812 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "remodal", - "version": "0.1.7", + "version": "0.2.0", "homepage": "http://vodkabears.github.io/remodal/", "authors": [ "Ilya Makarov " diff --git a/dist/jquery.remodal.css b/dist/jquery.remodal.css index 6529b1b..57b07a2 100644 --- a/dist/jquery.remodal.css +++ b/dist/jquery.remodal.css @@ -1,6 +1,11 @@ -/*! Remodal - v0.1.7 - 2014-07-14 - * https://github.com/VodkaBears/remodal - * Copyright (c) 2014 VodkaBears; */ +/* + * Remodal - v0.2.0 + * Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking. + * http://vodkabears.github.io/remodal/ + * + * Made by Ilya Makarov + * Under MIT License + */ /* ========================================================================== Remodal necessary styles diff --git a/dist/jquery.remodal.js b/dist/jquery.remodal.js index 30606de..0e63cdf 100644 --- a/dist/jquery.remodal.js +++ b/dist/jquery.remodal.js @@ -1,6 +1,11 @@ -/*! Remodal - v0.1.7 - 2014-07-14 - * https://github.com/VodkaBears/remodal - * Copyright (c) 2014 VodkaBears; */ +/* + * Remodal - v0.2.0 + * Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking. + * http://vodkabears.github.io/remodal/ + * + * Made by Ilya Makarov + * Under MIT License + */ ;(function ($) { "use strict"; @@ -30,17 +35,17 @@ * @return {Number} */ var getTransitionDuration = function ($elem) { - var duration = $elem.css('transition-duration') || - $elem.css('-webkit-transition-duration') || - $elem.css('-moz-transition-duration') || - $elem.css('-o-transition-duration') || - $elem.css('-ms-transition-duration') || + var duration = $elem.css("transition-duration") || + $elem.css("-webkit-transition-duration") || + $elem.css("-moz-transition-duration") || + $elem.css("-o-transition-duration") || + $elem.css("-ms-transition-duration") || 0; - var delay = $elem.css('transition-delay') || - $elem.css('-webkit-transition-delay') || - $elem.css('-moz-transition-delay') || - $elem.css('-o-transition-delay') || - $elem.css('-ms-transition-delay') || + var delay = $elem.css("transition-delay") || + $elem.css("-webkit-transition-delay") || + $elem.css("-moz-transition-delay") || + $elem.css("-o-transition-delay") || + $elem.css("-ms-transition-delay") || 0; return (parseFloat(duration) + parseFloat(delay)) * 1000; @@ -81,16 +86,50 @@ * Lock screen */ var lockScreen = function () { - $("html, body").addClass(pluginName + "_lock"); $(document.body).css("padding-right", "+=" + getScrollbarWidth()); + $("html, body").addClass(pluginName + "_lock"); }; /** * Unlock screen */ var unlockScreen = function () { - $("html, body").removeClass(pluginName + "_lock"); $(document.body).css("padding-right", "-=" + getScrollbarWidth()); + $("html, body").removeClass(pluginName + "_lock"); + }; + + /** + * Parse string with options + * @param str + * @returns {Object} + */ + var parseOptions = function (str) { + var obj = {}, clearedStr, arr; + + // remove spaces before and after delimiters + clearedStr = str.replace(/\s*:\s*/g, ":").replace(/\s*,\s*/g, ","); + + // parse string + arr = clearedStr.split(","); + var i, len, val; + for (i = 0, len = arr.length; i < len; i++) { + arr[i] = arr[i].split(":"); + val = arr[i][1]; + + // convert string value if it is like a boolean + if (typeof val === "string" || val instanceof String) { + val = val === "true" || (val === "false" ? false : val); + } + + // convert string value if it is like a number + if (typeof val === "string" || val instanceof String) { + val = !isNaN(val) ? +val : val; + } + + obj[arr[i][0]] = val; + } + + return obj; }; /** @@ -159,7 +198,7 @@ } }); - $(document).bind('keyup.' + pluginName, function (e) { + $(document).bind("keyup." + pluginName, function (e) { if (e.keyCode === 27) { self.close(); } @@ -244,9 +283,9 @@ }; if ($) { - $["fn"][pluginName] = function (opts) { + $.fn[pluginName] = function (opts) { var instance; - this["each"](function (i, e) { + this.each(function (i, e) { var $e = $(e); if ($e.data(pluginName) == null) { instance = new Remodal($e, opts); @@ -289,6 +328,8 @@ if (!options) { options = {}; + } else if (typeof options === "string" || options instanceof String) { + options = parseOptions(options); } $container[pluginName](options); @@ -317,7 +358,7 @@ // Catch syntax error if your hash is bad try { - $elem = $("[data-" + pluginName + "-id=" + id.replace(new RegExp('/', 'g'), "\\/") + "]"); + $elem = $("[data-" + pluginName + "-id=" + id.replace(new RegExp("/", "g"), "\\/") + "]"); } catch (e) {} if ($elem && $elem.length) { @@ -331,4 +372,4 @@ } }; $(window).bind("hashchange." + pluginName, hashHandler); -})(window["jQuery"] || window["Zepto"]); \ No newline at end of file +})(window.jQuery || window.Zepto); diff --git a/dist/jquery.remodal.min.js b/dist/jquery.remodal.min.js index 6511f4d..9e2adb1 100644 --- a/dist/jquery.remodal.min.js +++ b/dist/jquery.remodal.min.js @@ -1,4 +1,9 @@ -/*! Remodal - v0.1.7 - 2014-07-14 - * https://github.com/VodkaBears/remodal - * Copyright (c) 2014 VodkaBears; */ -!function(a){"use strict";function b(b,e){this.settings=a.extend({},d,e),this.modal=b,this.buildDOM(),this.addEventListeners(),this.index=a[c].lookup.push(this)-1,this.busy=!1}var c="remodal",d={hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0};a[c]={lookup:[]};var e,f,g=function(a){var b=a.css("transition-duration")||a.css("-webkit-transition-duration")||a.css("-moz-transition-duration")||a.css("-o-transition-duration")||a.css("-ms-transition-duration")||0,c=a.css("transition-delay")||a.css("-webkit-transition-delay")||a.css("-moz-transition-delay")||a.css("-o-transition-delay")||a.css("-ms-transition-delay")||0;return 1e3*(parseFloat(b)+parseFloat(c))},h=function(){if(a(document.body).height()<=a(window).height())return 0;var b=document.createElement("div");b.style.visibility="hidden",b.style.width="100px",document.body.appendChild(b);var c=b.offsetWidth;b.style.overflow="scroll";var d=document.createElement("div");d.style.width="100%",b.appendChild(d);var e=d.offsetWidth;return b.parentNode.removeChild(b),c-e},i=function(){a("html, body").addClass(c+"_lock"),a(document.body).css("padding-right","+="+h())},j=function(){a("html, body").removeClass(c+"_lock"),a(document.body).css("padding-right","-="+h())};b.prototype.buildDOM=function(){this.body=a(document.body),this.bg=a("."+c+"-bg"),this.modalClose=a("").addClass(c+"-close"),this.overlay=a("
").addClass(c+"-overlay"),this.modal.hasClass(c)||this.modal.addClass(c),this.modal.css("visibility","visible"),this.modal.append(this.modalClose),this.overlay.append(this.modal),this.body.append(this.overlay),this.confirm=this.modal.find("."+c+"-confirm"),this.cancel=this.modal.find("."+c+"-cancel");var b=g(this.overlay),d=g(this.modal),e=g(this.bg);this.td=d>b?d:b,this.td=e>this.td?e:this.td},b.prototype.addEventListeners=function(){var b=this;this.modalClose.bind("click."+c,function(a){a.preventDefault(),b.close()}),this.cancel.bind("click."+c,function(a){a.preventDefault(),b.modal.trigger("cancel"),b.settings.closeOnCancel&&b.close()}),this.confirm.bind("click."+c,function(a){a.preventDefault(),b.modal.trigger("confirm"),b.settings.closeOnConfirm&&b.close()}),a(document).bind("keyup."+c,function(a){27===a.keyCode&&b.close()}),this.overlay.bind("click."+c,function(d){var e=a(d.target);e.hasClass(c+"-overlay")&&b.close()})},b.prototype.open=function(){if(!this.busy){this.busy=!0,this.modal.trigger("open");var b=this.modal.attr("data-"+c+"-id");b&&this.settings.hashTracking&&(f=a(window).scrollTop(),location.hash=b),e&&e!==this&&(e.overlay.hide(),e.body.removeClass(c+"_active")),e=this,i(),this.overlay.show();var d=this;setTimeout(function(){d.body.addClass(c+"_active"),setTimeout(function(){d.busy=!1,d.modal.trigger("opened")},d.td+50)},25)}},b.prototype.close=function(){if(!this.busy){this.busy=!0,this.modal.trigger("close"),this.settings.hashTracking&&this.modal.attr("data-"+c+"-id")===location.hash.substr(1)&&(location.hash="",a(window).scrollTop(f)),this.body.removeClass(c+"_active");var b=this;setTimeout(function(){b.overlay.hide(),j(),b.busy=!1,b.modal.trigger("closed")},b.td+50)}},a&&(a.fn[c]=function(d){var e;return this.each(function(f,g){var h=a(g);null==h.data(c)&&(e=new b(h,d),h.data(c,e.index),e.settings.hashTracking&&h.attr("data-"+c+"-id")===location.hash.substr(1)&&e.open())}),e}),a(document).ready(function(){a(document).on("click","[data-"+c+"-target]",function(b){b.preventDefault();var d=b.currentTarget,e=d.getAttribute("data-"+c+"-target"),f=a("[data-"+c+"-id="+e+"]");a[c].lookup[f.data(c)].open()}),a(document).find("."+c).each(function(b,d){var e=a(d),f=e.data(c+"-options");f||(f={}),e[c](f)})});var k=function(b,d){var f=location.hash.replace("#","");if("undefined"==typeof d&&(d=!0),f){var g;try{g=a("[data-"+c+"-id="+f.replace(new RegExp("/","g"),"\\/")+"]")}catch(b){}if(g&&g.length){var h=a[c].lookup[g.data(c)];h&&h.settings.hashTracking&&h.open()}}else d&&e&&!e.busy&&e.settings.hashTracking&&e.close()};a(window).bind("hashchange."+c,k)}(window.jQuery||window.Zepto); \ No newline at end of file +/* + * Remodal - v0.2.0 + * Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking. + * http://vodkabears.github.io/remodal/ + * + * Made by Ilya Makarov + * Under MIT License + */ +!function(a){"use strict";function b(b,e){this.settings=a.extend({},d,e),this.modal=b,this.buildDOM(),this.addEventListeners(),this.index=a[c].lookup.push(this)-1,this.busy=!1}var c="remodal",d={hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0};a[c]={lookup:[]};var e,f,g=function(a){var b=a.css("transition-duration")||a.css("-webkit-transition-duration")||a.css("-moz-transition-duration")||a.css("-o-transition-duration")||a.css("-ms-transition-duration")||0,c=a.css("transition-delay")||a.css("-webkit-transition-delay")||a.css("-moz-transition-delay")||a.css("-o-transition-delay")||a.css("-ms-transition-delay")||0;return 1e3*(parseFloat(b)+parseFloat(c))},h=function(){if(a(document.body).height()<=a(window).height())return 0;var b=document.createElement("div");b.style.visibility="hidden",b.style.width="100px",document.body.appendChild(b);var c=b.offsetWidth;b.style.overflow="scroll";var d=document.createElement("div");d.style.width="100%",b.appendChild(d);var e=d.offsetWidth;return b.parentNode.removeChild(b),c-e},i=function(){a(document.body).css("padding-right","+="+h()),a("html, body").addClass(c+"_lock")},j=function(){a(document.body).css("padding-right","-="+h()),a("html, body").removeClass(c+"_lock")},k=function(a){var b,c,d={};b=a.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,","),c=b.split(",");var e,f,g;for(e=0,f=c.length;f>e;e++)c[e]=c[e].split(":"),g=c[e][1],("string"==typeof g||g instanceof String)&&(g="true"===g||("false"===g?!1:g)),("string"==typeof g||g instanceof String)&&(g=isNaN(g)?g:+g),d[c[e][0]]=g;return d};b.prototype.buildDOM=function(){this.body=a(document.body),this.bg=a("."+c+"-bg"),this.modalClose=a("").addClass(c+"-close"),this.overlay=a("
").addClass(c+"-overlay"),this.modal.hasClass(c)||this.modal.addClass(c),this.modal.css("visibility","visible"),this.modal.append(this.modalClose),this.overlay.append(this.modal),this.body.append(this.overlay),this.confirm=this.modal.find("."+c+"-confirm"),this.cancel=this.modal.find("."+c+"-cancel");var b=g(this.overlay),d=g(this.modal),e=g(this.bg);this.td=d>b?d:b,this.td=e>this.td?e:this.td},b.prototype.addEventListeners=function(){var b=this;this.modalClose.bind("click."+c,function(a){a.preventDefault(),b.close()}),this.cancel.bind("click."+c,function(a){a.preventDefault(),b.modal.trigger("cancel"),b.settings.closeOnCancel&&b.close()}),this.confirm.bind("click."+c,function(a){a.preventDefault(),b.modal.trigger("confirm"),b.settings.closeOnConfirm&&b.close()}),a(document).bind("keyup."+c,function(a){27===a.keyCode&&b.close()}),this.overlay.bind("click."+c,function(d){var e=a(d.target);e.hasClass(c+"-overlay")&&b.close()})},b.prototype.open=function(){if(!this.busy){this.busy=!0,this.modal.trigger("open");var b=this.modal.attr("data-"+c+"-id");b&&this.settings.hashTracking&&(f=a(window).scrollTop(),location.hash=b),e&&e!==this&&(e.overlay.hide(),e.body.removeClass(c+"_active")),e=this,i(),this.overlay.show();var d=this;setTimeout(function(){d.body.addClass(c+"_active"),setTimeout(function(){d.busy=!1,d.modal.trigger("opened")},d.td+50)},25)}},b.prototype.close=function(){if(!this.busy){this.busy=!0,this.modal.trigger("close"),this.settings.hashTracking&&this.modal.attr("data-"+c+"-id")===location.hash.substr(1)&&(location.hash="",a(window).scrollTop(f)),this.body.removeClass(c+"_active");var b=this;setTimeout(function(){b.overlay.hide(),j(),b.busy=!1,b.modal.trigger("closed")},b.td+50)}},a&&(a.fn[c]=function(d){var e;return this.each(function(f,g){var h=a(g);null==h.data(c)&&(e=new b(h,d),h.data(c,e.index),e.settings.hashTracking&&h.attr("data-"+c+"-id")===location.hash.substr(1)&&e.open())}),e}),a(document).ready(function(){a(document).on("click","[data-"+c+"-target]",function(b){b.preventDefault();var d=b.currentTarget,e=d.getAttribute("data-"+c+"-target"),f=a("[data-"+c+"-id="+e+"]");a[c].lookup[f.data(c)].open()}),a(document).find("."+c).each(function(b,d){var e=a(d),f=e.data(c+"-options");f?("string"==typeof f||f instanceof String)&&(f=k(f)):f={},e[c](f)})});var l=function(b,d){var f=location.hash.replace("#","");if("undefined"==typeof d&&(d=!0),f){var g;try{g=a("[data-"+c+"-id="+f.replace(new RegExp("/","g"),"\\/")+"]")}catch(b){}if(g&&g.length){var h=a[c].lookup[g.data(c)];h&&h.settings.hashTracking&&h.open()}}else d&&e&&!e.busy&&e.settings.hashTracking&&e.close()};a(window).bind("hashchange."+c,l)}(window.jQuery||window.Zepto); \ No newline at end of file diff --git a/remodal.jquery.json b/remodal.jquery.json index a344622..136e4e1 100644 --- a/remodal.jquery.json +++ b/remodal.jquery.json @@ -14,7 +14,7 @@ "ui", "zepto" ], - "version": "0.1.7", + "version": "0.2.0", "author": { "name": "Ilya Makarov", "email": "dfrost.00@gmail.com",