PageSourceSearch

https://www.kiwiveterans.co.nz/themes/ngatoa_template/js/facebox/facebox.js

js kiwiveterans.co.nz collected 2026-09-25 11:48:27 UTC 9,485 bytes, 333 lines download raw bytes

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