1/* 2 * Facebox (for jQuery) 3 * version: 1.3 4 * @requires jQuery v1.2 or later 5 * @homepage https://github.com/defunkt/facebox 6 * 7 * Licensed under the MIT: 8 * http://www.opensource.org/licenses/mit-license.php 9 * 10 * Copyright Forever Chris Wanstrath, Kyle Neath 11 * 12 * Usage: 13 * 14 * jQuery(document).ready(function() { 15 * jQuery('a[rel*=facebox]').facebox() 16 * }) 17 * 18 * <a href="#terms" rel="facebox">Terms</a> 19 * Loads the #terms div in the box 20 * 21 * <a href="terms.html" rel="facebox">Terms</a> 22 * Loads the terms.html page in the box 23 * 24 * <a href="terms.png" rel="facebox">Terms</a> 25 * Loads the terms.png image in the box 26 * 27 * 28 * You can also use it programmatically: 29 * 30 * jQuery.facebox('some html') 31 * jQuery.facebox('some html', 'my-groovy-style') 32 * 33 * The above will open a facebox with "some html" as the content. 34 * 35 * jQuery.facebox(function($) { 36 * $.get('blah.html', function(data) { $.facebox(data) }) 37 * }) 38 * 39 * The above will show a loading screen before the passed function is called, 40 * allowing for a better ajaxy experience. 41 * 42 * The facebox function can also display an ajax page, an image, or the contents of a div: 43 * 44 * jQuery.facebox({ ajax: 'remote.html' }) 45 * jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style') 46 * jQuery.facebox({ image: 'stairs.jpg' }) 47 * jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style') 48 * jQuery.facebox({ div: '#box' }) 49 * jQuery.facebox({ div: '#box' }, 'my-groovy-style') 50 * 51 * Want to close the facebox? Trigger the 'close.facebox' document event: 52 * 53 * jQuery(document).trigger('close.facebox') 54 * 55 * Facebox also has a bunch of other hooks: 56 * 57 * loading.facebox 58 * beforeReveal.facebox 59 * reveal.facebox (aliased as 'afterReveal.facebox') 60 * init.facebox 61 * afterClose.facebox 62 * 63 * Simply bind a function to any of these hooks: 64 * 65 * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... }) 66 * 67 */ 68(function($) { 69 $.facebox = function(data, klass) { 70 $.facebox.loading(data.settings || []) 71 72 if (data.ajax) fillFaceboxFromAjax(data.ajax, klass) 73 else if (data.image) fillFaceboxFromImage(data.image, klass) 74 else if (data.div) fillFaceboxFromHref(data.div, klass) 75 else if ($.isFunction(data)) data.call($) 76 else $.facebox.reveal(data, klass) 77 } 78 79 /* 80 * Public, $.facebox methods 81 */ 82 83 $.extend($.facebox, { 84 settings: { 85 opacity : 0.2, 86 closebox : true, 87 closeclick : true, 88 closekey : true, 89 overlay : true, 90 loadingImage : '/app/js/homepage_overlay_ad/loading.gif', 91 closeImage : '/app/js/homepage_overlay_ad/closelabel.png', 92 imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ], 93 faceboxHtml : '\ 94 <div id="facebox" style="display:none;"> \ 95 <div class="popup"> \ 96 <div class="content"> \ 97 </div> \ 98 <a href="#" class="close"></a> \ 99 </div> \ 100 </div>' 101 }, 102 103 loading: function() { 104 init() 105 if ($('#facebox .loading').length == 1) return true 106 showOverlay() 107 108 $('#facebox .content').empty(). 109 append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>') 110 111 $('#facebox').show().css({ 112 top: getPageScroll()[1] + (getPageHeight() / 10), 113 left: $(window).width() / 2 - ($('#facebox .popup').width() / 2) 114 }) 115 116 if($.facebox.settings.closekey){ 117 $(document).bind('keydown.facebox', function(e) { 118 if (e.keyCode == 27) $.facebox.close() 119 return true 120 }) 121 } 122 123 $(document).trigger('loading.facebox') 124 }, 125 126 reveal: function(data, klass) { 127 $(document).trigger('beforeReveal.facebox') 128 if (klass) $('#facebox .content').addClass(klass) 129 $('#facebox .content').empty().append(data) 130 $('#facebox .popup').children().fadeIn('normal') 131 $('#facebox').css('left', $(window).width() / 2 - ($('#facebox .popup').width() / 2)) 132 $(document).trigger('reveal.facebox').trigger('afterReveal.facebox') 133 }, 134 135 close: function() { 136 $(document).trigger('close.facebox') 137 return false 138 } 139 }) 140 141 /* 142 * Public, $.fn methods 143 */ 144 145 $.fn.facebox = function(settings) { 146 if ($(this).length == 0) return 147 148 init(settings) 149 150 function clickHandler() { 151 $.facebox.loading(true) 152 153 // support for rel="facebox.inline_popup" syntax, to add a class 154 // also supports deprecated "facebox[.inline_popup]" syntax 155 var klass = this.rel.match(/facebox\[?\.(\w+)\]?/) 156 if (klass) klass = klass[1] 157 158 fillFaceboxFromHref(this.href, klass) 159 return false 160 } 161 162 return this.bind('click.facebox', clickHandler) 163 } 164 165 /* 166 * Private methods 167 */ 168 169 // called one time to setup facebox on this page 170 function init(settings) { 171 if ($.facebox.settings.inited) return true 172 else $.facebox.settings.inited = true 173 174 $(document).trigger('init.facebox') 175 makeCompatible() 176 177 var imageTypes = $.facebox.settings.imageTypes.join('|') 178 $.facebox.settings.imageTypesRegexp = new RegExp('\\.(' + imageTypes + ')(\\?.*)?$', 'i') 179 180 if (settings) $.extend($.facebox.settings, settings) 181 $('body').append($.facebox.settings.faceboxHtml) 182 183 var preload = [ new Image(), new Image() ] 184 preload[0].src = $.facebox.settings.closeImage 185 preload[1].src = $.facebox.settings.loadingImage 186 187 $('#facebox').find('.b:first, .bl').each(function() { 188 preload.push(new Image()) 189 preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1') 190 }) 191 192 193 if($.facebox.settings.closebox){ 194 $('#facebox .close') 195 .click($.facebox.close) 196 .append('<img src="' 197 + $.facebox.settings.closeImage 198 + '" class="close_image" title="close">') 199 } 200 201 202 203 } 204 205 // getPageScroll() by quirksmode.com 206 function getPageScroll() { 207 var xScroll, yScroll; 208 if (self.pageYOffset) { 209 yScroll = self.pageYOffset; 210 xScroll = self.pageXOffset; 211 } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict 212 yScroll = document.documentElement.scrollTop; 213 xScroll = document.documentElement.scrollLeft; 214 } else if (document.body) {// all other Explorers 215 yScroll = document.body.scrollTop; 216 xScroll = document.body.scrollLeft; 217 } 218 return new Array(xScroll,yScroll) 219 } 220 221 // Adapted from getPageSize() by quirksmode.com 222 function getPageHeight() { 223 var windowHeight
224 if (self.innerHeight) { // all except Explorer 225 windowHeight = self.innerHeight; 226 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 227 windowHeight = document.documentElement.clientHeight; 228 } else if (document.body) { // other Explorers 229 windowHeight = document.body.clientHeight; 230 } 231 return windowHeight 232 } 233 234 // Backwards compatibility 235 function makeCompatible() { 236 var $s = $.facebox.settings 237 238 $s.loadingImage = $s.loading_image || $s.loadingImage 239 $s.closeImage = $s.close_image || $s.closeImage 240 $s.imageTypes = $s.image_types || $s.imageTypes 241 $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml 242 } 243 244 // Figures out what you want to display and displays it 245 // formats are: 246 // div: #id 247 // image: blah.extension 248 // ajax: anything else 249 function fillFaceboxFromHref(href, klass) { 250 // div 251 if (href.match(/#/)) { 252 var url = window.location.href.split('#')[0] 253 var target = href.replace(url,'') 254 if (target == '#') return 255 $.facebox.reveal($(target).html(), klass) 256 257 // image 258 } else if (href.match($.facebox.settings.imageTypesRegexp)) { 259 fillFaceboxFromImage(href, klass) 260 // ajax 261 } else { 262 fillFaceboxFromAjax(href, klass) 263 } 264 } 265 266 function fillFaceboxFromImage(href, klass) { 267 var image = new Image() 268 image.onload = function() { 269 $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass) 270 } 271 image.src = href 272 } 273 274 function fillFaceboxFromAjax(href, klass) { 275 $.facebox.jqxhr = $.get(href, function(data) { $.facebox.reveal(data, klass) }) 276 } 277 278 function skipOverlay() { 279 return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 280 } 281 282 function showOverlay() { 283 if (skipOverlay()) return 284 285 if ($('#facebox_overlay').length == 0) 286 $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>') 287 288 $('#facebox_overlay').hide().addClass("facebox_overlayBG") 289 .css('opacity', $.facebox.settings.opacity) 290 .click(function() {if($.facebox.settings.closeclick){$(document).trigger('close.facebox')}}) 291 .fadeIn(200) 292 return false 293 } 294 295 function hideOverlay() { 296 if (skipOverlay()) return 297 298 $('#facebox_overlay').fadeOut(200, function(){ 299 $("#facebox_overlay").removeClass("facebox_overlayBG") 300 $("#facebox_overlay").addClass("facebox_hide") 301 $("#facebox_overlay").remove() 302 }) 303 304 return false 305 } 306 307 /* 308 * Bindings 309 */ 310 311 $(document).bind('close.facebox', function() { 312 if ($.facebox.jqxhr) { 313 $.facebox.jqxhr.abort() 314 $.facebox.jqxhr = null 315 } 316 $(document).unbind('keydown.facebox') 317 $('#facebox').fadeOut(function() { 318// $('#facebox .content').removeClass().addClass('content') 319 $('#facebox .content').remove() 320//Removed line added line below it. 321 $('#facebox .loading').remove() 322 $(document).trigger('afterClose.facebox') 323 }) 324 hideOverlay() 325 }) 326 327})(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.