From 7e26b30c18369709dfaf6be4170196d9f287838f Mon Sep 17 00:00:00 2001 From: Antonio Lettieri Date: Thu, 26 Jan 2012 14:52:20 -0800 Subject: [PATCH 1/3] 1. Included onOpening, onOpened, onClosing, onClosed callback handlers 2. Moved the helper methods to the top. --- jquery.reveal.js | 61 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/jquery.reveal.js b/jquery.reveal.js index 53ba3d9..f1aa4ff 100644 --- a/jquery.reveal.js +++ b/jquery.reveal.js @@ -16,10 +16,14 @@ $.fn.reveal = function (options) { var defaults = { - animation: 'fadeAndPop', // fade, fadeAndPop, none - animationSpeed: 300, // how fast animtions are - closeOnBackgroundClick: true, // if you click background will modal close? - dismissModalClass: 'close-reveal-modal' // the class of a button or element that will close an open modal + animation: 'fadeAndPop', // fade, fadeAndPop, none + animationSpeed: 300, // how fast animtions are + closeOnBackgroundClick: true, // if you click background will modal close? + dismissModalClass: 'close-reveal-modal', // the class of a button or element that will close an open modal + onOpening: function(){}, // Callback when modal is ready to open + onOpened: function(){}, // Callback when modal is fully opened + onClosing: function(){}, // Callback when modal is preparing to close + onClosed: function(){} //Callback when modal is closed }; var options = $.extend({}, defaults, options); @@ -35,30 +39,60 @@ modalBg.fadeTo('fast', 0.8); } + + /* Internal callback handlers */ + + /** + * @func: modalOpened + * @desc: calls the unlockModal method. Then executes the onOpened callback. + */ + function modalOpened() { + unlockModal(); + options.onOpened.call( [], modal ); // Execute the onOpened callback - modal is fully visible + } + /** + * @func: modalClosed + * @desc: calls the unlockModal method. Then executes the onClosed callback. + */ + function modalClosed() { + unlockModal(); + options.onClosed.call( [], modal ); // Execute the onClosed callback - Modal is closed + } + + function unlockModal() { + locked = false; + } + + function lockModal() { + locked = true; + } + + function openAnimation() { modalBg.unbind('click.modalEvent'); $('.' + options.dismissModalClass).unbind('click.modalEvent'); if (!locked) { lockModal(); + options.onOpening.call( [], modal ); // Call onOpenig callback function - modal is preparing to open if (options.animation == "fadeAndPop") { modal.css({'top': $(document).scrollTop() - topOffset, 'opacity': 0, 'visibility': 'visible'}); modalBg.fadeIn(options.animationSpeed / 2); modal.delay(options.animationSpeed / 2).animate({ "top": $(document).scrollTop() + topMeasure + 'px', "opacity": 1 - }, options.animationSpeed, unlockModal); + }, options.animationSpeed, modalOpened); } if (options.animation == "fade") { modal.css({'opacity': 0, 'visibility': 'visible', 'top': $(document).scrollTop() + topMeasure}); modalBg.fadeIn(options.animationSpeed / 2); modal.delay(options.animationSpeed / 2).animate({ "opacity": 1 - }, options.animationSpeed, unlockModal); + }, options.animationSpeed, modalOpened); } if (options.animation == "none") { modal.css({'visibility': 'visible', 'top': $(document).scrollTop() + topMeasure}); modalBg.css({"display": "block"}); - unlockModal(); + modalOpened(); } } modal.unbind('reveal:open', openAnimation); @@ -68,6 +102,7 @@ function closeAnimation() { if (!locked) { lockModal(); + options.onClosing.call( [], modal ); // Call onClosing callback function - modal is preparing to close if (options.animation == "fadeAndPop") { modalBg.delay(options.animationSpeed).fadeOut(options.animationSpeed); modal.animate({ @@ -75,7 +110,7 @@ "opacity": 0 }, options.animationSpeed / 2, function () { modal.css({'top': topMeasure, 'opacity': 1, 'visibility': 'hidden'}); - unlockModal(); + modalClosed(); }); } if (options.animation == "fade") { @@ -84,7 +119,7 @@ "opacity" : 0 }, options.animationSpeed, function () { modal.css({'opacity': 1, 'visibility': 'hidden', 'top': topMeasure}); - unlockModal(); + modalClosed(); }); } if (options.animation == "none") { @@ -114,13 +149,7 @@ } }); - function unlockModal() { - locked = false; - } - - function lockModal() { - locked = true; - } + }); }; })(jQuery); From aa14ee44710535bfd6a4900c9560b953a3ced21e Mon Sep 17 00:00:00 2001 From: Antonio Lettieri Date: Thu, 26 Jan 2012 14:56:22 -0800 Subject: [PATCH 2/3] Moved unlockModal and lockModal above callback helpers. --- jquery.reveal.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/jquery.reveal.js b/jquery.reveal.js index f1aa4ff..27d84fe 100644 --- a/jquery.reveal.js +++ b/jquery.reveal.js @@ -39,34 +39,36 @@ modalBg.fadeTo('fast', 0.8); } - - /* Internal callback handlers */ - - /** - * @func: modalOpened - * @desc: calls the unlockModal method. Then executes the onOpened callback. - */ - function modalOpened() { - unlockModal(); - options.onOpened.call( [], modal ); // Execute the onOpened callback - modal is fully visible + function unlockModal() { + locked = false; } - /** - * @func: modalClosed - * @desc: calls the unlockModal method. Then executes the onClosed callback. - */ - function modalClosed() { - unlockModal(); - options.onClosed.call( [], modal ); // Execute the onClosed callback - Modal is closed + + function lockModal() { + locked = true; } - function unlockModal() { - locked = false; - } + /* Internal callback handlers */ - function lockModal() { - locked = true; + /** + * @func: modalOpened + * @desc: calls the unlockModal method. Then executes the onOpened callback. + */ + function modalOpened() { + unlockModal(); + options.onOpened.call( [], modal ); // Execute the onOpened callback - modal is fully visible + } + + /** + * @func: modalClosed + * @desc: calls the unlockModal method. Then executes the onClosed callback. + */ + function modalClosed() { + unlockModal(); + options.onClosed.call( [], modal ); // Execute the onClosed callback - Modal is closed } + + function openAnimation() { modalBg.unbind('click.modalEvent'); From 4a372b324fb0e903669c68ccfd1d2be1fd481fb1 Mon Sep 17 00:00:00 2001 From: Antonio Lettieri Date: Fri, 27 Jan 2012 09:34:57 -0800 Subject: [PATCH 3/3] Added internal helpers to handle the callback methods. --- jquery.reveal.js | 62 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/jquery.reveal.js b/jquery.reveal.js index 27d84fe..b121114 100644 --- a/jquery.reveal.js +++ b/jquery.reveal.js @@ -6,7 +6,6 @@ * http://www.opensource.org/licenses/mit-license.php */ - (function ($) { $('a[data-reveal-id]').live('click', function (event) { event.preventDefault(); @@ -20,10 +19,10 @@ animationSpeed: 300, // how fast animtions are closeOnBackgroundClick: true, // if you click background will modal close? dismissModalClass: 'close-reveal-modal', // the class of a button or element that will close an open modal - onOpening: function(){}, // Callback when modal is ready to open - onOpened: function(){}, // Callback when modal is fully opened - onClosing: function(){}, // Callback when modal is preparing to close - onClosed: function(){} //Callback when modal is closed + onOpening: function(){}, // Callback when modal is ready to open + onOpened: function(){}, // Callback when modal is fully opened + onClosing: function(){}, // Callback when modal is preparing to close + onClosed: function(){} // Callback when modal is closed }; var options = $.extend({}, defaults, options); @@ -39,15 +38,24 @@ modalBg.fadeTo('fast', 0.8); } - function unlockModal() { - locked = false; - } + function unlockModal() { + locked = false; + } - function lockModal() { - locked = true; - } + function lockModal() { + locked = true; + } - /* Internal callback handlers */ + /* ---- Internal callback helpers ---- */ + + /** + * @func: modalOpening + * @desc: calls the lockModal method. Then executes the onOpening callback. + */ + function modalOpening() { + lockModal(); + options.onOpening.call( [], modal ); // Execute the onOpening callback - modal is preparing to open + } /** * @func: modalOpened @@ -58,6 +66,15 @@ options.onOpened.call( [], modal ); // Execute the onOpened callback - modal is fully visible } + /** + * @func: modalClosing + * @desc: calls the lockModal method. Then executes the onClosing callback. + */ + function modalClosing() { + lockModal(); + options.onClosing.call( [], modal ); // Execute the onClosing callback - modal is preparing to close + } + /** * @func: modalClosed * @desc: calls the unlockModal method. Then executes the onClosed callback. @@ -74,27 +91,28 @@ modalBg.unbind('click.modalEvent'); $('.' + options.dismissModalClass).unbind('click.modalEvent'); if (!locked) { - lockModal(); - options.onOpening.call( [], modal ); // Call onOpenig callback function - modal is preparing to open + + modalOpening(); // Modal is preparing to open + if (options.animation == "fadeAndPop") { modal.css({'top': $(document).scrollTop() - topOffset, 'opacity': 0, 'visibility': 'visible'}); modalBg.fadeIn(options.animationSpeed / 2); modal.delay(options.animationSpeed / 2).animate({ "top": $(document).scrollTop() + topMeasure + 'px', "opacity": 1 - }, options.animationSpeed, modalOpened); + }, options.animationSpeed, modalOpened /* Modal has opened */ ); } if (options.animation == "fade") { modal.css({'opacity': 0, 'visibility': 'visible', 'top': $(document).scrollTop() + topMeasure}); modalBg.fadeIn(options.animationSpeed / 2); modal.delay(options.animationSpeed / 2).animate({ "opacity": 1 - }, options.animationSpeed, modalOpened); + }, options.animationSpeed, modalOpened /* Modal has opened */ ); } if (options.animation == "none") { modal.css({'visibility': 'visible', 'top': $(document).scrollTop() + topMeasure}); modalBg.css({"display": "block"}); - modalOpened(); + modalOpened(); /* Modal has opened */ } } modal.unbind('reveal:open', openAnimation); @@ -103,8 +121,9 @@ function closeAnimation() { if (!locked) { - lockModal(); - options.onClosing.call( [], modal ); // Call onClosing callback function - modal is preparing to close + + modalClosing(); // Modal is preparing to close + if (options.animation == "fadeAndPop") { modalBg.delay(options.animationSpeed).fadeOut(options.animationSpeed); modal.animate({ @@ -112,7 +131,7 @@ "opacity": 0 }, options.animationSpeed / 2, function () { modal.css({'top': topMeasure, 'opacity': 1, 'visibility': 'hidden'}); - modalClosed(); + modalClosed(); /* Modal has finished closing */ }); } if (options.animation == "fade") { @@ -121,12 +140,13 @@ "opacity" : 0 }, options.animationSpeed, function () { modal.css({'opacity': 1, 'visibility': 'hidden', 'top': topMeasure}); - modalClosed(); + modalClosed(); /* Modal has finished closing */ }); } if (options.animation == "none") { modal.css({'visibility': 'hidden', 'top': topMeasure}); modalBg.css({'display': 'none'}); + modalClosed(); /* Modal has finished closing */ } } modal.unbind('reveal:close', closeAnimation);