PageSourceSearch

https://motelplus-berlin.de/js/superslides/jquery.superslides.js

js motelplus-berlin.de collected 2026-10-07 15:34:45 UTC 14,827 bytes, 666 lines download raw bytes

1/*! Superslides - v0.6.3-wip - 2013-12-17
2* https://github.com/nicinabox/superslides
3* Copyright (c) 2013 Nic Aitch; Licensed MIT */
4(function(window, $) {
5
6var Superslides, plugin = 'superslides';
7
8Superslides = function(el, options) {
9  this.options = $.extend({
10    play: false,
11    animation_speed: 600,
12    animation_easing: 'swing',
13    animation: 'slide',
14    inherit_width_from: window,
15    inherit_height_from: window,
16    pagination: true,
17    hashchange: false,
18    scrollable: true,
19    elements: {
20      preserve: '.preserve',
21      nav: '.slides-navigation',
22      container: '.slides-container',
23      pagination: '.slides-pagination'
24    }
25  }, options);
26
27  var that       = this,
28      $control   = $('<div>', { "class": 'slides-control' }),
29      multiplier = 1;
30
31  this.$el        = $(el);
32  this.$container = this.$el.find(this.options.elements.container);
33
34  // Private Methods
35  var initialize = function() {
36    multiplier = that._findMultiplier();
37
38    that.$el.on('click', that.options.elements.nav + " a", function(e) {
39      e.preventDefault();
40
41      that.stop();
42      if ($(this).hasClass('next')) {
43        that.animate('next', function() {
44          that.start();
45        });
46      } else {
47        that.animate('prev', function() {
48          that.start();
49        });
50      }
51    });
52
53    $(document).on('keyup', function(e) {
54      if (e.keyCode === 37) {
55        that.animate('prev');
56      }
57      if (e.keyCode === 39) {
58        that.animate('next');
59      }
60    });
61
62    $(window).on('resize', function() {
63      setTimeout(function() {
64        var $children = that.$container.children();
65
66        that.width  = that._findWidth();
67        that.height = that._findHeight();
68
69        $children.css({
70          width: that.width,
71          left: that.width
72        });
73
74        that.css.containers();
75        that.css.images();
76      }, 10);
77    });
78
79    if (that.options.hashchange) {
80      $(window).on('hashchange', function() {
81        var hash = that._parseHash(), index;
82
83        index = that._upcomingSlide(hash);
84
85        if (index >= 0 && index !== that.current) {
86          that.animate(index);
87        }
88      });
89    }
90
91    that.pagination._events();
92
93    that.start();
94    return that;
95  };
96
97var css = {
98  containers: function() {
99    if (that.init) {
100      that.$el.css({
101        height: that.height
102      });
103
104      that.$control.css({
105        width: that.width * multiplier,
106        left: -that.width
107      });
108
109      that.$container.css({
110
111      });
112    } else {
113      $('body').css({
114        margin: 0
115      });
116
117      that.$el.css({
118        position: 'relative',
119        overflow: 'hidden',
120        width: '100%',
121        height: that.height
122      });
123
124      that.$control.css({
125        position: 'relative',
126        transform: 'translate3d(0)',
127        height: '100%',
128        width: that.width * multiplier,
129        left: -that.width
130      });
131
132      that.$container.css({
133        display: 'none',
134        margin: '0',
135        padding: '0',
136        listStyle: 'none',
137        position: 'relative',
138        height: '100%'
139      });
140    }
141
142    if (that.size() === 1) {
143      that.$el.find(that.options.elements.nav).hide();
144    }
145  },
146  images: function() {
147    var $images = that.$container.find('img')
148                                 .not(that.options.elements.preserve)
149
150    $images.removeAttr('width').removeAttr('height')
151      .css({
152        "-webkit-backface-visibility": 'hidden',
153        "-ms-interpolation-mode": 'bicubic',
154        "position": 'absolute',
155        "left": '0',
156        "top": '0',
157        "z-index": '-1',
158        "max-width": 'none'
159      });
160
161    $images.each(function() {
162      var image_aspect_ratio = that.image._aspectRatio(this),
163          image = this;
164
165      if (!$.data(this, 'processed')) {
166        var img = new Image();
167        img.onload = function() {
168          that.image._scale(image, image_aspect_ratio);
169          that.image._center(image, image_aspect_ratio);
170          $.data(image, 'processed', true);
171        };
172        img.src = this.src;
173
174      } else {
175        that.image._scale(image, image_aspect_ratio);
176        that.image._center(image, image_aspect_ratio);
177      }
178    });
179  },
180  children: function() {
181    var $children = that.$container.children();
182
183    if ($children.is('img')) {
184      $children.each(function() {
185        if ($(this).is('img')) {
186          $(this).wrap('<div>');
187
188          // move id attribute
189          var id = $(this).attr('id');
190          $(this).removeAttr('id');
191          $(this).parent().attr('id', id);
192        }
193      });
194
195      $children = that.$container.children();
196    }
197
198    if (!that.init) {
199      $children.css({
200        display: 'none',
201        left: that.width * 2
202      });
203    }
204
205    $children.css({
206      position: 'absolute',
207      overflow: 'hidden',
208      height: '100%',
209      width: that.width,
210      top: 0,
211      zIndex: 0
212    });
213
214  }
215}
216
217var fx = {
218  slide: function(orientation, complete) {
219    var $children = that.$container.children(),
220        $target   = $children.eq(orientation.upcoming_slide);
221
222    $target.css({
223      left: orientation.upcoming_position,
224      display: 'block'
225    });
226
227    that.$control.animate({
228      left: orientation.offset
229    },
230    that.options.animation_speed,
231    that.options.animation_easing,
232    function() {
233      if (that.size() > 1) {
234        that.$control.css({
235          left: -that.width
236        });
237
238        $children.eq(orientation.upcoming_slide).css({
239          left: that.width,
240          zIndex: 2
241        });
242
243        if (orientation.outgoing_slide >= 0) {
244          $children.eq(orientation.outgoing_slide).css({
245            left: that.width,
246            display: 'none',
247            zIndex: 0
248          });
249        }
250      }
251
252      complete();
253    });
254  },
255  fade: function(orientation, complete) {
256    var that = this,
257        $children = that.$container.children(),
258        $outgoing = $children.eq(orientation.outgoing_slide),
259        $target = $children.eq(orientation.upcoming_slide);
260
261    $target.css({
262      left: this.width,
263      opacity: 0,
264      display: 'block'
265    }).animate({
266          opacity: 1
267        },
268        that.options.animation_speed,
269        that.options.animation_easing
270    );
271
272    if (orientation.outgoing_slide >= 0) {
273      $outgoing.animate({
274        opacity: 0
275      },
276      that.options.animation_speed,
277      that.options.animation_easing,
278      function() {
279        if (that.size() > 1) {
280          $children.eq(orientation.upcoming_slide).css({
281            zIndex: 2
282          });
283
284          if (orientation.outgoing_slide >= 0) {
285            $children.eq(orientation.outgoing_slide).css({
286              opacity: 1,
287              display: 'none',
288              zIndex: 0
289            });
290          }
291        }
292
293        complete();
294      });
295    } else {
296      $target.css({
297        zIndex: 2
298      });
299      complete();
300    }
301  }
302};
303
304fx = $.extend(fx, $.fn.superslides.fx);
305
306var image = {
307  _centerY: function(image) {
308    var $img = $(image);
309
310    $img.css({
311      top: (that.height - $img.height()) / 2
312    });
313  },
314  _centerX: function(image) {
315    var $img = $(image);
316
317    $img.css({
318      left: (that.width - $img.width()) / 2
319    });
320  },
321  _center: function(image) {
322    that.image._centerX(image);
323    that.image._centerY(image);
324  },
325  _aspectRatio: function(image) {
326    if (!image.naturalHeight && !image.naturalWidth) {
327      var img = new Image();
328      img.src = image.src;
329      image.naturalHeight = img.height;
330      image.naturalWidth = img.width;
331    }
332
333    return image.naturalHeight / image.naturalWidth;
334  },
335  _scale: function(image, image_aspect_ratio) {
336    image_aspect_ratio = image_aspect_ratio || that.image._aspectRatio(image);
337
338    var container_aspect_ratio = that.height / that.width,
339        $img = $(image);
340
341    if (container_aspect_ratio > image_aspect_ratio) {
342      $img.css({
343        height: that.height,
344        width: that.height / image_aspect_ratio
345      });
346
347    } else {
348      $img.css({
349        height: that.width * image_aspect_ratio,
350        width: that.width
351      });
352    }
353  }
354};
355
356var pagination = {
357  _setCurrent: function(i) {
358    if (!that.$pagination) { return; }
359
360    var $pagination_children = that.$pagination.children();
361
362    $pagination_children.removeClass('current');
363    $pagination_children.eq(i)
364      .addClass('current');
365  },
366  _addItem: function(i) {
367    var slide_number = i + 1,
368        href = slide_number,
369        $slide = that.$container.children().eq(i),
370        slide_id = $slide.attr('id');
371
372    if (slide_id) {
373      href = slide_id;
374    }
375
376    var $item = $("<a>", {
377      'href': "#" + href,
378      'text': href
379    });
380
381    $item.appendTo(that.$pagination);
382  },
383  _setup: function() {
384    if (!that.options.pagination || that.size() === 1) { return; }
385
386    var $pagination = $("<nav>", {
387      'class': that.options.elements.pagination.replace(/^\./, '')
388    });
389
390    that.$pagination = $pagination.appendTo(that.$el);
391
392    for (var i = 0; i < that.size(); i++) {
393      that.pagination._addItem(i);
394    }
395  },
396  _events: function() {
397    that.$el.on('click', that.options.elements.pagination + ' a', function(e) {
398      e.preventDefault();
399
400      var hash  = that._parseHash(this.hash), index;
401      index = that._upcomingSlide(hash, true);
402
403      if (index !== that.current) {
404        that.animate(index, function() {
405          that.start();
406        });
407      }
408    });
409  }
410};
411
412  this.css = css;
413  this.image = image;
414  this.pagination = pagination;
415  this.fx = fx;
416  this.animation = this.fx[this.options.animation];
417
418  this.$control = this.$container.wrap($control).parent('.slides-control');
419
420  that._findPositions();
421  that.width  = that._findWidth();
422  that.height = that._findHeight();
423
424  this.css.children();
425  this.css.containers();
426  this.css.images();
427  this.pagination._setup();
428
429  return initialize();
430};
431
432Superslides.prototype = {
433  _findWidth: function() {
434    return $(this.options.inherit_width_from).width();
435  },
436  _findHeight: function() {
437    return $(this.options.inherit_height_from).height();
438  },
439
440  _findMultiplier: function() {
441    return this.size() === 1 ? 1 : 3;
442  },
443
444  _upcomingSlide: function(direction, from_hash_change) {
445    if (from_hash_change && !isNaN(direction)) {
446      direction = direction - 1;
447    }
448
449    if ((/next/).test(direction)) {
450      return this._nextInDom();
451
452    } else if ((/prev/).test(direction)) {
453      return this._prevInDom();
454
455    } else if ((/\d/).test(direction)) {
456      return +direction;
457
458    } else if (direction && (/\w/).test(direction)) {
459      var index = this._findSlideById(direction);
460      if (index >= 0) {
461        return index;
462      } else {
463        return 0;
464      }
465
466    } else {
467      return 0;
468    }
469  },
470
471  _findSlideById: function(id) {
472    return this.$container.find('#' + id).index();
473  },
474
475  _findPositions: function(current, thisRef) {
476    thisRef = thisRef || this;
477
478    if (current === undefined) {
479      current = -1;
480    }
481
482    thisRef.current = current;
483    thisRef.next    = thisRef._nextInDom();
484    thisRef.prev    = thisRef._prevInDom();
485  },
486
487  _nextInDom: function() {
488    var index = this.current + 1;
489
490    if (index === this.size()) {
491      index = 0;
492    }
493
494    return index;
495  },
496
497  _prevInDom: function() {
498    var index = this.current - 1;
499
500    if (index < 0) {
501      index = this.size() - 1;
502    }
503
504    return index;
505  },
506
507  _parseHash: function(hash) {
508    hash = hash || window.location.hash;
509    hash = hash.replace(/^#/, '');
510
511    if (hash && !isNaN(+hash)) {
512      hash = +hash;
513    }
514
515    return hash;
516  },
517
518  size: function() {
519    return this.$container.children().length;
520  },
521
522  destroy: function() {
523    return this.$el.removeData();
524  },
525
526  update: function() {
527    this.css.children();
528    this.css.containers();
529    this.css.images();
530
531    this.pagination._addItem(this.size())
532
533    this._findPositions(this.current);
534    this.$el.trigger('updated.slides');
535  },
536
537  stop: function() {
538    clearInterval(this.play_id);
539    delete this.play_id;
540
541    this.$el.trigger('stopped.slides');
542  },
543
544  start: function() {
545    var that = this;
546
547    if (that.options.hashchange) {
548      $(window).trigger('hashchange');
549    } else {
550      this.animate();
551    }
552
553    if (this.options.play) {
554      if (this.play_id) {
555        this.stop();
556      }
557
558      this.play_id = setInterval(function() {
559        that.animate();
560      }, this.options.play);
561    }
562
563    this.$el.trigger('started.slides');
564  },
565
566  animate: function(direction, userCallback) {
567    var that = this,
568        orientation = {};
569
570    if (this.animating) {
571      return;
572    }
573
574    this.animating = true;
575
576    if (direction === undefined) {
577      direction = 'next';
578    }
579
580    orientation.upcoming_slide = this._upcomingSlide(direction);
581
582    if (orientation.upcoming_slide >= this.size()) {
583      return;
584    }
585
586    orientation.outgoing_slide    = this.current;
587    orientation.upcoming_position = this.width * 2;
588    orientation.offset            = -orientation.upcoming_position;
589
590    if (direction === 'prev' || direction < orientation.outgoing_slide) {
591      orientation.upcoming_position = 0;
592      orientation.offset            = 0;
593    }
594
595    if (that.size() > 1) {
596      that.pagination._setCurrent(orientation.upcoming_slide);
597    }
598
599    if (that.options.hashchange) {
600      var hash = orientation.upcoming_slide + 1,
601          id = that.$container.children(':eq(' + orientation.upcoming_slide + ')').attr('id');
602
603      if (id) {
604        window.location.hash = id;
605      } else {
606        window.location.hash = hash;
607      }
608    }
609    if (that.size() === 1) {
610      that.stop();
611      that.options.play = 0;
612      that.options.animation_speed = 0;
613      orientation.upcoming_slide    = 0;
614      orientation.outgoing_slide    = -1;
615    }
616    that.$el.trigger('animating.slides', [orientation]);
617
618    that.animation(orientation, function() {
619      that._findPositions(orientation.upcoming_slide, that);
620
621      if (typeof userCallback === 'function') {
622        userCallback();
623      }
624
625      that.animating = false;
626      that.$el.trigger('animated.slides');
627
628      if (!that.init) {
629        that.$el.trigger('init.slides');
630        that.init = true;
631        that.$container.fadeIn('fast');
632      }
633    });
634  }
635};
636
637// jQuery plugin definition
638
639$.fn[plugin] = function(option, args) {
640  var result = [];
641
642  this.each(function() {
643    var $this, data, options;
644
645    $this = $(this);
646    data = $this.data(plugin);
647    options = typeof option === 'object' && option;
648
649    if (!data) {
650      result = $this.data(plugin, (data = new Superslides(this, options)));
651    }
652
653    if (typeof option === "string") {
654      result = data[option];
655      if (typeof result === 'function') {
656        return result = result.call(data, args);
657      }
658    }
659  });
660
661  return result;
662};
663
664$.fn[plugin].fx = {};
665
666})(this, 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.