From c60b9070040b57f898dd062e7e10043bfdef6791 Mon Sep 17 00:00:00 2001 From: VodkaBears Date: Fri, 20 Feb 2015 15:49:44 +0300 Subject: [PATCH] Release v0.6.2 --- CHANGELOG.md | 5 + bower.json | 2 +- dist/jquery.remodal.css | 2 +- dist/jquery.remodal.js | 863 +++++++++++++++++++------------------ dist/jquery.remodal.min.js | 4 +- package.json | 2 +- 6 files changed, 456 insertions(+), 422 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef1aa51..f046094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.6.2 +* Improved the codestyle. +* Used package.json instead of jquery.json. +* Updated dependencies. + ### 0.6.1 * Fix '#on' event handlers. diff --git a/bower.json b/bower.json index ce1b742..5ff1134 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "remodal", - "version": "0.6.1", + "version": "0.6.2", "homepage": "http://vodkabears.github.io/remodal/", "authors": [ "Ilya Makarov " diff --git a/dist/jquery.remodal.css b/dist/jquery.remodal.css index 97971b9..137073f 100644 --- a/dist/jquery.remodal.css +++ b/dist/jquery.remodal.css @@ -1,5 +1,5 @@ /* - * Remodal - v0.6.1 + * Remodal - v0.6.2 * Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking. * http://vodkabears.github.io/remodal/ * diff --git a/dist/jquery.remodal.js b/dist/jquery.remodal.js index b00df4f..9e834c5 100644 --- a/dist/jquery.remodal.js +++ b/dist/jquery.remodal.js @@ -1,5 +1,5 @@ /* - * Remodal - v0.6.1 + * Remodal - v0.6.2 * Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking. * http://vodkabears.github.io/remodal/ * @@ -7,474 +7,503 @@ * Under MIT License */ !(function($) { - "use strict"; - - /** - * Remodal settings - * @private - */ - var pluginName = "remodal", - namespace = window.remodalGlobals && window.remodalGlobals.namespace || pluginName, - defaults = $.extend({ - hashTracking: true, - closeOnConfirm: true, - closeOnCancel: true, - closeOnEscape: true, - closeOnAnyClick: true - }, window.remodalGlobals && window.remodalGlobals.defaults), - - // Current modal - current, - - // Scroll position - scrollTop; - - /** - * Get a transition duration in ms - * @param {jQuery} $elem - * @return {Number} - * @private - */ - function getTransitionDuration($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") || - "0s", - 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") || - "0s", - max, len, num, i; - - duration = duration.split(", "); - delay = delay.split(", "); - - // The duration length is the same as the delay length - for (i = 0, len = duration.length, max = Number.NEGATIVE_INFINITY; i < len; i++) { - num = parseFloat(duration[i]) + parseFloat(delay[i]); - - if (num > max) { - max = num; - } - } + 'use strict'; + + /** + * Name of the plugin + * @private + * @type {String} + */ + var pluginName = 'remodal'; + + /** + * Namespace for CSS and events + * @private + * @type {String} + */ + var namespace = window.remodalGlobals && window.remodalGlobals.namespace || pluginName; + + /** + * Default settings + * @private + * @type {Object} + */ + var defaults = $.extend({ + hashTracking: true, + closeOnConfirm: true, + closeOnCancel: true, + closeOnEscape: true, + closeOnAnyClick: true + }, window.remodalGlobals && window.remodalGlobals.defaults); + + /** + * Current modal + * @private + * @type {Remodal} + */ + var current; + + /** + * Scrollbar position + * @private + * @type {Number} + */ + var scrollTop; + + /** + * Get a transition duration in ms + * @private + * @param {jQuery} $elem + * @return {Number} + */ + function getTransitionDuration($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') || + '0s'; + + 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') || + '0s'; + + var max; + var len; + var num; + var i; + + duration = duration.split(', '); + delay = delay.split(', '); + + // The duration length is the same as the delay length + for (i = 0, len = duration.length, max = Number.NEGATIVE_INFINITY; i < len; i++) { + num = parseFloat(duration[i]) + parseFloat(delay[i]); + + if (num > max) { + max = num; + } + } - return num * 1000; + return num * 1000; + } + + /** + * Get a scrollbar width + * @private + * @return {Number} + */ + function getScrollbarWidth() { + if ($(document.body).height() <= $(window).height()) { + return 0; } - /** - * Get a scrollbar width - * @return {Number} - * @private - */ - function getScrollbarWidth() { - if ($(document.body).height() <= $(window).height()) { - return 0; - } + var outer = document.createElement('div'); + var inner = document.createElement('div'); + var widthNoScroll; + var widthWithScroll; - var outer = document.createElement("div"), - inner = document.createElement("div"), - widthNoScroll, - widthWithScroll; + outer.style.visibility = 'hidden'; + outer.style.width = '100px'; + document.body.appendChild(outer); - outer.style.visibility = "hidden"; - outer.style.width = "100px"; - document.body.appendChild(outer); + widthNoScroll = outer.offsetWidth; - widthNoScroll = outer.offsetWidth; + // Force scrollbars + outer.style.overflow = 'scroll'; - // Force scrollbars - outer.style.overflow = "scroll"; + // Add inner div + inner.style.width = '100%'; + outer.appendChild(inner); - // Add innerdiv - inner.style.width = "100%"; - outer.appendChild(inner); + widthWithScroll = inner.offsetWidth; - widthWithScroll = inner.offsetWidth; + // Remove divs + outer.parentNode.removeChild(outer); - // Remove divs - outer.parentNode.removeChild(outer); + return widthNoScroll - widthWithScroll; + } - return widthNoScroll - widthWithScroll; - } + /** + * Lock the screen + * @private + */ + function lockScreen() { + var $html = $('html'); + var lockedClass = namespace + '-is-locked'; + var paddingRight; + var $body; - /** - * Lock screen - * @private - */ - function lockScreen() { - var $html = $("html"), - lockedClass = namespace + "-is-locked", - $body, - paddingRight; + if (!$html.hasClass(lockedClass)) { + $body = $(document.body); - if (!$html.hasClass(lockedClass)) { - $body = $(document.body); + // Zepto does not support '-=', '+=' in the `css` method + paddingRight = parseInt($body.css('padding-right'), 10) + getScrollbarWidth(); - // Zepto does not support '-=', '+=' in the `css` method - paddingRight = parseInt($body.css("padding-right"), 10) + getScrollbarWidth(); + $body.css('padding-right', paddingRight + 'px'); + $html.addClass(lockedClass); + } + } + + /** + * Unlock the screen + * @private + */ + function unlockScreen() { + var $html = $('html'); + var lockedClass = namespace + '-is-locked'; + var paddingRight; + var $body; + + if ($html.hasClass(lockedClass)) { + $body = $(document.body); + + // Zepto does not support '-=', '+=' in the `css` method + paddingRight = parseInt($body.css('padding-right'), 10) - getScrollbarWidth(); + + $body.css('padding-right', paddingRight + 'px'); + $html.removeClass(lockedClass); + } + } + + /** + * Parse a string with options + * @private + * @param str + * @returns {Object} + */ + function parseOptions(str) { + var obj = {}; + var arr; + var len; + var val; + var i; + + // Remove spaces before and after delimiters + str = str.replace(/\s*:\s*/g, ':').replace(/\s*,\s*/g, ','); + + // Parse a string + arr = str.split(','); + for (i = 0, len = arr.length; i < len; i++) { + arr[i] = arr[i].split(':'); + val = arr[i][1]; + + // Convert a string value if it is like a boolean + if (typeof val === 'string' || val instanceof String) { + val = val === 'true' || (val === 'false' ? false : val); + } + + // Convert a 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; + } - $body.css("padding-right", paddingRight + "px"); - $html.addClass(lockedClass); - } + return obj; + } + + /** + * Remodal constructor + * @param {jQuery} $modal + * @param {Object} options + * @constructor + */ + function Remodal($modal, options) { + var remodal = this; + var tdOverlay; + var tdModal; + var tdBg; + + remodal.settings = $.extend({}, defaults, options); + + // Build DOM + remodal.$body = $(document.body); + remodal.$overlay = $('.' + namespace + '-overlay'); + + if (!remodal.$overlay.length) { + remodal.$overlay = $('
').addClass(namespace + '-overlay'); + remodal.$body.append(remodal.$overlay); } - /** - * Unlock screen - * @private - */ - function unlockScreen() { - var $html = $("html"), - lockedClass = namespace + "-is-locked", - $body, - paddingRight; + remodal.$bg = $('.' + namespace + '-bg'); + remodal.$closeButton = $('').addClass(namespace + '-close'); + remodal.$wrapper = $('
').addClass(namespace + '-wrapper'); + remodal.$modal = $modal; + remodal.$modal.addClass(namespace); + remodal.$modal.css('visibility', 'visible'); + + remodal.$modal.append(remodal.$closeButton); + remodal.$wrapper.append(remodal.$modal); + remodal.$body.append(remodal.$wrapper); + remodal.$confirmButton = remodal.$modal.find('.' + namespace + '-confirm'); + remodal.$cancelButton = remodal.$modal.find('.' + namespace + '-cancel'); + + // Calculate timeouts + tdOverlay = getTransitionDuration(remodal.$overlay); + tdModal = getTransitionDuration(remodal.$modal); + tdBg = getTransitionDuration(remodal.$bg); + remodal.td = tdModal > tdOverlay ? tdModal : tdOverlay; + remodal.td = tdBg > remodal.td ? tdBg : remodal.td; + + // Add the close button event listener + remodal.$wrapper.on('click.' + namespace, '.' + namespace + '-close', function(e) { + e.preventDefault(); + + remodal.close(); + }); - if ($html.hasClass(lockedClass)) { - $body = $(document.body); + // Add the cancel button event listener + remodal.$wrapper.on('click.' + namespace, '.' + namespace + '-cancel', function(e) { + e.preventDefault(); - // Zepto does not support '-=', '+=' in the `css` method - paddingRight = parseInt($body.css("padding-right"), 10) - getScrollbarWidth(); + remodal.$modal.trigger('cancel'); - $body.css("padding-right", paddingRight + "px"); - $html.removeClass(lockedClass); - } - } + if (remodal.settings.closeOnCancel) { + remodal.close('cancellation'); + } + }); - /** - * Parse string with options - * @param str - * @returns {Object} - * @private - */ - function parseOptions(str) { - var obj = {}, - arr, len, val, i; - - // Remove spaces before and after delimiters - str = str.replace(/\s*:\s*/g, ":").replace(/\s*,\s*/g, ","); - - // Parse string - arr = str.split(","); - 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; - } + // Add the confirm button event listener + remodal.$wrapper.on('click.' + namespace, '.' + namespace + '-confirm', function(e) { + e.preventDefault(); - return obj; - } + remodal.$modal.trigger('confirm'); - /** - * Remodal constructor - * @param {jQuery} $modal - * @param {Object} options - * @constructor - */ - function Remodal($modal, options) { - var remodal = this, - tdOverlay, - tdModal, - tdBg; - - remodal.settings = $.extend({}, defaults, options); - - // Build DOM - remodal.$body = $(document.body); - remodal.$overlay = $("." + namespace + "-overlay"); - - if (!remodal.$overlay.length) { - remodal.$overlay = $("
").addClass(namespace + "-overlay"); - remodal.$body.append(remodal.$overlay); - } + if (remodal.settings.closeOnConfirm) { + remodal.close('confirmation'); + } + }); - remodal.$bg = $("." + namespace + "-bg"); - remodal.$closeButton = $("") - .addClass(namespace + "-close"); - remodal.$wrapper = $("
").addClass(namespace + "-wrapper"); - remodal.$modal = $modal; - remodal.$modal.addClass(namespace); - remodal.$modal.css("visibility", "visible"); - - remodal.$modal.append(remodal.$closeButton); - remodal.$wrapper.append(remodal.$modal); - remodal.$body.append(remodal.$wrapper); - remodal.$confirmButton = remodal.$modal.find("." + namespace + "-confirm"); - remodal.$cancelButton = remodal.$modal.find("." + namespace + "-cancel"); - - // Calculate timeouts - tdOverlay = getTransitionDuration(remodal.$overlay); - tdModal = getTransitionDuration(remodal.$modal); - tdBg = getTransitionDuration(remodal.$bg); - remodal.td = tdModal > tdOverlay ? tdModal : tdOverlay; - remodal.td = tdBg > remodal.td ? tdBg : remodal.td; - - // Add close button event listener - remodal.$wrapper.on("click." + namespace, "." + namespace + "-close", function(e) { - e.preventDefault(); - - remodal.close(); - }); - - // Add cancel button event listener - remodal.$wrapper.on("click." + namespace, "." + namespace + "-cancel", function(e) { - e.preventDefault(); - - remodal.$modal.trigger("cancel"); - - if (remodal.settings.closeOnCancel) { - remodal.close("cancellation"); - } - }); - - // Add confirm button event listener - remodal.$wrapper.on("click." + namespace, "." + namespace + "-confirm", function(e) { - e.preventDefault(); - - remodal.$modal.trigger("confirm"); - - if (remodal.settings.closeOnConfirm) { - remodal.close("confirmation"); - } - }); - - // Add keyboard event listener - $(document).on("keyup." + namespace, function(e) { - if (e.keyCode === 27 && remodal.settings.closeOnEscape) { - remodal.close(); - } - }); - - // Add overlay event listener - remodal.$wrapper.on("click." + namespace, function(e) { - var $target = $(e.target); - - if (!$target.hasClass(namespace + "-wrapper")) { - return; - } - - if (remodal.settings.closeOnAnyClick) { - remodal.close(); - } - }); - - remodal.index = $[pluginName].lookup.push(remodal) - 1; - remodal.busy = false; - } + // Add the keyboard event listener + $(document).on('keyup.' + namespace, function(e) { + if (e.keyCode === 27 && remodal.settings.closeOnEscape) { + remodal.close(); + } + }); - /** - * Open the modal window - * @public - */ - Remodal.prototype.open = function() { - // Check if animation is complete - if (this.busy) { - return; - } + // Add the overlay event listener + remodal.$wrapper.on('click.' + namespace, function(e) { + var $target = $(e.target); - var remodal = this, - id; + if (!$target.hasClass(namespace + '-wrapper')) { + return; + } - remodal.busy = true; - remodal.$modal.trigger("open"); + if (remodal.settings.closeOnAnyClick) { + remodal.close(); + } + }); - id = remodal.$modal.attr("data-" + pluginName + "-id"); + remodal.index = $[pluginName].lookup.push(remodal) - 1; + remodal.busy = false; + } - if (id && remodal.settings.hashTracking) { - scrollTop = $(window).scrollTop(); - location.hash = id; - } + /** + * Open a modal window + * @public + */ + Remodal.prototype.open = function() { - if (current && current !== remodal) { - current.$overlay.hide(); - current.$wrapper.hide(); - current.$body.removeClass(namespace + "-is-active"); - } + // Check if the animation was completed + if (this.busy) { + return; + } - current = remodal; + var remodal = this; + var id; - lockScreen(); - remodal.$overlay.show(); - remodal.$wrapper.show(); + remodal.busy = true; + remodal.$modal.trigger('open'); - setTimeout(function() { - remodal.$body.addClass(namespace + "-is-active"); + id = remodal.$modal.attr('data-' + pluginName + '-id'); - setTimeout(function() { - remodal.busy = false; - remodal.$modal.trigger("opened"); - }, remodal.td + 50); - }, 25); - }; + if (id && remodal.settings.hashTracking) { + scrollTop = $(window).scrollTop(); + location.hash = id; + } - /** - * Close the modal window - * @public - * @param {String|undefined} reason A reason to close - */ - Remodal.prototype.close = function(reason) { + if (current && current !== remodal) { + current.$overlay.hide(); + current.$wrapper.hide(); + current.$body.removeClass(namespace + '-is-active'); + } - // Check if the animation was completed - if (this.busy) { - return; - } + current = remodal; - this.busy = true; - this.$modal.trigger({ - type: "close", - reason: reason - }); + lockScreen(); + remodal.$overlay.show(); + remodal.$wrapper.show(); - var remodal = this; + setTimeout(function() { + remodal.$body.addClass(namespace + '-is-active'); - if (remodal.settings.hashTracking && - remodal.$modal.attr("data-" + pluginName + "-id") === location.hash.substr(1)) { + setTimeout(function() { + remodal.busy = false; + remodal.$modal.trigger('opened'); + }, remodal.td + 50); + }, 25); + }; + + /** + * Close a modal window + * @public + * @param {String|undefined} reason A reason to close + */ + Remodal.prototype.close = function(reason) { + + // Check if the animation was completed + if (this.busy) { + return; + } - location.hash = ""; - $(window).scrollTop(scrollTop); - } + var remodal = this; - remodal.$body.removeClass(namespace + "-is-active"); - - setTimeout(function() { - remodal.$overlay.hide(); - remodal.$wrapper.hide(); - unlockScreen(); - - remodal.busy = false; - remodal.$modal.trigger({ - type: "closed", - reason: reason - }); - }, remodal.td + 50); - }; - - /** - * Special plugin object for instances. - * @type {Object} - * @public - */ - $[pluginName] = { - lookup: [] - }; - - /** - * Plugin constructor - * @param {Object} options - * @returns {JQuery} - * @constructor - */ - $.fn[pluginName] = function(opts) { - var instance, - $elem; - - this.each(function(index, elem) { - $elem = $(elem); - - if ($elem.data(pluginName) == null) { - instance = new Remodal($elem, opts); - $elem.data(pluginName, instance.index); - - if (instance.settings.hashTracking && - $elem.attr("data-" + pluginName + "-id") === location.hash.substr(1)) { - - instance.open(); - } - } else { - instance = $[pluginName].lookup[$elem.data(pluginName)]; - } - }); - - return instance; - }; - - $(document).ready(function() { - - // data-remodal-target opens a modal window with the special Id. - $(document).on("click", "[data-" + pluginName + "-target]", function(e) { - e.preventDefault(); - - var elem = e.currentTarget, - id = elem.getAttribute("data-" + pluginName + "-target"), - $target = $("[data-" + pluginName + "-id=" + id + "]"); - - $[pluginName].lookup[$target.data(pluginName)].open(); - }); - - // Auto initialization of modal windows. - // They should have the 'remodal' class attribute. - // Also you can write `data-remodal-options` attribute to pass params into the modal. - $(document).find("." + namespace).each(function(i, container) { - var $container = $(container), - options = $container.data(pluginName + "-options"); - - if (!options) { - options = {}; - } else if (typeof options === "string" || options instanceof String) { - options = parseOptions(options); - } - - $container[pluginName](options); - }); + remodal.busy = true; + remodal.$modal.trigger({ + type: 'close', + reason: reason }); - /** - * Hashchange handler - * @param {Event} e - * @param {Boolean} [closeOnEmptyHash=true] - * @private - */ - function hashHandler(e, closeOnEmptyHash) { - var id = location.hash.replace("#", ""), - instance, - $elem; - - if (typeof closeOnEmptyHash === "undefined") { - closeOnEmptyHash = true; + if (remodal.settings.hashTracking && + remodal.$modal.attr('data-' + pluginName + '-id') === location.hash.substr(1)) { + + location.hash = ''; + $(window).scrollTop(scrollTop); + } + + remodal.$body.removeClass(namespace + '-is-active'); + + setTimeout(function() { + remodal.$overlay.hide(); + remodal.$wrapper.hide(); + unlockScreen(); + + remodal.busy = false; + remodal.$modal.trigger({ + type: 'closed', + reason: reason + }); + }, remodal.td + 50); + }; + + /** + * Special plugin object for instances. + * @public + * @type {Object} + */ + $[pluginName] = { + lookup: [] + }; + + /** + * Plugin constructor + * @param {Object} options + * @returns {JQuery} + * @constructor + */ + $.fn[pluginName] = function(opts) { + var instance; + var $elem; + + this.each(function(index, elem) { + $elem = $(elem); + + if ($elem.data(pluginName) == null) { + instance = new Remodal($elem, opts); + $elem.data(pluginName, instance.index); + + if (instance.settings.hashTracking && + $elem.attr('data-' + pluginName + '-id') === location.hash.substr(1)) { + + instance.open(); } + } else { + instance = $[pluginName].lookup[$elem.data(pluginName)]; + } + }); + + return instance; + }; + + $(document).ready(function() { + + // data-remodal-target opens a modal window with the special Id. + $(document).on('click', '[data-' + pluginName + '-target]', function(e) { + e.preventDefault(); + + var elem = e.currentTarget; + var id = elem.getAttribute('data-' + pluginName + '-target'); + var $target = $('[data-' + pluginName + '-id=' + id + ']'); - if (!id) { - if (closeOnEmptyHash) { + $[pluginName].lookup[$target.data(pluginName)].open(); + }); - // Check if we have currently opened modal and animation is complete - if (current && !current.busy && current.settings.hashTracking) { - current.close(); - } - } - } else { + // Auto initialization of modal windows. + // They should have the 'remodal' class attribute. + // Also you can write `data-remodal-options` attribute to pass params into the modal. + $(document).find('.' + namespace).each(function(i, container) { + var $container = $(container); + var options = $container.data(pluginName + '-options'); - // Catch syntax error if your hash is bad - try { - $elem = $( - "[data-" + pluginName + "-id=" + - id.replace(new RegExp("/", "g"), "\\/") + "]" - ); - } catch (err) {} + if (!options) { + options = {}; + } else if (typeof options === 'string' || options instanceof String) { + options = parseOptions(options); + } - if ($elem && $elem.length) { - instance = $[pluginName].lookup[$elem.data(pluginName)]; + $container[pluginName](options); + }); + }); + + /** + * Hashchange handler + * @private + * @param {Event} e + * @param {Boolean} [closeOnEmptyHash=true] + */ + function hashHandler(e, closeOnEmptyHash) { + var id = location.hash.replace('#', ''); + var instance; + var $elem; + + if (typeof closeOnEmptyHash === 'undefined') { + closeOnEmptyHash = true; + } - if (instance && instance.settings.hashTracking) { - instance.open(); - } - } + if (!id) { + if (closeOnEmptyHash) { + // Check if we have currently opened modal and animation was completed + if (current && !current.busy && current.settings.hashTracking) { + current.close(); } + } + } else { + + // Catch syntax error if your hash is bad + try { + $elem = $( + '[data-' + pluginName + '-id=' + + id.replace(new RegExp('/', 'g'), '\\/') + ']' + ); + } catch (err) {} + + if ($elem && $elem.length) { + instance = $[pluginName].lookup[$elem.data(pluginName)]; + + if (instance && instance.settings.hashTracking) { + instance.open(); + } + } + } + } - $(window).bind("hashchange." + namespace, hashHandler); + $(window).bind('hashchange.' + namespace, hashHandler); })(window.jQuery || window.Zepto); diff --git a/dist/jquery.remodal.min.js b/dist/jquery.remodal.min.js index 04f7310..51ae4cd 100644 --- a/dist/jquery.remodal.min.js +++ b/dist/jquery.remodal.min.js @@ -1,9 +1,9 @@ /* - * Remodal - v0.6.1 + * Remodal - v0.6.2 * 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(a){var b,c,d,e,f=a.css("transition-duration")||a.css("-webkit-transition-duration")||a.css("-moz-transition-duration")||a.css("-o-transition-duration")||a.css("-ms-transition-duration")||"0s",g=a.css("transition-delay")||a.css("-webkit-transition-delay")||a.css("-moz-transition-delay")||a.css("-o-transition-delay")||a.css("-ms-transition-delay")||"0s";for(f=f.split(", "),g=g.split(", "),e=0,c=f.length,b=Number.NEGATIVE_INFINITY;c>e;e++)d=parseFloat(f[e])+parseFloat(g[e]),d>b&&(b=d);return 1e3*d}function c(){if(a(document.body).height()<=a(window).height())return 0;var b,c,d=document.createElement("div"),e=document.createElement("div");return d.style.visibility="hidden",d.style.width="100px",document.body.appendChild(d),b=d.offsetWidth,d.style.overflow="scroll",e.style.width="100%",d.appendChild(e),c=e.offsetWidth,d.parentNode.removeChild(d),b-c}function d(){var b,d,e=a("html"),f=l+"-is-locked";e.hasClass(f)||(b=a(document.body),d=parseInt(b.css("padding-right"),10)+c(),b.css("padding-right",d+"px"),e.addClass(f))}function e(){var b,d,e=a("html"),f=l+"-is-locked";e.hasClass(f)&&(b=a(document.body),d=parseInt(b.css("padding-right"),10)-c(),b.css("padding-right",d+"px"),e.removeClass(f))}function f(a){var b,c,d,e,f={};for(a=a.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,","),b=a.split(","),e=0,c=b.length;c>e;e++)b[e]=b[e].split(":"),d=b[e][1],("string"==typeof d||d instanceof String)&&(d="true"===d||("false"===d?!1:d)),("string"==typeof d||d instanceof String)&&(d=isNaN(d)?d:+d),f[b[e][0]]=d;return f}function g(c,d){var e,f,g,h=this;h.settings=a.extend({},m,d),h.$body=a(document.body),h.$overlay=a("."+l+"-overlay"),h.$overlay.length||(h.$overlay=a("
").addClass(l+"-overlay"),h.$body.append(h.$overlay)),h.$bg=a("."+l+"-bg"),h.$closeButton=a("").addClass(l+"-close"),h.$wrapper=a("
").addClass(l+"-wrapper"),h.$modal=c,h.$modal.addClass(l),h.$modal.css("visibility","visible"),h.$modal.append(h.$closeButton),h.$wrapper.append(h.$modal),h.$body.append(h.$wrapper),h.$confirmButton=h.$modal.find("."+l+"-confirm"),h.$cancelButton=h.$modal.find("."+l+"-cancel"),e=b(h.$overlay),f=b(h.$modal),g=b(h.$bg),h.td=f>e?f:e,h.td=g>h.td?g:h.td,h.$wrapper.on("click."+l,"."+l+"-close",function(a){a.preventDefault(),h.close()}),h.$wrapper.on("click."+l,"."+l+"-cancel",function(a){a.preventDefault(),h.$modal.trigger("cancel"),h.settings.closeOnCancel&&h.close("cancellation")}),h.$wrapper.on("click."+l,"."+l+"-confirm",function(a){a.preventDefault(),h.$modal.trigger("confirm"),h.settings.closeOnConfirm&&h.close("confirmation")}),a(document).on("keyup."+l,function(a){27===a.keyCode&&h.settings.closeOnEscape&&h.close()}),h.$wrapper.on("click."+l,function(b){var c=a(b.target);c.hasClass(l+"-wrapper")&&h.settings.closeOnAnyClick&&h.close()}),h.index=a[k].lookup.push(h)-1,h.busy=!1}function h(b,c){var d,e,f=location.hash.replace("#","");if("undefined"==typeof c&&(c=!0),f){try{e=a("[data-"+k+"-id="+f.replace(new RegExp("/","g"),"\\/")+"]")}catch(g){}e&&e.length&&(d=a[k].lookup[e.data(k)],d&&d.settings.hashTracking&&d.open())}else c&&i&&!i.busy&&i.settings.hashTracking&&i.close()}var i,j,k="remodal",l=window.remodalGlobals&&window.remodalGlobals.namespace||k,m=a.extend({hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0,closeOnEscape:!0,closeOnAnyClick:!0},window.remodalGlobals&&window.remodalGlobals.defaults);g.prototype.open=function(){if(!this.busy){var b,c=this;c.busy=!0,c.$modal.trigger("open"),b=c.$modal.attr("data-"+k+"-id"),b&&c.settings.hashTracking&&(j=a(window).scrollTop(),location.hash=b),i&&i!==c&&(i.$overlay.hide(),i.$wrapper.hide(),i.$body.removeClass(l+"-is-active")),i=c,d(),c.$overlay.show(),c.$wrapper.show(),setTimeout(function(){c.$body.addClass(l+"-is-active"),setTimeout(function(){c.busy=!1,c.$modal.trigger("opened")},c.td+50)},25)}},g.prototype.close=function(b){if(!this.busy){this.busy=!0,this.$modal.trigger({type:"close",reason:b});var c=this;c.settings.hashTracking&&c.$modal.attr("data-"+k+"-id")===location.hash.substr(1)&&(location.hash="",a(window).scrollTop(j)),c.$body.removeClass(l+"-is-active"),setTimeout(function(){c.$overlay.hide(),c.$wrapper.hide(),e(),c.busy=!1,c.$modal.trigger({type:"closed",reason:b})},c.td+50)}},a[k]={lookup:[]},a.fn[k]=function(b){var c,d;return this.each(function(e,f){d=a(f),null==d.data(k)?(c=new g(d,b),d.data(k,c.index),c.settings.hashTracking&&d.attr("data-"+k+"-id")===location.hash.substr(1)&&c.open()):c=a[k].lookup[d.data(k)]}),c},a(document).ready(function(){a(document).on("click","[data-"+k+"-target]",function(b){b.preventDefault();var c=b.currentTarget,d=c.getAttribute("data-"+k+"-target"),e=a("[data-"+k+"-id="+d+"]");a[k].lookup[e.data(k)].open()}),a(document).find("."+l).each(function(b,c){var d=a(c),e=d.data(k+"-options");e?("string"==typeof e||e instanceof String)&&(e=f(e)):e={},d[k](e)})}),a(window).bind("hashchange."+l,h)}(window.jQuery||window.Zepto); \ No newline at end of file +!function(a){"use strict";function b(a){var b,c,d,e,f=a.css("transition-duration")||a.css("-webkit-transition-duration")||a.css("-moz-transition-duration")||a.css("-o-transition-duration")||a.css("-ms-transition-duration")||"0s",g=a.css("transition-delay")||a.css("-webkit-transition-delay")||a.css("-moz-transition-delay")||a.css("-o-transition-delay")||a.css("-ms-transition-delay")||"0s";for(f=f.split(", "),g=g.split(", "),e=0,c=f.length,b=Number.NEGATIVE_INFINITY;c>e;e++)d=parseFloat(f[e])+parseFloat(g[e]),d>b&&(b=d);return 1e3*d}function c(){if(a(document.body).height()<=a(window).height())return 0;var b,c,d=document.createElement("div"),e=document.createElement("div");return d.style.visibility="hidden",d.style.width="100px",document.body.appendChild(d),b=d.offsetWidth,d.style.overflow="scroll",e.style.width="100%",d.appendChild(e),c=e.offsetWidth,d.parentNode.removeChild(d),b-c}function d(){var b,d,e=a("html"),f=l+"-is-locked";e.hasClass(f)||(d=a(document.body),b=parseInt(d.css("padding-right"),10)+c(),d.css("padding-right",b+"px"),e.addClass(f))}function e(){var b,d,e=a("html"),f=l+"-is-locked";e.hasClass(f)&&(d=a(document.body),b=parseInt(d.css("padding-right"),10)-c(),d.css("padding-right",b+"px"),e.removeClass(f))}function f(a){var b,c,d,e,f={};for(a=a.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,","),b=a.split(","),e=0,c=b.length;c>e;e++)b[e]=b[e].split(":"),d=b[e][1],("string"==typeof d||d instanceof String)&&(d="true"===d||("false"===d?!1:d)),("string"==typeof d||d instanceof String)&&(d=isNaN(d)?d:+d),f[b[e][0]]=d;return f}function g(c,d){var e,f,g,h=this;h.settings=a.extend({},m,d),h.$body=a(document.body),h.$overlay=a("."+l+"-overlay"),h.$overlay.length||(h.$overlay=a("
").addClass(l+"-overlay"),h.$body.append(h.$overlay)),h.$bg=a("."+l+"-bg"),h.$closeButton=a('').addClass(l+"-close"),h.$wrapper=a("
").addClass(l+"-wrapper"),h.$modal=c,h.$modal.addClass(l),h.$modal.css("visibility","visible"),h.$modal.append(h.$closeButton),h.$wrapper.append(h.$modal),h.$body.append(h.$wrapper),h.$confirmButton=h.$modal.find("."+l+"-confirm"),h.$cancelButton=h.$modal.find("."+l+"-cancel"),e=b(h.$overlay),f=b(h.$modal),g=b(h.$bg),h.td=f>e?f:e,h.td=g>h.td?g:h.td,h.$wrapper.on("click."+l,"."+l+"-close",function(a){a.preventDefault(),h.close()}),h.$wrapper.on("click."+l,"."+l+"-cancel",function(a){a.preventDefault(),h.$modal.trigger("cancel"),h.settings.closeOnCancel&&h.close("cancellation")}),h.$wrapper.on("click."+l,"."+l+"-confirm",function(a){a.preventDefault(),h.$modal.trigger("confirm"),h.settings.closeOnConfirm&&h.close("confirmation")}),a(document).on("keyup."+l,function(a){27===a.keyCode&&h.settings.closeOnEscape&&h.close()}),h.$wrapper.on("click."+l,function(b){var c=a(b.target);c.hasClass(l+"-wrapper")&&h.settings.closeOnAnyClick&&h.close()}),h.index=a[k].lookup.push(h)-1,h.busy=!1}function h(b,c){var d,e,f=location.hash.replace("#","");if("undefined"==typeof c&&(c=!0),f){try{e=a("[data-"+k+"-id="+f.replace(new RegExp("/","g"),"\\/")+"]")}catch(g){}e&&e.length&&(d=a[k].lookup[e.data(k)],d&&d.settings.hashTracking&&d.open())}else c&&i&&!i.busy&&i.settings.hashTracking&&i.close()}var i,j,k="remodal",l=window.remodalGlobals&&window.remodalGlobals.namespace||k,m=a.extend({hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0,closeOnEscape:!0,closeOnAnyClick:!0},window.remodalGlobals&&window.remodalGlobals.defaults);g.prototype.open=function(){if(!this.busy){var b,c=this;c.busy=!0,c.$modal.trigger("open"),b=c.$modal.attr("data-"+k+"-id"),b&&c.settings.hashTracking&&(j=a(window).scrollTop(),location.hash=b),i&&i!==c&&(i.$overlay.hide(),i.$wrapper.hide(),i.$body.removeClass(l+"-is-active")),i=c,d(),c.$overlay.show(),c.$wrapper.show(),setTimeout(function(){c.$body.addClass(l+"-is-active"),setTimeout(function(){c.busy=!1,c.$modal.trigger("opened")},c.td+50)},25)}},g.prototype.close=function(b){if(!this.busy){var c=this;c.busy=!0,c.$modal.trigger({type:"close",reason:b}),c.settings.hashTracking&&c.$modal.attr("data-"+k+"-id")===location.hash.substr(1)&&(location.hash="",a(window).scrollTop(j)),c.$body.removeClass(l+"-is-active"),setTimeout(function(){c.$overlay.hide(),c.$wrapper.hide(),e(),c.busy=!1,c.$modal.trigger({type:"closed",reason:b})},c.td+50)}},a[k]={lookup:[]},a.fn[k]=function(b){var c,d;return this.each(function(e,f){d=a(f),null==d.data(k)?(c=new g(d,b),d.data(k,c.index),c.settings.hashTracking&&d.attr("data-"+k+"-id")===location.hash.substr(1)&&c.open()):c=a[k].lookup[d.data(k)]}),c},a(document).ready(function(){a(document).on("click","[data-"+k+"-target]",function(b){b.preventDefault();var c=b.currentTarget,d=c.getAttribute("data-"+k+"-target"),e=a("[data-"+k+"-id="+d+"]");a[k].lookup[e.data(k)].open()}),a(document).find("."+l).each(function(b,c){var d=a(c),e=d.data(k+"-options");e?("string"==typeof e||e instanceof String)&&(e=f(e)):e={},d[k](e)})}),a(window).bind("hashchange."+l,h)}(window.jQuery||window.Zepto); \ No newline at end of file diff --git a/package.json b/package.json index a2c7b97..1ecfad7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "remodal", - "version": "0.6.1", + "version": "0.6.2", "description": "Flat, responsive, lightweight, easy customizable modal window plugin with declarative state notation and hash tracking.", "keywords": [ "jquery-plugin",