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