PageSourceSearch

https://www.transportevents.com/wp-content/plugins/popup-press/js/libs/bpopup.js?ver=0.10

js transportevents.com collected 2026-10-02 05:59:52 UTC 14,790 bytes, 458 lines download raw bytes

1/*===================================================================================================================
2 * @name: bPopup
3 * @type: jQuery
4 * @author: (c) Bjoern Klinggaard - @bklinggaard
5 * @demo: http://dinbror.dk/bpopup
6 * @version: 0.11.0
7 * @requires jQuery 1.4.3
8 *==================================================================================================================*/
9
10; (function ($) {
11  'use strict';
12
13  $.fn.bPopup = function (options, callback) {
14
15    if ($.isFunction(options)) {
16      callback = options;
17      options = null;
18    }
19
20    // OPTIONS
21    var o = $.extend({}, $.fn.bPopup.defaults, options);
22
23    // HIDE SCROLLBAR?
24    if (!o.scrollBar)
25      $('html').css('overflow', 'hidden');
26
27    // VARIABLES
28    var $popup = this
29      , d = $(document)
30      , w = window
31      , $w = $(w)
32      , wH = windowHeight()
33      , wW = windowWidth()
34      , prefix = '__b-popup'
35      , isIOS6X = (/OS 6(_\d)+/i).test(navigator.userAgent) // Used for a temporary fix for ios6 timer bug when using zoom/scroll
36      , buffer = 200
37      , popups = 0
38      , id
39      , inside
40      , fixedVPos
41      , fixedHPos
42      , fixedPosStyle
43      , vPos
44      , hPos
45      , height
46      , width
47      , debounce
48      , autoCloseTO
49      , $header = $popup.find('.pps-header')
50      , $wrap = $popup.find('.pps-wrap')
51      , $content = $popup.find('.pps-content')
52    ;
53
54    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
55    // PUBLIC FUNCTION - call it: $(element).bPopup().close();
56    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
57    $popup.close = function () {
58      close();
59    };
60
61    $popup.reposition = function (animateSpeed) {
62      reposition(animateSpeed);
63    };
64
65    return $popup.each(function () {
66      if ($(this).data('bPopup')) return; //POPUP already exists?
67      init();
68    });
69
70    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
71    // HELPER FUNCTIONS - PRIVATE
72    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
73    function init() {
74      triggerCall(o.onOpen);
75      popups = ($w.data('bPopup') || 0) + 1, id = prefix + popups + '__', fixedVPos = o.position[1] !== 'auto', fixedHPos = o.position[0] !== 'auto', fixedPosStyle = o.positionStyle === 'fixed', height = $popup.outerHeight(true), width = $popup.outerWidth(true);
76      o.loadUrl ? createContent() : open();
77    };
78
79    function createContent() {
80      o.contentContainer = $(o.contentContainer || $popup);
81      switch (o.content) {
82        case ('iframe'):
83          var iframe = $('<iframe class="b-iframe" ' + o.iframeAttr + '></iframe>');
84          iframe.appendTo(o.contentContainer);
85          height = $popup.outerHeight(true);
86          width = $popup.outerWidth(true);
87          open();
88          iframe.attr('src', o.loadUrl); // setting iframe src after open due IE9 bug
89          triggerCall(o.loadCallback);
90          break;
91        case ('image'):
92          open();
93          $('<img />')
94            .load(function () {
95              triggerCall(o.loadCallback);
96              recenter($(this));
97            }).attr('src', o.loadUrl).hide().appendTo(o.contentContainer);
98          break;
99        default:
100          open();
101          $('<div class="b-ajax-wrapper"></div>')
102            .load(o.loadUrl, o.loadData, function (response, status, xhr) {
103              triggerCall(o.loadCallback, status);
104              recenter($(this));
105            }).hide().appendTo(o.contentContainer);
106          break;
107      }
108    };
109
110    function open() {
111      // MODAL OVERLAY
112      if (o.modal) {
113        $('<div class="b-modal ' + id + '"></div>')
114          .css({
115            backgroundColor: o.modalColor,
116            position: 'fixed',
117            top: 0,
118            right: 0,
119            bottom: 0,
120            left: 0,
121            opacity: 0,
122            zIndex: o.zIndex + popups
123          })
124          .appendTo(o.appendTo)
125          .fadeTo(o.speed, o.opacity);
126      }
127
128      // POPUP
129      resizePopup();
130
131      calcPosition();
132      $popup
133        .data('bPopup', o).data('id', id)
134        .css({
135          'left': o.transition == 'slideIn' || o.transition == 'slideBack' ? (o.transition == 'slideBack' ? d.scrollLeft() + wW : (hPos + width) * -1) : getLeftPos(!(!o.follow[0] && fixedHPos || fixedPosStyle))
136          ,
137          'position': o.positionStyle || 'absolute'
138          ,
139          'top': o.transition == 'slideDown' || o.transition == 'slideUp' ? (o.transition == 'slideUp' ? d.scrollTop() + wH : vPos + height * -1) : getTopPos(!(!o.follow[1] && fixedVPos || fixedPosStyle))
140          ,
141          'z-index': o.zIndex + popups + 1
142        }).each(function () {
143        if (o.appending) {
144          $(this).appendTo(o.appendTo);
145        }
146      });
147      doTransition(true);
148
149
150    };
151
152    function close() {
153      if (o.modal) {
154        $('.b-modal.' + $popup.data('id'))
155          .fadeTo(o.speed, 0, function () {
156            $(this).remove();
157          });
158      }
159      // Clean up
160      unbindEvents();
161      clearTimeout(autoCloseTO);
162      // Close trasition
163      doTransition();
164
165      return false; // Prevent default
166    };
167
168    function reposition(animateSpeed) {
169      wH = windowHeight();
170      wW = windowWidth();
171      inside = insideWindow();
172      if (inside.x || inside.y) {
173        clearTimeout(debounce);
174        debounce = setTimeout(function () {
175          calcPosition();
176          animateSpeed = animateSpeed || o.followSpeed;
177          var css = {};
178          if (inside.x)
179            css.left = o.follow[0] ? getLeftPos(true) : 'auto';
180          if (inside.y)
181            css.top = o.follow[1] ? getTopPos(true) : 'auto';
182          $popup
183            .dequeue()
184            .each(function () {
185              if (fixedPosStyle) {
186                $(this).css({ 'left': hPos, 'top': vPos });
187              }
188              else {
189                $(this).animate(css, animateSpeed, o.followEasing);
190              }
191            });
192        }, 50);
193      }
194    };
195
196    //Eksperimental
197    function recenter(content) {
198      var _width = content.width(), _height = content.height(), css = {};
199      o.contentContainer.css({ height: _height, width: _width });
200
201      if (_height >= $popup.height()) {
202        css.height = $popup.height();
203      }
204      if (_width >= $popup.width()) {
205        css.width = $popup.width();
206      }
207      height = $popup.outerHeight(true)
208        , width = $popup.outerWidth(true);
209
210      calcPosition();
211      o.contentContainer.css({ height: 'auto', width: 'auto' });
212
213      css.left = getLeftPos(!(!o.follow[0] && fixedHPos || fixedPosStyle)),
214        css.top = getTopPos(!(!o.follow[1] && fixedVPos || fixedPosStyle));
215
216      $popup
217        .animate(
218          css
219          , 250
220          , function () {
221            content.show();
222            inside = insideWindow();
223          }
224        );
225    };
226
227    function bindEvents() {
228      $w.data('bPopup', popups);
229      $popup.delegate('.bClose, .' + o.closeClass, 'click.' + id, close); // legacy, still supporting the close class bClose
230
231      if (o.modalClose) {
232        $('.b-modal.' + id).css('cursor', 'pointer').bind('click', close);
233      }
234
235      // Temporary disabling scroll/resize events on devices with IOS6+
236      // due to a bug where events are dropped after pinch to zoom
237      if (!isIOS6X && (o.follow[0] || o.follow[1])) {
238        $w.bind('scroll.' + id, function () {
239          if (inside.x || inside.y) {
240            var css = {};
241            if (inside.x)
242              css.left = o.follow[0] ? getLeftPos(!fixedPosStyle) : 'auto';
243            if (inside.y)
244              css.top = o.follow[1] ? getTopPos(!fixedPosStyle) : 'auto';
245            $popup
246              .dequeue()
247              .animate(css, o.followSpeed, o.followEasing);
248          }
249        }).bind('resize.' + id, function () {
250          resizePopup();
251          reposition();
252        });
253      }
254      if (o.escClose) {
255        d.bind('keydown.' + id, function (e) {
256          if (e.which == 27) {  //escape
257            close();
258          }
259        });
260      }
261    };
262
263    function unbindEvents() {
264      if (!o.scrollBar) {
265        $('html').css('overflow', 'auto');
266      }
267      $('.b-modal.' + id).unbind('click');
268      d.unbind('keydown.' + id);
269      $w.unbind('.' + id).data('bPopup', ($w.data('bPopup') - 1 > 0) ? $w.data('bPopup') - 1 : null);
270      $popup.undelegate('.bClose, .' + o.closeClass, 'click.' + id, close).data('bPopup', null);
271    };
272
273    function doTransition(open) {
274      switch (open ? o.transition : o.transitionClose || o.transition) {
275        case "slideIn":
276          animate({
277            left: open ? getLeftPos(!(!o.follow[0] && fixedHPos || fixedPosStyle)) : d.scrollLeft() - (width || $popup.outerWidth(true)) - buffer
278          });
279          break;
280        case "slideBack":
281          animate({
282            left: open ? getLeftPos(!(!o.follow[0] && fixedHPos || fixedPosStyle)) : d.scrollLeft() + wW + buffer
283          });
284          break;
285        case "slideDown":
286          animate({
287            top: open ? getTopPos(!(!o.follow[1] && fixedVPos || fixedPosStyle)) : d.scrollTop() - (height || $popup.outerHeight(true)) - buffer
288          });
289          break;
290        case "slideUp":
291          animate({
292            top: open ? getTopPos(!(!o.follow[1] && fixedVPos || fixedPosStyle)) : d.scrollTop() + wH + buffer
293          });
294          break;
295        default:
296          //Hardtyping 1 and 0 to ensure opacity 1 and not 0.9999998
297          $popup.stop().fadeTo(o.speed, open ? 1 : 0, function () {
298            onCompleteCallback(open);
299          });
300      }
301
302      function animate(css) {
303        $popup
304          .css({ display: 'block', opacity: 1 })
305          .animate(css, o.speed, o.easing, function () {
306            onCompleteCallback(open);
307          });
308      };
309    };
310
311
312    function onCompleteCallback(open) {
313      if (open) {
314        bindEvents();
315        triggerCall(callback);
316        if (o.autoClose) {
317          autoCloseTO = setTimeout(close, o.autoClose);
318        }
319      } else {
320        $popup.hide();
321        triggerCall(o.onClose);
322        if (o.loadUrl) {
323          o.contentContainer.empty();
324          $popup.css({ height: 'auto', width: 'auto' });
325        }
326      }
327    };
328
329    function getLeftPos(includeScroll) {
330      return includeScroll ? hPos + d.scrollLeft() : hPos;
331    };
332
333    function getTopPos(includeScroll) {
334      return includeScroll ? vPos + d.scrollTop() : vPos;
335    };
336
337    function triggerCall(func, arg) {
338      $.isFunction(func) && func.call($popup, arg);
339    };
340
341    function calcPosition() {
342      vPos = fixedVPos ? o.position[1] : Math.max(0, ((wH - $popup.outerHeight(true)) / 2) - o.amsl)
343        , hPos = fixedHPos ? o.position[0] : (wW - $popup.outerWidth(true)) / 2
344        , inside = insideWindow();
345    };
346
347    function resizePopup() {
348      var dataPopuppress = $popup.data('popuppress');
349      var newWidthpx;
350      if( dataPopuppress.width_units == '%' ){
351        //Convertimos % a px
352        newWidthpx = parseInt((wW * (Math.min(100, dataPopuppress.width)) / 100));
353        $popup.css('width', newWidthpx + 'px');
354      }
355
356      inside = insideWindow(dataPopuppress);
357      //Resize width
358      if (!inside.x) {
359        newWidthpx = parseInt((wW * 96 / 100));//96%
360        $popup.css('width', newWidthpx+ 'px');
361      }
362
363      //Resize height
364      if (!inside.y) {
365        if (dataPopuppress.height != 'auto') {
366          $popup.css('height', (windowHeight() - 30 - Math.abs(o.amsl) * 2) + 'px');
367        }
368      }
369
370      //Update height content
371      if ($popup.find('li.pps-active-slide img.pps-img-slider').length) {
372        return;
373      }
374      if ($popup.find('li.pps-active-slide .pps-embed iframe').length) {
375        return;
376      }
377
378      if( dataPopuppress.auto_height === 'true' ){
379        return;
380      }
381      setTimeout(function(){
382        $content.css({
383          'height': $header.length ? ($wrap.height() - $header.find('h3').outerHeight(true)) : '100%',
384        });
385      }, 50);
386
387    };
388
389    function insideWindow(dataPopuppress) {
390      if( dataPopuppress === undefined ){
391        return {
392          x: wW >= $popup.outerWidth(true),
393          y: wH >= $popup.outerHeight(true)
394        }
395      }
396      var popupWidth = parseInt(dataPopuppress.width);
397      var popupHeight;
398      if( dataPopuppress.width_units === '%' ){
399        popupWidth = parseInt((wW * (Math.min(100, popupWidth)) / 100));
400      }
401      if( dataPopuppress.height === 'auto' ){
402        popupHeight = $popup.outerHeight(true);
403      } else {
404        popupHeight = parseInt(dataPopuppress.height);
405        if( dataPopuppress.height_units === '%' ){
406          popupHeight = parseInt((wH * (Math.min(100, popupHeight)) / 100));
407        }
408      }
409      return {
410        x: wW >= popupWidth,
411        y: wH >= popupHeight
412      }
413    };
414
415    function windowHeight() {
416      return $w.height();
417    };
418
419    function windowWidth() {
420      return $w.width();
421    };
422  };
423
424  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
425  // DEFAULT VALUES
426  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
427  $.fn.bPopup.defaults = {
428    amsl: 50
429    , appending: true
430    , appendTo: 'body'
431    , autoClose: false
432    , closeClass: 'b-close'
433    , content: 'ajax' // ajax, iframe or image
434    , contentContainer: false
435    , easing: 'swing'
436    , escClose: true
437    , follow: [true, true] // x, y
438    , followEasing: 'swing'
439    , followSpeed: 500
440    , iframeAttr: 'scrolling="no" frameborder="0"'
441    , loadCallback: false
442    , loadData: false
443    , loadUrl: false
444    , modal: true
445    , modalClose: true
446    , modalColor: '#000'
447    , onClose: false
448    , onOpen: false
449    , opacity: 0.7
450    , position: ['auto', 'auto'] // x, y,
451    , positionStyle: 'absolute'// absolute or fixed
452    , scrollBar: true
453    , speed: 250 // open & close speed
454    , transition: 'fadeIn' //transitions: fadeIn, slideDown, slideIn, slideBack
455    , transitionClose: false
456    , zIndex: 9997 // popup gets z-index 9999, modal overlay 9998
457  };
458})(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.