PageSourceSearch

https://democraticworld.in/components/com_virtuemart/assets/js/facebox.js

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

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.