1function UmSlider(el, options){ 2 var that = this; 3 this.inited = false; 4 this.content = el.find('.content:first'); 5 if ( !this.content || this.content.length === 0) return false; 6 var width = this.content.outerWidth(); 7 var controls = el.find('.controls:first'); 8 9 this.onChange = options.onChange || function(prev, next){ 10 prev.removeClass('active'); 11 next.addClass('active'); 12 }; 13 this.infinite = options.infinite || false; 14 // controls 15 this.dotsWrap = options.dotsWrap || controls.children('.dots'); 16 this.dots = this.dotsWrap.children('.dot'); 17 this.prev = options.prev || controls.children('.prev'); 18 this.next = options.next || controls.children('.next'); 19 this.numeric = options.numeric || controls.children('.numeric'); 20 this.centeringSingle = options.centeringSingle || false; 21 22 // items 23 this.items = options.items || this.content.children(); 24 this.count = this.items.length; 25 26 // grouping into pages 27 this.groupBy = options.groupBy || 1; 28 this.responsive = options.responsive || [{ bp: 0, groupBy: this.groupBy }]; 29 // responsive: array of objects { bp, groupBy}, where bp stands for "breakpoint". 30 // first object is always bp null and contains default items, if other bps fail 31 this.getGroupBy = function(){ 32 if ( that.responsive === 'auto' ){ 33 var activeItems = that.items.filter('.active'); 34 if (!activeItems.length) activeItems = that.items.addClass('active'); 35 if (!activeItems.eq(0).is(':visible')) return that.groupBy; 36 var contentWidth = that.content.get(0).getBoundingClientRect().width, 37 itemWidth = activeItems.get(0).getBoundingClientRect().width, 38 percent = (itemWidth * 100) / contentWidth; 39 res = Math.floor(100 / Math.floor(percent)); 40 41 return res; 42 } 43 for ( var i = 0; i < that.responsive.length; i++){ 44 if ( Modernizr.mq('(max-width: '+that.responsive[i].bp+'px)') ){ 45 return that.responsive[i].groupBy; 46 } 47 } 48 // if we arrived here, it means that all bp's failed and we should return default. 49 return that.responsive[0].groupBy; 50 } 51 52 this.changeNumeric = function(){ 53 var shown = that.groupBy; 54 if ( that.activePage === that.pageCount-1 ) shown = that.pages[that.activePage].length; 55 if ( shown > 1 ){ 56 that.numeric.html(that.activePage+1+'-'+shown+' / '+that.count); 57 } else { 58 that.numeric.html(that.activePage+1+' / '+that.count); 59 } 60 } 61 62 this.pages = []; // each item of array = another array containing items in that page 63 this.pageCount; 64 this.active; // active item, not page - will be used in item-navigation someday 65 this.activePage; 66 this.updatePages = function(){ 67 that.groupBy = that.getGroupBy(); 68 that.pages = []; 69 for (var i = 0; i < that.items.length; i += that.groupBy){ 70 if ( (i+that.groupBy) >= that.items.length){ 71 that.pages.push(that.items.slice(i)); 72 break; 73 } 74 that.pages.push(that.items.slice(i, i+that.groupBy)); 75 } 76 that.pageCount = that.pages.length; 77 if ( that.pageCount === 1 && that.centeringSingle){ 78 that.content.addClass('center'); 79 } else that.content.removeClass('center'); 80 that.active = that.items.filter('.active').eq(0).index(); 81 if ( -1 === that.active ){ 82 // if no active items found, start with 0 83 that.active = 0; 84 } 85 that.activePage = Math.floor( that.active / that.groupBy ); 86 that.items.removeClass('active'); 87 if ( that.pageCount > 0 ) that.pages[that.activePage].addClass('active'); 88 that.updateDots(); 89 that.updateBtns(); 90 that.changeNumeric(); 91 } 92 this.updateDots = function(){ 93 var dotsCount = that.dots.length; 94 if ( that.pageCount <= 1 ){ 95 if ( dotsCount !== 0 ){ 96 that.dots.remove(); 97 that.dots = $(); 98 } 99 return; 100 } 101 if ( that.pageCount > dotsCount ){ 102 var newDots = []; 103 for ( var i = 0; i < that.pageCount - dotsCount; i++ ){ 104 var newDot = $('<i class="dot" />'); 105 newDots.push(newDot); 106 that.dots = that.dots.add(newDot); 107 } 108 that.dotsWrap.append(newDots); 109 } else if ( that.pageCount < dotsCount ){ 110 var removed = that.dots.slice(that.pageCount).remove(); 111 that.dots = that.dots.not(removed); 112 } 113 that.dots.eq(that.activePage).addClass('active').siblings('.active').removeClass('active'); 114 } 115 this.updateBtns = function(){ 116 if ( that.pageCount <= 1 ) { 117 that.prev.css('display', 'none'); 118 that.next.css('display', 'none'); 119 return; 120 } else { 121 that.prev.css('display', ''); 122 that.next.css('display', ''); 123 } 124 125 that.prev.removeClass('disabled'); 126 that.next.removeClass('disabled'); 127 if ( that.activePage === 0 && !that.infinite){ 128 that.prev.addClass('disabled'); 129 } 130 if ( that.activePage === that.pageCount-1 && !that.infinite){ 131 that.next.addClass('disabled'); 132 } 133 } 134 this.updatePages(); 135 136 this.animating = false; 137 // defining prev and next items, start animation 138 this.changePage = function(targetPage){ 139 if ( that.animating ){ return;} 140 that.counter = 0; // if cycling - this will start interval over 141 that.videoPlaying = false; 142 var dir = '>'; 143 var prevPage = that.activePage; 144 145 // changing active page, checking direction (forward / backward) and define 146 // animations accordingly 147 switch (targetPage){ 148 case 'next': 149 that.activePage++; 150 break; 151 case 'prev': 152 that.activePage--; 153 dir = '<'; 154 break; 155 default: 156 if ( $.isNumeric(targetPage) ){ 157 if ( targetPage < that.activePage){ 158 dir = '<'; 159 } 160 that.activePage = targetPage; 161 } else { 162 that.activePage++; // just in case smth go wrong 163 } 164 } 165 166 // checking if went outside limits 167 if ( that.activePage >= that.pageCount ) that.activePage = 0; 168 if ( that.activePage < 0) that.activePage = that.pageCount - 1; 169 that.updateBtns(); 170 that.changeNumeric(); 171 172 // switching active dot 173 that.dots.eq(prevPage).removeClass('active'); 174 that.dots.eq(that.activePage).addClass('active'); 175 176 // get prev and next items and pass them to change function with dir 177 that.onChange(that.pages[prevPage], that.pages[that.activePage], dir, prevPage, that.activePage); 178 } 179 180 // controls functionality
181 this.dotsWrap.on('click', '.dot', function(){ 182 var _ = $(this); 183 if ( _.hasClass('active') ) return; 184 that.changePage( $(this).index() ); 185 }) 186 this.prev.on('click', function(){ 187 if ( $(this).hasClass('disabled') ) return; 188 that.changePage('prev'); 189 }) 190 this.next.on('click', function(){ 191 if ( $(this).hasClass('disabled') ) return; 192 that.changePage('next'); 193 }) 194 this.content.on('swipeleft', function(){ 195 if ( Modernizr.mq('(max-width: 767px)') ){ 196 that.changePage('next'); 197 } 198 }) 199 this.content.on('swiperight', function(){ 200 if ( Modernizr.mq('(max-width: 767px)') ){ 201 that.changePage('prev'); 202 } 203 }) 204 205 // auto sliding 206 this.cycle = options.cycle || false; 207 this.paused = false; 208 this.videoPlaying = false; 209 this.interval = options.interval || 8; // time in seconds 210 this.counter = 0; 211 var timer; 212 if ( this.cycle && this.count > 1){ 213 timer = setInterval(function(){ 214 if ( that.paused || that.videoPlaying ) return; 215 if ( that.counter++ === that.interval ){ 216 that.changePage('next'); 217 } 218 }, 1000); 219 el.hover(function(){ that.paused = true; }, function(){ that.paused = false; }); 220 } 221 222 function afterResize(){ 223 if ( that.groupBy !== that.getGroupBy() ){ 224 that.updatePages(); 225 } 226 } 227 var resizeTimer; 228 $(window).on('resize', function(){ 229 clearTimeout(resizeTimer); 230 resizeTimer = setTimeout(afterResize, 300); 231 }) 232 233 this.inited = true; 234 el.data('UmSlider', this); 235}/*function UMSlider(el, options)*/
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.