PageSourceSearch

http://www.communi-trip.com/js/facebox.js

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