Skip to content

Commit

Permalink
Merge branch 'master' of github.com:zurb/foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Humphreys committed Feb 9, 2012
2 parents 265ae6b + e44a5c3 commit a78453c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 36 deletions.
97 changes: 61 additions & 36 deletions javascripts/jquery.reveal.js
Expand Up @@ -5,7 +5,7 @@
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/

/*globals jQuery */

(function ($) {
$('a[data-reveal-id]').live('click', function (event) {
Expand All @@ -19,108 +19,133 @@
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
dismissModalClass: 'close-reveal-modal', // the class of a button or element that will close an open modal
open: $.noop,
opened: $.noop,
close: $.noop,
closed: $.noop
};
var options = $.extend({}, defaults, options);
options = $.extend({}, defaults, options);

return this.each(function () {
var modal = $(this),
topMeasure = parseInt(modal.css('top')),
topMeasure = parseInt(modal.css('top'), 10),
topOffset = modal.height() + topMeasure,
locked = false,
modalBg = $('.reveal-modal-bg');
modalBg = $('.reveal-modal-bg'),
closeButton;

if (modalBg.length == 0) {
if (modalBg.length === 0) {
modalBg = $('<div class="reveal-modal-bg" />').insertAfter(modal);
modalBg.fadeTo('fast', 0.8);
}

function unlockModal() {
locked = false;
}

function lockModal() {
locked = true;
}

function openAnimation() {
modalBg.unbind('click.modalEvent');
$('.' + options.dismissModalClass).unbind('click.modalEvent');
if (!locked) {
lockModal();
if (options.animation == "fadeAndPop") {
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, function () {
modal.trigger('reveal:opened');
});
}
if (options.animation == "fade") {
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, function () {
modal.trigger('reveal:opened');
});
}
if (options.animation == "none") {
if (options.animation === "none") {
modal.css({'visibility': 'visible', 'top': $(document).scrollTop() + topMeasure});
modalBg.css({"display": "block"});
unlockModal();
modal.trigger('reveal:opened');
}
}
modal.unbind('reveal:open', openAnimation);
}
modal.bind('reveal:open', openAnimation);
modal.bind('reveal:open.reveal', openAnimation);

function closeAnimation() {
if (!locked) {
lockModal();
if (options.animation == "fadeAndPop") {
modalBg.delay(options.animationSpeed).fadeOut(options.animationSpeed);
if (options.animation === "fadeAndPop") {
modal.animate({
"top": $(document).scrollTop() - topOffset + 'px',
"opacity": 0
}, options.animationSpeed / 2, function () {
modal.css({'top': topMeasure, 'opacity': 1, 'visibility': 'hidden'});
unlockModal();
});
modalBg.delay(options.animationSpeed).fadeOut(options.animationSpeed, function () {
modal.trigger('reveal:closed');
});
}
if (options.animation == "fade") {
modalBg.delay(options.animationSpeed).fadeOut(options.animationSpeed);
if (options.animation === "fade") {
modal.animate({
"opacity" : 0
}, options.animationSpeed, function () {
modal.css({'opacity': 1, 'visibility': 'hidden', 'top': topMeasure});
unlockModal();
});
modalBg.delay(options.animationSpeed).fadeOut(options.animationSpeed, function () {
modal.trigger('reveal:closed');
});
}
if (options.animation == "none") {
if (options.animation === "none") {
modal.css({'visibility': 'hidden', 'top': topMeasure});
modalBg.css({'display': 'none'});
modal.trigger('reveal:closed');
}
}
modal.unbind('reveal:close', closeAnimation);
}
modal.bind('reveal:close', closeAnimation);

function destroy() {
modal.unbind('.reveal');
modalBg.unbind('.reveal');
$('.' + options.dismissModalClass).unbind('.reveal');
$('body').unbind('.reveal');
}

modal.bind('reveal:close.reveal', closeAnimation);
modal.bind('reveal:opened.reveal reveal:closed.reveal', unlockModal);
modal.bind('reveal:closed.reveal', destroy);

modal.bind('reveal:open.reveal', options.open);
modal.bind('reveal:opened.reveal', options.opened);
modal.bind('reveal:close.reveal', options.close);
modal.bind('reveal:closed.reveal', options.closed);

modal.trigger('reveal:open');

var closeButton = $('.' + options.dismissModalClass).bind('click.modalEvent', function () {
closeButton = $('.' + options.dismissModalClass).bind('click.reveal', function () {
modal.trigger('reveal:close');
});

if (options.closeOnBackgroundClick) {
modalBg.css({"cursor": "pointer"});
modalBg.bind('click.modalEvent', function () {
modalBg.bind('click.reveal', function () {
modal.trigger('reveal:close');
});
}

$('body').keyup(function (event) {
$('body').bind('keyup.reveal', function (event) {
if (event.which === 27) { // 27 is the keycode for the Escape key
modal.trigger('reveal:close');
}
});

function unlockModal() {
locked = false;
}

function lockModal() {
locked = true;
}
});
};
})(jQuery);
} (jQuery));
39 changes: 39 additions & 0 deletions test.html
Expand Up @@ -262,6 +262,24 @@ <h3>Buttons</h3>
<p><a href="#" class="nice radius large black button">Nice Black Button</a></p>
</div>
</div>

<h3>Reveal</h3>
<div class="row">
<div class="six columns">
<h6>Data Attributes</h6>
<p>
<a href="#" class="tiny blue button" data-reveal-id="testModal">Default</a>
<a href="#" class="tiny blue button" data-reveal-id="testModal" data-animation="fade">Fade</a>
<a href="#" class="tiny blue button" data-reveal-id="testModal" data-animation="none">None</a>
</p>
<h6>JavaScript</h6>
<p>
<a href="#" id="fireReveal" class="tiny blue button">Default</a>
<a href="#" id="fireRevealFade" class="tiny blue button">Fade</a>
<a href="#" id="fireRevealNone" class="tiny blue button">None</a>
</p>
</div>
</div>

</div>

Expand Down Expand Up @@ -324,6 +342,27 @@ <h2>Awesome. I have it.</h2>
<script src="javascripts/jquery.tooltips.js"></script>
<!-- End Combine and Compress These JS Files -->
<script src="javascripts/app.js"></script>

<script>
$('#testModal').bind('reveal:open reveal:opened reveal:close reveal:closed', function (event) {
console.log(event);
});

$('#fireReveal').click(function (event) {
event.preventDefault();
$('#testModal').reveal();
});

$('#fireRevealFade').click(function (event) {
event.preventDefault();
$('#testModal').reveal({animation: 'fade'});
});

$('#fireRevealNone').click(function (event) {
event.preventDefault();
$('#testModal').reveal({animation: 'none'});
});
</script>

</body>
</html>

0 comments on commit a78453c

Please sign in to comment.