4 /*---------------------------
\r
6 ----------------------------*/
\r
8 /*---------------------------
\r
9 Listener for data-reveal-id attributes
\r
10 ----------------------------*/
\r
12 $('a[data-reveal-id]').live('click', function(e) {
\r
14 var modalLocation = $(this).attr('data-reveal-id');
\r
15 $('#'+modalLocation).reveal($(this).data());
\r
18 /*---------------------------
\r
20 ----------------------------*/
\r
22 $.fn.reveal = function(options) {
\r
26 animation: 'fadeAndPop', //fade, fadeAndPop, none
\r
27 animationspeed: 300, //how fast animtions are
\r
28 closeonbackgroundclick: true, //if you click background will modal close?
\r
29 dismissmodalclass: 'close-reveal-modal' //the class of a button or element that will close an open modal
\r
32 //Extend dem' options
\r
33 var options = $.extend({}, defaults, options);
\r
35 return this.each(function() {
\r
37 /*---------------------------
\r
39 ----------------------------*/
\r
40 var modal = $(this),
\r
41 topMeasure = parseInt(modal.css('top')),
\r
42 topOffset = modal.height() + topMeasure,
\r
44 modalBG = $('.reveal-modal-bg');
\r
46 /*---------------------------
\r
48 ----------------------------*/
\r
49 if(modalBG.length == 0) {
\r
50 modalBG = $('<div class="reveal-modal-bg" />').insertAfter(modal);
\r
53 /*---------------------------
\r
54 Open & Close Animations
\r
55 ----------------------------*/
\r
56 //Entrance Animations
\r
57 modal.bind('reveal:open', function () {
\r
58 modalBG.unbind('click.modalEvent');
\r
59 $('.' + options.dismissmodalclass).unbind('click.modalEvent');
\r
62 if(options.animation == "fadeAndPop") {
\r
63 modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
\r
64 modalBG.fadeIn(options.animationspeed/2);
\r
65 modal.delay(options.animationspeed/2).animate({
\r
66 "top": $(document).scrollTop()+topMeasure + 'px',
\r
68 }, options.animationspeed,unlockModal());
\r
70 if(options.animation == "fade") {
\r
71 modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
\r
72 modalBG.fadeIn(options.animationspeed/2);
\r
73 modal.delay(options.animationspeed/2).animate({
\r
75 }, options.animationspeed,unlockModal());
\r
77 if(options.animation == "none") {
\r
78 modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
\r
79 modalBG.css({"display":"block"});
\r
83 modal.unbind('reveal:open');
\r
87 modal.bind('reveal:close', function () {
\r
90 if(options.animation == "fadeAndPop") {
\r
91 modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
\r
93 "top": $(document).scrollTop()-topOffset + 'px',
\r
95 }, options.animationspeed/2, function() {
\r
96 modal.css({'top':topMeasure, 'opacity' : 1, 'visibility' : 'hidden'});
\r
100 if(options.animation == "fade") {
\r
101 modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
\r
104 }, options.animationspeed, function() {
\r
105 modal.css({'opacity' : 1, 'visibility' : 'hidden', 'top' : topMeasure});
\r
109 if(options.animation == "none") {
\r
110 modal.css({'visibility' : 'hidden', 'top' : topMeasure});
\r
111 modalBG.css({'display' : 'none'});
\r
114 modal.unbind('reveal:close');
\r
117 /*---------------------------
\r
118 Open and add Closing Listeners
\r
119 ----------------------------*/
\r
120 //Open Modal Immediately
\r
121 modal.trigger('reveal:open')
\r
123 //Close Modal Listeners
\r
124 var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent', function () {
\r
125 modal.trigger('reveal:close')
\r
128 if(options.closeonbackgroundclick) {
\r
129 modalBG.css({"cursor":"pointer"})
\r
130 modalBG.bind('click.modalEvent', function () {
\r
131 modal.trigger('reveal:close')
\r
134 $('body').keyup(function(e) {
\r
135 if(e.which===27){ modal.trigger('reveal:close'); } // 27 is the keycode for the Escape key
\r
139 /*---------------------------
\r
141 ----------------------------*/
\r
142 function unlockModal() {
\r
145 function lockModal() {
\r
150 }//orbit plugin call
\r