1/* 2 * jQuery Reveal Plugin 1.0 3 * www.ZURB.com 4 * Copyright 2010, ZURB 5 * Free to use under the MIT license. 6 * http://www.opensource.org/licenses/mit-license.php 7*/ 8 9 10(function($) { 11 12/*--------------------------- 13 Defaults for Reveal 14----------------------------*/ 15 16/*--------------------------- 17 Listener for data-reveal-id attributes 18----------------------------*/ 19 20 $('a[data-reveal-id]').live('click', function(e) { 21 e.preventDefault(); 22 var modalLocation = $(this).attr('data-reveal-id'); 23 $('#'+modalLocation).reveal($(this).data()); 24 }); 25 26/*--------------------------- 27 Extend and Execute 28----------------------------*/ 29 30 $.fn.reveal = function(options) { 31 32 33 var defaults = { 34 middle: false, 35 animation: 'fadeAndPop', //fade, fadeAndPop, none 36 animationspeed: 300, //how fast animtions are 37 closeonbackgroundclick: true, //if you click background will modal close? 38 dismissmodalclass: 'close-reveal-modal' //the class of a button or element that will close an open modal 39 }; 40 41 //Extend dem' options 42 var options = $.extend({}, defaults, options); 43 44 return this.each(function() { 45 46/*--------------------------- 47 Global Variables 48----------------------------*/ 49 var modal = $(this), 50 $parent = modal.parent(), 51// middlePos = options.middle ? Math.round(($parent.height() - modal.outerHeight()) / 2) : 0, 52 topMeasure = parseInt(modal.css('top')), 53 topOffset = modal.height() + topMeasure, 54 locked = false, 55 modalBG = $('.reveal-modal-bg'); 56 57/*--------------------------- 58 Create Modal BG 59----------------------------*/ 60 if(modalBG.length == 0) { 61 modalBG = $('<div class="reveal-modal-bg" />').insertAfter(modal); 62 } 63 64/*--------------------------- 65 Open & Close Animations 66----------------------------*/ 67 //Entrance Animations 68 modal.bind('reveal:open', function () { 69 modalBG.unbind('click.modalEvent'); 70 $('.' + options.dismissmodalclass).unbind('click.modalEvent'); 71 if(!locked) { 72 lockModal(); 73 var middlePos = 0; 74 if (options.middle) { 75 middlePos = Math.round( ($(window).height() - modal.outerHeight()) / 2 ); 76 } 77 if(options.animation == "fadeAndPop") { 78 modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'}); 79 modalBG.fadeIn(options.animationspeed/2); 80 81 82 var topValue = $(document).scrollTop()+topMeasure+middlePos; 83 if (topValue<0) { 84 topValue = 0; 85 } 86 87 modal.delay(options.animationspeed/2).animate({ 88 "top": topValue + 'px', 89 "opacity" : 1 90 }, options.animationspeed,unlockModal()); 91 } 92 if(options.animation == "fade") { 93 modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+middlePos+topMeasure}); 94 modalBG.fadeIn(options.animationspeed/2); 95 modal.delay(options.animationspeed/2).animate({ 96 "opacity" : 1 97 }, options.animationspeed,unlockModal()); 98 } 99 if(options.animation == "none") { 100 modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+middlePos+topMeasure}); 101 modalBG.css({"display":"block"}); 102 unlockModal() 103 } 104 } 105 modal.unbind('reveal:open'); 106 }); 107 108 //Closing Animation 109 modal.bind('reveal:close', function () { 110 if(!locked) { 111 lockModal(); 112 if(options.animation == "fadeAndPop") { 113 modalBG.delay(options.animationspeed).fadeOut(options.animationspeed); 114 modal.animate({ 115 "top": $(document).scrollTop()-topOffset + 'px', 116 "opacity" : 0 117 }, options.animationspeed/2, function() { 118 modal.css({'top':topMeasure, 'opacity' : 1, 'visibility' : 'hidden'}); 119 unlockModal(); 120 }); 121 } 122 if(options.animation == "fade") { 123 modalBG.delay(options.animationspeed).fadeOut(options.animationspeed); 124 modal.animate({ 125 "opacity" : 0 126 }, options.animationspeed, function() { 127 modal.css({'opacity' : 1, 'visibility' : 'hidden', 'top' : topMeasure}); 128 unlockModal(); 129 }); 130 } 131 if(options.animation == "none") { 132 modal.css({'visibility' : 'hidden', 'top' : topMeasure}); 133 modalBG.css({'display' : 'none'}); 134 } 135 } 136 modal.unbind('reveal:close'); 137 }); 138 139/*--------------------------- 140 Open and add Closing Listeners 141----------------------------*/ 142 //Open Modal Immediately 143 modal.trigger('reveal:open') 144
145 //Close Modal Listeners 146 var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent', function () { 147 modal.trigger('reveal:close') 148 }); 149 150 if(options.closeonbackgroundclick) { 151 modalBG.css({"cursor":"pointer"}) 152 modalBG.bind('click.modalEvent', function () { 153 modal.trigger('reveal:close') 154 }); 155 } 156 $('body').keyup(function(e) { 157 if(e.which===27){ modal.trigger('reveal:close'); } // 27 is the keycode for the Escape key 158 }); 159 160 161/*--------------------------- 162 Animations Locks 163----------------------------*/ 164 function unlockModal() { 165 locked = false; 166 } 167 function lockModal() { 168 locked = true; 169 } 170 171 });//each call 172 }//orbit plugin call 173})(jQuery); 174
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.