1/* 2* $ lightbox_me 3* By: Buck Wilson 4* Version : 2.4 5* 6* Licensed under the Apache License, Version 2.0 (the "License"); 7* you may not use this file except in compliance with the License. 8* You may obtain a copy of the License at 9* 10* http://www.apache.org/licenses/LICENSE-2.0 11* 12* Unless required by applicable law or agreed to in writing, software 13* distributed under the License is distributed on an "AS IS" BASIS, 14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15* See the License for the specific language governing permissions and 16* limitations under the License. 17*/ 18 19 20(function($) { 21 22 $.fn.lightbox_me = function(options) { 23 24 return this.each(function() { 25 26 var 27 opts = $.extend({}, $.fn.lightbox_me.defaults, options), 28 $overlay = $(), 29 $self = $(this), 30 $iframe = $('<iframe id="foo" style="z-index: ' + (opts.zIndex + 1) + ';border: none; margin: 0; padding: 0; position: absolute; width: 100%; height: 100%; top: 0; left: 0; filter: mask();"/>'); 31 32 if (opts.showOverlay) { 33 //check if there's an existing overlay, if so, make subequent ones clear 34 var $currentOverlays = $(".js_lb_overlay:visible"); 35 if ($currentOverlays.length > 0){ 36 $overlay = $('<div class="lb_overlay_clear js_lb_overlay"/>'); 37 } else { 38 $overlay = $('<div class="' + opts.classPrefix + '_overlay js_lb_overlay"/>'); 39 } 40 } 41 42 /*---------------------------------------------------- 43 DOM Building 44 ---------------------------------------------------- */ 45 $('body').append($self.hide()).append($overlay); 46 47 48 /*---------------------------------------------------- 49 Overlay CSS stuffs 50 ---------------------------------------------------- */ 51 52 // set css of the overlay 53 if (opts.showOverlay) { 54 setOverlayHeight(); // pulled this into a function because it is called on window resize. 55 $overlay.css({ position: 'absolute', width: '100%', top: 0, left: 0, right: 0, bottom: 0, zIndex: (opts.zIndex + 2), display: 'none' }); 56 if (!$overlay.hasClass('lb_overlay_clear')){ 57 $overlay.css(opts.overlayCSS); 58 } 59 } 60 61 /*---------------------------------------------------- 62 Animate it in. 63 ---------------------------------------------------- */ 64 // 65 if (opts.showOverlay) { 66 $overlay.fadeIn(opts.overlaySpeed, function() { 67 setSelfPosition(); 68 $self[opts.appearEffect](opts.lightboxSpeed, function() { setOverlayHeight(); setSelfPosition(); opts.onLoad()}); 69 }); 70 } else { 71 setSelfPosition(); 72 $self[opts.appearEffect](opts.lightboxSpeed, function() { opts.onLoad()}); 73 } 74 75 /*---------------------------------------------------- 76 Hide parent if parent specified (parentLightbox should be jquery reference to any parent lightbox) 77 ---------------------------------------------------- */ 78 if (opts.parentLightbox) { 79 opts.parentLightbox.fadeOut(200); 80 } 81 82 83 /*---------------------------------------------------- 84 Bind Events 85 ---------------------------------------------------- */ 86 87 $(window).resize(setOverlayHeight) 88 .resize(setSelfPosition) 89 .scroll(setSelfPosition); 90 91 $(window).bind('keyup.lightbox_me', observeKeyPress); 92 93 if (opts.closeClick) { 94 $overlay.click(function(e) { closeLightbox(); e.preventDefault; }); 95 } 96 $self.delegate(opts.closeSelector, "click", function(e) { 97 closeLightbox(); e.preventDefault(); 98 }); 99 $self.bind('close', closeLightbox); 100 $self.bind('reposition', setSelfPosition); 101 102 103 104 /*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 105 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ 106 107 108 /*---------------------------------------------------- 109 Private Functions 110 ---------------------------------------------------- */ 111 112 /* Remove or hide all elements */ 113 function closeLightbox() { 114 var s = $self[0].style; 115 if (opts.destroyOnClose) { 116 $self.add($overlay).remove(); 117 } else { 118 $self.add($overlay).hide(); 119 } 120 121 //show the hidden parent lightbox 122 if (opts.parentLightbox) { 123 opts.parentLightbox.fadeIn(200); 124 } 125 if (opts.preventScroll) { 126 $('body').css('overflow', ''); 127 } 128 $iframe.remove(); 129 130 // clean up events. 131 $self.undelegate(opts.closeSelector, "click"); 132 $self.unbind('close', closeLightbox); 133 $self.unbind('repositon', setSelfPosition); 134 135 $(window).unbind('resize', setOverlayHeight); 136 $(window).unbind('resize', setSelfPosition); 137 $(window).unbind('scroll', setSelfPosition); 138 $(window).unbind('keyup.lightbox_me'); 139 opts.onClose(); 140 } 141 142 143 /* Function to bind to the window to observe the escape/enter key press */ 144 function observeKeyPress(e) {
145 if((e.keyCode == 27 || (e.DOM_VK_ESCAPE == 27 && e.which==0)) && opts.closeEsc) closeLightbox(); 146 } 147 148 149 /* Set the height of the overlay 150 : if the document height is taller than the window, then set the overlay height to the document height. 151 : otherwise, just set overlay height: 100% 152 */ 153 function setOverlayHeight() { 154 if ($(window).height() < $(document).height()) { 155 $overlay.css({height: $(document).height() + 'px'}); 156 $iframe.css({height: $(document).height() + 'px'}); 157 } else { 158 $overlay.css({height: '100%'}); 159 } 160 } 161 162 163 /* Set the position of the modal'd window ($self) 164 : if $self is taller than the window, then make it absolutely positioned 165 : otherwise fixed 166 */ 167 function setSelfPosition() { 168 var s = $self[0].style; 169 170 // reset CSS so width is re-calculated for margin-left CSS 171 $self.css({left: '50%', marginLeft: ($self.outerWidth() / 2) * -1, zIndex: (opts.zIndex + 3) }); 172 173 174 /* we have to get a little fancy when dealing with height, because lightbox_me 175 is just so fancy. 176 */ 177 178 // if the height of $self is bigger than the window and self isn't already position absolute 179 if (($self.height() + 80 >= $(window).height()) && ($self.css('position') != 'absolute')) { 180 181 // we are going to make it positioned where the user can see it, but they can still scroll 182 // so the top offset is based on the user's scroll position. 183 var topOffset = $(document).scrollTop() + 40; 184 $self.css({position: 'absolute', top: topOffset + 'px', marginTop: 0}) 185 } else if ($self.height()+ 80 < $(window).height()) { 186 //if the height is less than the window height, then we're gonna make this thing position: fixed. 187 if (opts.centered) { 188 $self.css({ position: 'fixed', top: '50%', marginTop: ($self.outerHeight() / 2) * -1}) 189 } else { 190 $self.css({ position: 'fixed'}).css(opts.modalCSS); 191 } 192 if (opts.preventScroll) { 193 $('body').css('overflow', 'hidden'); 194 } 195 } 196 } 197 198 }); 199 200 201 202 }; 203 204 $.fn.lightbox_me.defaults = { 205 206 // animation 207 appearEffect: "fadeIn", 208 appearEase: "", 209 overlaySpeed: 250, 210 lightboxSpeed: 300, 211 212 // close 213 closeSelector: ".close", 214 closeClick: true, 215 closeEsc: true, 216 217 // behavior 218 destroyOnClose: false, 219 showOverlay: true, 220 parentLightbox: false, 221 preventScroll: false, 222 223 // callbacks 224 onLoad: function() {}, 225 onClose: function() {}, 226 227 // style 228 classPrefix: 'lb', 229 zIndex: 999, 230 centered: false, 231 modalCSS: {top: '40px'}, 232 overlayCSS: {background: 'black', opacity: .3} 233 } 234})(jQuery);
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.