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 * 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.iframe) fillFaceboxFromHref(data.iframe,klass, data.rev) 75 else if (data.image) fillFaceboxFromImage(data.image, klass) 76 else if (data.div) fillFaceboxFromHref(data.div, klass, data.rev) 77 else if (data.text) fillFaceboxFromText(data.text, klass) 78 else if ($.isFunction(data)) data.call($) 79 else $.facebox.reveal(data, klass) 80 } 81 82 /* 83 * Public, $.facebox methods 84 */ 85 86 $.extend($.facebox, { 87 settings: { 88 opacity : 0.2, 89 overlay : true, 90 loadingImage : 'components/com_virtuemart/assets/images/facebox/loading.gif', 91 closeImage : 'components/com_virtuemart/assets/images/facebox/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 $('#facebox .body').children().hide().end(). 110 append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>') 111 112 // $('#facebox').css({ 113 // top: 100 , // getPageScroll()[1] + (getPageHeight() / 10), 114 // left: $(window).width() / 2 - 205 115 // }).show() 116 $('#facebox').css({ 117 top: getPageScroll()[1] + ($(window).height() / 10), 118 left: ($(window).width() - $('#facebox').width()) / 2 119 }).show() 120 $(document).bind('keydown.facebox', function(e) { 121 if (e.keyCode == 27) $.facebox.close() 122 return true 123 }) 124 $(document).trigger('loading.facebox') 125 }, 126 127 reveal: function(data, klass) { 128 $(document).trigger('beforeReveal.facebox') 129 if (klass) $('#facebox .content').addClass(klass) 130 $('#facebox .content').append(data) 131 $('#facebox .loading').remove() 132 $('#facebox .body').children().fadeIn('normal') 133 $('#facebox').css('left', $(window).width() / 2 - ($('#facebox .popup').width() / 2)) 134 $(document).trigger('reveal.facebox').trigger('afterReveal.facebox') 135 }, 136 137 close: function() { 138 $(document).trigger('close.facebox') 139 return false 140 } 141 }) 142 143 /* 144 * Public, $.fn methods 145 */ 146 147 $.fn.facebox = function(settings) { 148 if ($(this).length == 0) return 149 150 init(settings) 151 152 function clickHandler() { 153 $.facebox.loading(true) 154 155 // support for rel="facebox.inline_popup" syntax, to add a class 156 // also supports deprecated "facebox[.inline_popup]" syntax 157 var klass = this.rel.match(/facebox\[?\.(\w+)\]?/) 158 if (klass) klass = klass[1] 159 160 fillFaceboxFromHref(this.href, klass, this.rev) 161 return false 162 } 163 164 return this.bind('click.facebox', clickHandler) 165 } 166 167 /* 168 * Private methods 169 */ 170 171 // called one time to setup facebox on this page 172 function init(settings) { 173 if ($.facebox.settings.inited) return true 174 else $.facebox.settings.inited = true 175 176 $(document).trigger('init.facebox') 177 makeCompatible() 178 179 var imageTypes = $.facebox.settings.imageTypes.join('|') 180 $.facebox.settings.imageTypesRegexp = new RegExp('\.(' + imageTypes + ')$', 'i') 181 182 if (settings) $.extend($.facebox.settings, settings) 183 $('body').append($.facebox.settings.faceboxHtml) 184 185 var preload = [ new Image(), new Image() ] 186 preload[0].src = $.facebox.settings.closeImage 187 preload[1].src = $.facebox.settings.loadingImage 188 189 $('#facebox').find('.b:first, .bl').each(function() { 190 preload.push(new Image()) 191 preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1') 192 }) 193 194 $('#facebox .close').click($.facebox.close) 195 $('#facebox .close_image').attr('src', $.facebox.settings.closeImage) 196 } 197 198 // getPageScroll() by quirksmode.com 199 function getPageScroll() { 200 var xScroll, yScroll; 201 if (self.pageYOffset) { 202 yScroll = self.pageYOffset; 203 xScroll = self.pageXOffset; 204 } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict 205 yScroll = document.documentElement.scrollTop; 206 xScroll = document.documentElement.scrollLeft; 207 } else if (document.body) {// all other Explorers 208 yScroll = document.body.scrollTop; 209 xScroll = document.body.scrollLeft; 210 } 211 return new Array(xScroll,yScroll) 212 } 213 214 // Adapted from getPageSize() by quirksmode.com 215 function getPageHeight() { 216 var windowHeight
217 if (self.innerHeight) { // all except Explorer 218 windowHeight = self.innerHeight; 219 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 220 windowHeight = document.documentElement.clientHeight; 221 } else if (document.body) { // other Explorers 222 windowHeight = document.body.clientHeight; 223 } 224 return windowHeight 225 } 226 227 // Backwards compatibility 228 function makeCompatible() { 229 var $s = $.facebox.settings 230 231 $s.loadingImage = $s.loading_image || $s.loadingImage 232 $s.closeImage = $s.close_image || $s.closeImage 233 $s.imageTypes = $s.image_types || $s.imageTypes 234 $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml 235 } 236 237 // Figures out what you want to display and displays it 238 // formats are: 239 // div: #id 240 // image: blah.extension 241 // ajax: anything else 242 function fillFaceboxFromHref(href, klass, rev ) { 243 // div 244 if (href.match(/#/)) { 245 var url = window.location.href.split('#')[0] 246 var target = href.replace(url,'') 247 if (target == '#') return 248 $.facebox.reveal($(target).html(), klass) 249 // iframe 250 } else if (rev.split('|')[0] == 'iframe') { 251 fillFaceboxFromIframe(href, klass, rev.split('|')[1],rev.split('|')[2]) 252 // image 253 } else if (href.match($.facebox.settings.imageTypesRegexp)) { 254 fillFaceboxFromImage(href, klass) 255 // ajax 256 } else { 257 fillFaceboxFromAjax(href, klass) 258 } 259 } 260function fillFaceboxFromIframe(href, klass, height, width) { 261 $.facebox.reveal('<iframe scrolling="auto" marginwidth="0" width="'+width+'" height="' + height + '" frameborder="0" src="' + href + '" marginheight="0"></iframe>', klass) 262} 263 264 function fillFaceboxFromImage(href, klass) { 265 var image = new Image() 266 image.onload = function() { 267 $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass) 268 } 269 image.src = href 270 } 271 function fillFaceboxFromText(text, klass) { 272 $.facebox.reveal('<div>'+ text + '</div>', klass) 273 274 } 275 276 function fillFaceboxFromAjax(href, klass) { 277 $.get(href, function(data) { $.facebox.reveal(data, klass) }) 278 } 279 280 function skipOverlay() { 281 return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 282 } 283 284 function showOverlay() { 285 if (skipOverlay()) return 286 287 if ($('#facebox_overlay').length == 0) 288 $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>') 289 290 $('#facebox_overlay').hide().addClass("facebox_overlayBG") 291 .css('opacity', $.facebox.settings.opacity) 292 .click(function() { $(document).trigger('close.facebox') }) 293 .fadeIn(200) 294 return false 295 } 296 297 function hideOverlay() { 298 if (skipOverlay()) return 299 300 $('#facebox_overlay').fadeOut(200, function(){ 301 $("#facebox_overlay").removeClass("facebox_overlayBG") 302 $("#facebox_overlay").addClass("facebox_hide") 303 $("#facebox_overlay").remove() 304 }) 305 306 return false 307 } 308 309 /* 310 * Bindings 311 */ 312 313 $(document).bind('close.facebox', function() { 314 $(document).unbind('keydown.facebox') 315 $('#facebox').fadeOut(function() { 316 $('#facebox .content').removeClass().addClass('content') 317 $('#facebox .loading').remove() 318 $(document).trigger('afterClose.facebox') 319 }) 320 hideOverlay() 321 }) 322 323 $(document).bind('afterReveal.facebox', function() { 324 var windowHeight = $(window).height(); 325 var faceboxHeight = $('#facebox').height(); 326 if(faceboxHeight < windowHeight) { 327 var scrolltop = $(window).scrollTop(); 328 var top = Math.floor((windowHeight - faceboxHeight) / 2) + scrolltop; 329 $('#facebox').css('top', (top)); 330 } 331 else { 332 $('#facebox').css('top',$(window).scrollTop() ); 333 } 334 }); 335 336 337})(jQuery); 338
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.