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/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 * 33 * The above will open a facebox with "some html" as the box-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 or image: 43 * 44 * jQuery.facebox({ ajax: 'remote.html' }) 45 * jQuery.facebox({ image: 'dude.jpg' }) 46 * 47 * Want to close the facebox? Trigger the 'close.facebox' document event: 48 * 49 * jQuery(document).trigger('close.facebox') 50 * 51 * Facebox also has a bunch of other hooks: 52 * 53 * loading.facebox 54 * beforeReveal.facebox 55 * reveal.facebox (aliased as 'afterReveal.facebox') 56 * init.facebox 57 * 58 * Simply bind a function to any of these hooks: 59 * 60 * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and box-contents are revealed... }) 61 * 62 */ 63(function($) { 64 $.facebox = function(data, klass, id) { 65 if (id == undefined) { 66 ts = new Date() 67 ts = ts.getTime() 68 id = "facebox"+ts 69 } 70 $.facebox.settings.id = id 71 $.facebox.loading() 72 73 if (data.ajax) fillFaceboxFromAjax(data.ajax) 74 else if (data.image) fillFaceboxFromImage(data.image) 75 else if (data.div) fillFaceboxFromHref(data.div) 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.45, 87 overlay : true, 88 loadingImage : '/images/js/facebox/loading.gif', 89 closeImage : '/images/js/facebox/closelabel.gif', 90 imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ], 91 id : 'fcbox', 92 faceboxHtml : '\ 93 <div class="facebox" style="display:none;"> \ 94 <div class="popup"> \ 95 <table> \ 96 <tbody> \ 97 <tr> \ 98 <td class="tl"/><td class="b"/><td class="tr"/> \ 99 </tr> \ 100 <tr> \ 101 <td class="b"/> \ 102 <td class="body"> \ 103 <div class="box-content" style="padding: 20px;"> \ 104 </div> \ 105 <div class="box-footer"> \ 106 <a href="#" class="close" title="Close / Zamknij"> \ 107 <b>X</b> \ 108 </a> \ 109 </div> \ 110 </td> \ 111 <td class="b"/> \ 112 </tr> \ 113 <tr> \ 114 <td class="bl"/><td class="b"/><td class="br"/> \ 115 </tr> \ 116 </tbody> \ 117 </table> \ 118 </div> \ 119 </div>' 120 }, 121 122 loading: function() { 123 init() 124 if ($('#'+$.facebox.settings.id+' .loading').length == 1) return true 125 showOverlay() 126 127 $('#'+$.facebox.settings.id+' .box-content').empty() 128 $('#'+$.facebox.settings.id+' .body').children().hide().end(). 129 append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>') 130 131 $('#'+$.facebox.settings.id).css({ 132 top: getPageScroll()[1] + (getPageHeight() / 10), 133 left: 385.5 134 }).show() 135 136 $(document).bind('keydown.facebox', function(e) { 137 var id = $.facebox.settings.id 138 if (e.keyCode == 27) $.facebox.close(id) 139 return true 140 }) 141 $(document).trigger('loading.facebox') 142 }, 143 144 reveal: function(data, klass) { 145 $(document).trigger('beforeReveal.facebox') 146 if (klass) $('#'+$.facebox.settings.id+' .box-content').addClass(klass) 147 $('#'+$.facebox.settings.id+' .box-content').append(data) 148 $('#'+$.facebox.settings.id+' .loading').remove() 149 $('#'+$.facebox.settings.id+' .body').children().fadeIn('normal') 150 var zi = 100 + ($(".facebox").length * 2); 151 $('#'+$.facebox.settings.id).css('z-index', zi).css('left', $(window).width() / 2 - ($('#'+$.facebox.settings.id+' table').width() / 2)) 152 $(document).trigger('reveal.facebox').trigger('afterReveal.facebox') 153 }, 154 155 close: function(id) { 156 $(document).trigger('close.facebox', [id]) 157 return false 158 } 159 }) 160 161 /* 162 * Public, $.fn methods 163 */ 164 165 $.fn.facebox = function(settings) { 166 init(settings) 167 168 function clickHandler() { 169 $.facebox.loading(true) 170 171 // support for rel="facebox.inline_popup" syntax, to add a class 172 // also supports deprecated "facebox[.inline_popup]" syntax 173 var klass = this.rel.match(/facebox\[?\.(\w+)\]?/) 174 if (klass) klass = klass[1] 175 176 fillFaceboxFromHref(this.href, klass) 177 return false 178 } 179 180 return this.click(clickHandler) 181 } 182 183 /* 184 * Private methods 185 */ 186 187 // called one time to setup facebox on this page 188 function init(settings) { 189 190 if ($("#"+$.facebox.settings.id+".facebox").length > 0) return true 191 192 $(document).trigger('init.facebox') 193 makeCompatible() 194 195 var imageTypes = $.facebox.settings.imageTypes.join('|') 196 $.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i') 197 198 if (settings) $.extend($.facebox.settings, settings) 199 $('body').append($($.facebox.settings.faceboxHtml).attr("id", $.facebox.settings.id)) 200 201 var preload = [ new Image(), new Image() ] 202 preload[0].src = $.facebox.settings.closeImage 203 preload[1].src = $.facebox.settings.loadingImage 204 205 $('#'+$.facebox.settings.id).find('.b:first, .bl, .br, .tl, .tr').each(function() { 206 preload.push(new Image()) 207 preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1') 208 }) 209 210 $('#'+$.facebox.settings.id+' .close').click(function(e){ 211 e.preventDefault() 212 $.facebox.close($(this).parents(".facebox").attr("id")) 213 }) 214 $('#'+$.facebox.settings.id+' .close_image').attr('src', $.facebox.settings.closeImage) 215 } 216 217 // getPageScroll() by quirksmode.com 218 function getPageScroll() { 219 var xScroll, yScroll; 220 if (self.pageYOffset) { 221 yScroll = self.pageYOffset; 222 xScroll = self.pageXOffset; 223 } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict 224 yScroll = document.documentElement.scrollTop; 225 xScroll = document.documentElement.scrollLeft; 226 } else if (document.body) {// all other Explorers 227 yScroll = document.body.scrollTop; 228 xScroll = document.body.scrollLeft; 229 } 230 return new Array(xScroll,yScroll) 231 } 232 233 // Adapted from getPageSize() by quirksmode.com 234 function getPageHeight() { 235 var windowHeight
236 if (self.innerHeight) { // all except Explorer 237 windowHeight = self.innerHeight; 238 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 239 windowHeight = document.documentElement.clientHeight; 240 } else if (document.body) { // other Explorers 241 windowHeight = document.body.clientHeight; 242 } 243 return windowHeight 244 } 245 246 // Backwards compatibility 247 function makeCompatible() { 248 var $s = $.facebox.settings 249 250 $s.loadingImage = $s.loading_image || $s.loadingImage 251 $s.closeImage = $s.close_image || $s.closeImage 252 $s.imageTypes = $s.image_types || $s.imageTypes 253 $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml 254 } 255 256 // Figures out what you want to display and displays it 257 // formats are: 258 // div: #id 259 // image: blah.extension 260 // ajax: anything else 261 function fillFaceboxFromHref(href, klass) { 262 // div 263 if (href.match(/#/)) { 264 var url = window.location.href.split('#')[0] 265 var target = href.replace(url,'') 266 $.facebox.reveal($(target).clone().show(), klass) 267 268 // image 269 } else if (href.match($.facebox.settings.imageTypesRegexp)) { 270 fillFaceboxFromImage(href, klass) 271 // ajax 272 } else { 273 fillFaceboxFromAjax(href, klass) 274 } 275 } 276 277 function fillFaceboxFromImage(href, klass) { 278 var image = new Image() 279 image.onload = function() { 280 $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass) 281 } 282 image.src = href 283 } 284 285 function fillFaceboxFromAjax(href, klass) { 286 $.get(href, function(data) { $.facebox.reveal(data, klass) }) 287 } 288 289 function skipOverlay() { 290 return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 291 } 292 293 function showOverlay() { 294 if (skipOverlay()) return 295 296 if ($('#'+$.facebox.settings.id+'_overlay.facebox_overlay').length == 0) 297 $("body").append('<div id="'+$.facebox.settings.id+'_overlay" class="facebox_overlay facebox_hide"></div>') 298 299 var id = $.facebox.settings.id; 300 var zi = 99 + ($(".facebox").length * 2); 301 302 $('#'+id+'_overlay.facebox_overlay').attr("rel", id).hide().addClass("facebox_overlayBG") 303 .css('opacity', $.facebox.settings.opacity) 304 .css('z-index', zi) 305 .click(function() { 306 $(document).trigger('close.facebox', [$(this).attr("rel")]) 307 $(this).remove() 308 }) 309 .fadeIn(200) 310 return false 311 } 312 313 function hideOverlay(id) { 314 if (skipOverlay()) return 315 316 if(id != undefined) 317 { 318 $('#' + id + '_overlay.facebox_overlay').fadeOut(200, function(){ 319 $('#' + id + '_overlay.facebox_overlay').removeClass("facebox_overlayBG") 320 $('#' + id + '_overlay.facebox_overlay').addClass("facebox_hide") 321 $('#' + id + '_overlay.facebox_overlay').remove() 322 }) 323 } 324 else 325 { 326 $('.facebox_overlay').fadeOut(200, function(){ 327 $('.facebox_overlay').removeClass("facebox_overlayBG") 328 $('.facebox_overlay').addClass("facebox_hide") 329 $('.facebox_overlay').remove() 330 }) 331 } 332 333 return false 334 } 335 336 /* 337 * Bindings 338 */ 339 340 $(document).bind('close.facebox', function(e, id) { 341 $(document).unbind('keydown.facebox') 342 if(id != undefined) { 343 $('#'+id).fadeOut(function() { 344 $('#'+id+' .box-content').removeClass().addClass('box-content') 345 hideOverlay(id) 346 $('#'+id+' .loading').remove() 347 }) 348 } 349 else{ 350 $('.facebox').fadeOut(function() { 351 $('.facebox .box-content').removeClass().addClass('box-content') 352 hideOverlay() 353 $('.facebox .loading').remove() 354 }) 355 } 356 357 }) 358 359})(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.