1(function ($) { 2 'use strict'; 3 4 Drupal.behaviors.behaviorSlider = { 5 attach: function (context, settings) { 6 $('.p-slider').once('slider').each(function () { 7 if($(this).is(":visible")) { 8 var slider = new Slider(this, $(this).hasClass('p-slider--autorun')); 9 slider.init(); 10 } 11 }); 12 13 $(document).once('silder-global').each(function () { 14 $('.p-angebote--btn-show-preview').on('click', function(event) { 15 event.preventDefault(); 16 17 if ($('.p-angebote__slider-wrapper--preview').is(":hidden")) { 18 $('.p-angebote__slider-wrapper--current').slideUp(function() { 19 $('.p-angebote__slider-wrapper--preview').slideDown(); 20 21 var container = $('.p-angebote__slider-wrapper--preview .p-slider'); 22 if(!$(container).hasClass('p-slider--init')) { 23 var slider = new Slider(container, $(container).hasClass('p-slider--autorun')); 24 slider.init(); 25 } 26 27 $('.p-angebote--btn-show-preview').text('zu den aktuellen Angeboten') 28 }); 29 } else { 30 $('.p-angebote__slider-wrapper--preview').slideUp(function() { 31 $('.p-angebote__slider-wrapper--current').slideDown(); 32 33 $('.p-angebote--btn-show-preview').text('zur Angebotsvorschau') 34 }); 35 } 36 }); 37 }); 38 } 39 }; 40 41 var Slider = function(container, autorun) { 42 this.intervall = 6000; 43 this.swipeOverflow = 30; 44 this.container = $(container); 45 this.sliderPane = $('.p-slider__pane', container); 46 this.itemWidth; 47 this.sliderPaneWidth; 48 this.run = true, 49 this.swipe = !this.container.hasClass('p-slider--mp-teasers') || $( window ).width() < 960; 50 this.slideType = this.container.hasClass('p-slider--slide-smooth') ? 'smooth' : 'step'; 51 52 this.init = function() { 53 var that = this; 54 55 if ($('.p-slider__btn-jump-container', that.container).length && $('.p-sliderelement', this.sliderPane).length > 1) { 56 var buttons = $('.p-slider__btn-jump-container-bullets', this.container); 57 if (buttons.length > 0) { //wenn Bullets, so viele Buttons wie Slider-Elemente einhaengen 58 $('.p-sliderelement', this.sliderPane).each(function() { 59 var id = this.id.replace('p-', ''); 60 buttons.append('<div class="p-slider__btn-jump" data-index="p-slider__btn-jump-' + id + '"></div>') 61 }); 62 } 63 $('.p-slider__btn-jump-container', that.container).each(function() { 64 $('.p-slider__btn-jump', this).first().addClass('p-slider__btn-jump--active'); 65 }) 66 } 67 68 jQuery('.p-slider__btn-jump', this.container).click(function() { 69 that.run = false; 70 var id = $(this).attr('data-index').replace(/p-slider__btn-jump-/, ''); 71 that.setItem(id); 72 }); 73 74 $('.p-slider__btn-scroll-left', this.container).click(function(event) { 75 event.preventDefault(); 76 that.run = false, 77 that.switchItem(-1); 78 }) 79 80 $('.p-slider__btn-scroll-right', this.container).click(function(event) { 81 event.preventDefault(); 82 that.run = false, 83 that.switchItem(1); 84 }) 85 86 $('.p-slider__pane-container', this.container).on('swipeleft', function(event) { 87 if (that.swipe) { 88 that.run = false; 89 if (that.slideType == 'step') { 90 that.switchItem(1); 91 } else { 92 that.slide(1, event.swipestart.coords[0] - event.swipestop.coords[0], event.swipestop.time - event.swipestart.time); 93 } 94 } 95 }); 96 97 $('.p-slider__pane-container', this.container).on('swiperight', function(event) { 98 if (that.swipe) { 99 that.run = false; 100 if (that.slideType == 'step') { 101 that.switchItem(-1); 102 } else { 103 that.slide(-1, event.swipestop.coords[0] - event.swipestart.coords[0], event.swipestop.time - event.swipestart.time); 104 } 105 } 106 }); 107 108 this.initSize(); 109 if (autorun && $('.p-sliderelement', this.sliderPane).length > 1) { 110 this.start(); 111 } 112 113 this.container.addClass('p-slider--init'); 114 115 jQuery(window).resize(function() { 116 that.initSize(); 117 }); 118 } 119 120 this.initSize = function() { 121 var that = this; 122 123 this.itemWidth = $('.p-sliderelement', this.sliderPane).outerWidth();
124 this.sliderPaneWidth = 0; 125 126 var set = $('.p-sliderelement', this.sliderPane); 127 var length = set.length; 128 var maxHeight = 0; 129 set.each(function(index) { 130 var text = $('.p-sliderelement__text-container', this); 131 that.updateText(text); 132 if ($('.p-slider__text-below-container', that.container).height() > maxHeight) { 133 maxHeight = $('.p-slider__text-below-container', that.container).height(); 134 } 135 that.sliderPaneWidth += that.itemWidth 136 if (index === (length - 1)) { //letztes Element 137 that.sliderPaneWidth -= parseInt($(this).css('paddingRight')); //padding-right abziehen 138 } 139 }); 140 $('.p-slider__text-below-container', that.container).height(maxHeight); //Hoehe text_below_container setzen 141 } 142 143 this.start = function() { 144 var that = this; 145 146 //Text in Container schreiben 147 that.updateText(); 148 149 window.setTimeout(function() { 150 that.next(); 151 }, this.intervall); 152 } 153 154 this.next = function() { 155 var that = this; 156 157 if (this.run) { 158 this.switchItem(1); 159 window.setTimeout(function() { 160 that.next(); 161 }, this.intervall); 162 } 163 } 164 165 this.setItem = function(id) { 166 var that = this; 167 168 //Richtung und Schritte ermitteln 169 var direction = 0; 170 var steps = 0; 171 $('.p-slider__btn-jump', this.container).each(function() { 172 if (direction != 0) { //wenn Startitem bereits gefunden, steps++ 173 steps++; 174 } 175 176 if ($(this).attr('data-index').replace(/p-slider__btn-jump-/, '') == id) { //aktuelles Item hat ID 177 if (direction == 0) { //wenn Startitem Animation noch nicht gefunden 178 direction = -1; //Richtung festlegen 179 } else { 180 return false; //aktuelles Item ist Zielitem Animation -> break 181 } 182 } 183 if ($(this).hasClass('p-slider__btn-jump--active')) { //aktuelels Item ist aktives Item 184 if (direction == 0) { //wenn Startitem Animation noch nicht gefunden 185 direction = 1; //Richtung festlegen 186 } else { 187 return false; //aktuelles Item ist Zielitem Animation -> break 188 } 189 } 190 }); 191 if (steps > 0) { 192 that.switchItem(direction, steps); 193 } 194 } 195 196 this.switchItem = function(direction, steps) { 197 if(steps === undefined) { 198 steps = 1; 199 } 200 var that = this; 201 202 $('.p-slider__text-below-container', this.container).animate({ 203 opacity: 0, 204 }, 300); 205 206 if (direction == 1) { 207 //Elemente, die zwischen Start- und Zielitem liegen ausblenden 208 for (var i = 1; i < steps; i++) { 209 $('.p-sliderelement:eq(' + i + ')', that.sliderPane).hide(); 210 } 211 212 this.sliderPane.css('transform', 'translateX(-' + this.itemWidth + 'px)'); // Sliderpane um 1 Item nach links veschieben 213 214 this.sliderPane.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) { 215 //SliderPane zurueck setzen 216 that.sliderPane.addClass('notransition'); 217 that.sliderPane.css('transform', 'translateX(0px)'); 218 that.sliderPane[0].offsetHeight; 219 that.sliderPane.removeClass('notransition'); 220 //Items umsortieren 221 for (var i = 0; i < steps; i++) { 222 that.sliderPane.append($('.p-sliderelement', that.sliderPane).first().detach().show()); 223 } 224 that.setActiveButton(); //akitven Button setzen 225 that.updateText(); //Text in Container schreiben 226 }); 227 } else if (direction == -1) { 228 //Items umsortieren 229 for (var i = 1; i <= steps; i++) { 230 that.sliderPane.prepend($('.p-sliderelement', that.sliderPane).last().detach()); 231 if (i < steps) { 232 $('.p-sliderelement', that.sliderPane).first().hide(); //Elemente, die zwischen Start- und Zielitem liegen ausblenden 233 } 234 } 235 //SliderPane zurueck setzen 236 that.sliderPane.addClass('notransition'); 237 that.sliderPane.css('transform', 'translateX(-' + this.itemWidth + 'px)'); 238 that.sliderPane[0].offsetHeight; 239 that.sliderPane.removeClass('notransition'); 240 241 this.sliderPane.css('transform', 'translateX(0px)'); // Sliderpane um 1 Item nach rechts veschieben 242 this.sliderPane.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) { 243 //Elemente, die zwischen Start- und Zielitem liegen wieder einblenden 244 for (var i = 1; i < steps; i++) { 245 $('.p-sliderelement:eq(' + i + ')', that.sliderPane).show(); 246 } 247 that.setActiveButton(); //akitven Button setzen 248 that.updateText(); //Text in Container schreiben 249 }); 250 } 251 } 252 253 this.setActiveButton = function(text) { 254 var that = this; 255 256 if ($('.p-slider__btn-jump-container', that.container).length ) { 257 var id = $('.p-sliderelement', that.container).first().attr('id').replace('p-', ''); 258 $('.p-slider__btn-jump', that.container).removeClass('p-slider__btn-jump--active'); 259 $('[data-index="p-slider__btn-jump-' + id + '"]').addClass('p-slider__btn-jump--active'); 260 } 261 } 262 263 this.updateText = function(text) { 264 var that = this; 265 266 if ($('.p-slider__text-below-container', that.container).length ) { 267 text = typeof text === 'undefined' ? $('.p-sliderelement__text-container', $('.p-sliderelement', that.container).first()) : text; 268 $('.p-slider__text-below-container', that.container).html(text.html()).animate({ 269 opacity: 1, 270 }, 300); 271 } 272 } 273 274 this.slide = function(direction, swipeDistance, swipeTime) { 275 var that = this; 276 277// var distance = -direction * swipeDistance * (1200 / swipeTime); 278 var distance = -direction * swipeDistance * 10 * (100 / swipeTime); 279 var swipeTime = swipeTime / 100; 280 var newX; 281 if(this.sliderPane.css('transform') != 'none') { 282 newX = parseInt(this.sliderPane.css('transform').split(/[()]/
282)[1].split(',')[4]) + distance; 283 } else { 284 newX = parseInt(distance); 285 } 286 newX = newX > that.swipeOverflow ? that.swipeOverflow : newX; 287 var endX = -(that.sliderPaneWidth - this.sliderPane.width() + that.swipeOverflow); 288 newX = newX < endX ? endX : newX; 289 that.sliderPane.css('transition-duration', swipeTime + 's'); 290 this.sliderPane.css('transform', 'translateX(' + newX + 'px)'); // Sliderpane veschieben 291 this.sliderPane.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(event) { 292 var currentX = parseInt(that.sliderPane.css('transform').split(/[()]/)[1].split(',')[4]); 293 var newX = null; 294 if (currentX > 0) { 295 newX = 0; 296 } else if (currentX < -(that.sliderPaneWidth - that.sliderPane.width())) { 297 newX = -(that.sliderPaneWidth - that.sliderPane.width()); 298 } 299 if (newX !== null) { 300 var oldTransDur = that.sliderPane.css('transition-duration'); 301 that.sliderPane.css('transition-duration', '.4s'); 302 that.sliderPane.css('transform', 'translateX(' + newX + 'px)'); // Sliderpane zurueck auf Startpunkt veschieben 303 that.sliderPane.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(event) { 304 that.sliderPane.css('transition-duration', oldTransDur); 305 }); 306 } 307 }); 308 } 309 } 310})(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.