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