PageSourceSearch

https://www.novanumismatics.com/wp-content/themes/magazine-news-byte-premium/js/jquery.parallax.js?ver=1.4.2

js novanumismatics.com collected 2026-10-02 11:49:21 UTC 12,828 bytes, 420 lines download raw bytes

vendor: 12,828 bytes, lines 1-420
1/*!
2 * parallax.js v1.4.2 (http://pixelcog.github.io/parallax.js/)
3 * {WPHOOT modified}
4 * @copyright 2016 PixelCog, Inc.
5 * @license MIT (https://github.com/pixelcog/parallax.js/blob/master/LICENSE)
6 */
7
8;(function ( $, window, document, undefined ) {
9
10  // Polyfill for requestAnimationFrame
11  // via: https://gist.github.com/paulirish/1579671
12
13  (function() {
14    var lastTime = 0;
15    var vendors = ['ms', 'moz', 'webkit', 'o'];
16    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
17      window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
18      window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
19        || window[vendors[x]+'CancelRequestAnimationFrame'];
20    }
21
22    if (!window.requestAnimationFrame)
23      window.requestAnimationFrame = function(callback) {
24        var currTime = new Date().getTime();
25        var timeToCall = Math.max(0, 16 - (currTime - lastTime));
26        var id = window.setTimeout(function() { callback(currTime + timeToCall); },
27          timeToCall);
28        lastTime = currTime + timeToCall;
29        return id;
30      };
31
32    if (!window.cancelAnimationFrame)
33      window.cancelAnimationFrame = function(id) {
34        clearTimeout(id);
35      };
36  }());
37
38
39  // Parallax Constructor
40
41  function Parallax(element, options) {
42    var self = this;
43
44    if (typeof options == 'object') {
45      delete options.refresh;
46      delete options.render;
47      $.extend(this, options);
48    }
49
50    this.$element = $(element);
51
52    if (!this.imageSrc && this.$element.is('img')) {
53      this.imageSrc = this.$element.attr('src');
54    }
55
56    var positions = (this.position + '').toLowerCase().match(/\S+/g) || [];
57
58    if (positions.length < 1) {
59      positions.push('center');
60    }
61    if (positions.length == 1) {
62      positions.push(positions[0]);
63    }
64
65    if (positions[0] == 'top' || positions[0] == 'bottom' || positions[1] == 'left' || positions[1] == 'right') {
66      positions = [positions[1], positions[0]];
67    }
68
69    if (this.positionX != undefined) positions[0] = this.positionX.toLowerCase();
70    if (this.positionY != undefined) positions[1] = this.positionY.toLowerCase();
71
72    self.positionX = positions[0];
73    self.positionY = positions[1];
74
75    if (this.positionX != 'left' && this.positionX != 'right') {
76      if (isNaN(parseInt(this.positionX))) {
77        this.positionX = 'center';
78      } else {
79        this.positionX = parseInt(this.positionX);
80      }
81    }
82
83    if (this.positionY != 'top' && this.positionY != 'bottom') {
84      if (isNaN(parseInt(this.positionY))) {
85        this.positionY = 'center';
86      } else {
87        this.positionY = parseInt(this.positionY);
88      }
89    }
90
91    this.position =
92      this.positionX + (isNaN(this.positionX)? '' : 'px') + ' ' +
93      this.positionY + (isNaN(this.positionY)? '' : 'px');
94
95    if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
96      if (this.imageSrc && this.iosFix && !this.$element.is('img')) {
97        this.$element.css({
98          backgroundImage: 'url(' + this.imageSrc + ')',
99          backgroundSize: 'cover',
100          backgroundPosition: this.position
101        });
102      }
103      return this;
104    }
105
106    if (navigator.userAgent.match(/(Android)/)) {
107      if (this.imageSrc && this.androidFix && !this.$element.is('img')) {
108        this.$element.css({
109          backgroundImage: 'url(' + this.imageSrc + ')',
110          backgroundSize: 'cover',
111          backgroundPosition: this.position
112        });
113      }
114      return this;
115    }
116
117    /* WPHOOT MOD */
118    // this.$mirror = $('<div />').prependTo('body');
119    this.$mirror = $('<div />').prependTo('#main');
120    // if ( $('#page-wrapper').is('.site-boxed') )
121    //   this.$mirror = $('<div />').prependTo('#page-wrapper');
122    // else
123    //   this.$mirror = $('<div />').prependTo('body');
124    $(window).on('hootSliderAnimated',function(){ 
125      // self.refresh(); // seems redundant. uncomment if a bug is spotted
126      $(this).trigger('resize.px.parallax'); // use resize instead of load.px.parallax (conflicts with waypoint's 'bottom-in-view' offset)
127    });
128    /* WPHOOT MOD END */
129
130    var slider = this.$element.find('>.parallax-slider');
131    var sliderExisted = false;
132
133    if (slider.length == 0)
134      this.$slider = $('<img />').prependTo(this.$mirror);
135    else {
136      this.$slider = slider.prependTo(this.$mirror)
137      sliderExisted = true;
138    }
139
140    this.$mirror.addClass('parallax-mirror').css({
141      visibility: 'hidden',
142      zIndex: this.zIndex,
143      position: 'fixed',
144      top: 0,
145      left: 0,
146      overflow: 'hidden'
147    });
148
149    this.$slider.addClass('parallax-slider').one('load', function() {
150      if (!self.naturalHeight || !self.naturalWidth) {
151        self.naturalHeight = this.naturalHeight || this.height || 1;
152        self.naturalWidth  = this.naturalWidth  || this.width  || 1;
153      }
154      self.aspectRatio = self.naturalWidth / self.naturalHeight;
155
156      Parallax.isSetup || Parallax.setup();
157      Parallax.sliders.push(self);
158      Parallax.isFresh = false;
159      Parallax.requestRender();
160    });
161
162    if (!sliderExisted)
163      this.$slider[0].src = this.imageSrc;
164
165    if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete || slider.length > 0) {
166      this.$slider.trigger('load');
167    }
168
169  };
170
171
172  // Parallax Instance Methods
173
174  $.extend(Parallax.prototype, {
175    speed:    0.2,
176    bleed:    0,
177    zIndex:   -100,
178    iosFix:   true,
179    androidFix: true,
180    position: 'center',
181    overScrollFix: false,
182
183    refresh: function() {
184      this.boxWidth        = this.$element.outerWidth();
185      this.boxHeight       = this.$element.outerHeight() + this.bleed * 2;
186      this.boxOffsetTop    = this.$element.offset().top - this.bleed;
187      this.boxOffsetLeft   = this.$element.offset().left;
188      this.boxOffsetBottom = this.boxOffsetTop + this.boxHeight;
189
190      var winHeight = Parallax.winHeight;
191      var docHeight = Parallax.docHeight;
192      var maxOffset = Math.min(this.boxOffsetTop, docHeight - winHeight);
193      var minOffset = Math.max(this.boxOffsetTop + this.boxHeight - winHeight, 0);
194      var imageHeightMin = this.boxHeight + (maxOffset - minOffset) * (1 - this.speed) | 0;
195      var imageOffsetMin = (this.boxOffsetTop - maxOffset) * (1 - this.speed) | 0;
196
197      if (imageHeightMin * this.aspectRatio >= this.boxWidth) {
198        this.imageWidth    = imageHeightMin * this.aspectRatio | 0;
199        this.imageHeight   = imageHeightMin;
200        this.offsetBaseTop = imageOffsetMin;
201
202        var margin = this.imageWidth - this.boxWidth;
203
204        if (this.positionX == 'left') {
205          this.offsetLeft = 0;
206        } else if (this.positionX == 'right') {
207          this.offsetLeft = - margin;
208        } else if (!isNaN(this.positionX)) {
209          this.offsetLeft = Math.max(this.positionX, - margin);
210        } else {
211          this.offsetLeft = - margin / 2 | 0;
212        }
213      } else {
214        this.imageWidth    = this.boxWidth;
215        this.imageHeight   = this.boxWidth / this.aspectRatio | 0;
216        this.offsetLeft    = 0;
217
218        var margin = this.imageHeight - imageHeightMin;
219
220        if (this.positionY == 'top') {
221          this.offsetBaseTop = imageOffsetMin;
222        } else if (this.positionY == 'bottom') {
223          this.offsetBaseTop = imageOffsetMin - margin;
224        } else if (!isNaN(this.positionY)) {
225          this.offsetBaseTop = imageOffsetMin + Math.max(this.positionY, - margin);
226        } else {
227          this.offsetBaseTop = imageOffsetMin - margin / 2 | 0;
228        }
229      }
230    },
231
232    render: function() {
233      var scrollTop    = Parallax.scrollTop;
234      var scrollLeft   = Parallax.scrollLeft;
235      var overScroll   = this.overScrollFix ? Parallax.overScroll : 0;
236      var scrollBottom = scrollTop + Parallax.winHeight;
237
238      if (this.boxOffsetBottom > scrollTop && this.boxOffsetTop <= scrollBottom) {
239        this.visibility = 'visible';
240        this.mirrorTop = this.boxOffsetTop  - scrollTop;
241        this.mirrorLeft = this.boxOffsetLeft - scrollLeft;
242        this.offsetTop = this.offsetBaseTop - this.mirrorTop * (1 - this.speed);
243      } else {
244        this.visibility = 'hidden';
245      }
246
247      this.$mirror.css({
248        transform: 'translate3d(0px, 0px, 0px)',
249        visibility: this.visibility,
250        top: this.mirrorTop - overScroll,
251        left: this.mirrorLeft,
252        height: this.boxHeight,
253        width: this.boxWidth
254      });
255
256      this.$slider.css({
257        transform: 'translate3d(0px, 0px, 0px)',
258        position: 'absolute',
259        top: this.offsetTop,
260        left: this.offsetLeft,
261        height: this.imageHeight,
262        width: this.imageWidth,
263        maxWidth: 'none'
264      });
265    }
266  });
267
268
269  // Parallax Static Methods
270
271  $.extend(Parallax, {
272    scrollTop:    0,
273    scrollLeft:   0,
274    winHeight:    0,
275    winWidth:     0,
276    docHeight:    1 << 30,
277    docWidth:     1 << 30,
278    sliders:      [],
279    isReady:      false,
280    isFresh:      false,
281    isBusy:       false,
282
283    setup: function() {
284      if (this.isReady) return;
285
286      var $doc = $(document), $win = $(window);
287
288      var loadDimensions = function() {
289        Parallax.winHeight = $win.height();
290        Parallax.winWidth  = $win.width();
291        Parallax.docHeight = $doc.height();
292        Parallax.docWidth  = $doc.width();
293      };
294
295      var loadScrollPosition = function() {
296        var winScrollTop  = $win.scrollTop();
297        var scrollTopMax  = Parallax.docHeight - Parallax.winHeight;
298        var scrollLeftMax = Parallax.docWidth  - Parallax.winWidth;
299        Parallax.scrollTop  = Math.max(0, Math.min(scrollTopMax,  winScrollTop));
300        Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft()));
301        Parallax.overScroll = Math.max(winScrollTop - scrollTopMax, Math.min(winScrollTop, 0));
302      };
303
304      $win.on('resize.px.parallax load.px.parallax', function() {
305          loadDimensions();
306          Parallax.isFresh = false;
307          Parallax.requestRender();
308        })
309        .on('scroll.px.parallax load.px.parallax', function() {
310          loadScrollPosition();
311          Parallax.requestRender();
312        });
313
314      loadDimensions();
315      loadScrollPosition();
316
317      this.isReady = true;
318    },
319
320    configure: function(options) {
321      if (typeof options == 'object') {
322        delete options.refresh;
323        delete options.render;
324        $.extend(this.prototype, options);
325      }
326    },
327
328    refresh: function() {
329      $.each(this.sliders, function(){ this.refresh() });
330      this.isFresh = true;
331    },
332
333    render: function() {
334      this.isFresh || this.refresh();
335      $.each(this.sliders, function(){ this.render() });
336    },
337
338    requestRender: function() {
339      var self = this;
340
341      if (!this.isBusy) {
342        this.isBusy = true;
343        window.requestAnimationFrame(function() {
344          self.render();
345          self.isBusy = false;
346        });
347      }
348    },
349    destroy: function(el){
350      var i,
351          parallaxElement = $(el).data('px.parallax');
352      parallaxElement.$mirror.remove();
353      for(i=0; i < this.sliders.length; i+=1){
354        if(this.sliders[i] == parallaxElement){
355          this.sliders.splice(i, 1);
356        }
357      }
358      $(el).data('px.parallax', false);
359      if(this.sliders.length === 0){
360        $(window).off('scroll.px.parallax resize.px.parallax load.px.parallax');
361        this.isReady = false;
362        Parallax.isSetup = false;
363      }
364    }
365  });
366
367
368  // Parallax Plugin Definition
369
370  function Plugin(option) {
371    return this.each(function () {
372      var $this = $(this);
373      var options = typeof option == 'object' && option;
374
375      if (this == window || this == document || $this.is('body')) {
376        Parallax.configure(options);
377      }
378      else if (!$this.data('px.parallax')) {
379        options = $.extend({}, $this.data(), options);
380        $this.data('px.parallax', new Parallax(this, options));
381      }
382      else if (typeof option == 'object')
383      {
384        $.extend($this.data('px.parallax'), options);
385      }
386      if (typeof option == 'string') {
387        if(option == 'destroy'){
388            Parallax['destroy'](this);
389        }else{
390          Parallax[option]();
391        }
392      }
393    })
394  };
395
396  var old = $.fn.parallax;
397
398  $.fn.parallax             = Plugin;
399  $.fn.parallax.Constructor = Parallax;
400
401
402  // Parallax No Conflict
403
404  $.fn.parallax.noConflict = function () {
405    $.fn.parallax = old;
406    return this;
407  };
408
409
410  // Parallax Data-API
411
412$(document).on('ready.px.parallax.data-api', function () {
413    /* WPHOOT MOD */
414    // $('[data-parallax="scroll"]').parallax();
415    if( $('.lightSlider').length > 0 ) setTimeout(function(){ $('[data-parallax="scroll"]').parallax(); }, 3000);
416    else $('[data-parallax="scroll"]').parallax();
417    /* WPHOOT MOD END */
418  });
419
420}(jQuery, window, document));

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.