1(function($){ 2 'use strict'; 3 $.fn.AcmeTicker = function(options) { 4 /*Merge options and default options*/ 5 let opts = $.extend({}, $.fn.AcmeTicker.defaults, options); 6 7 /*Functions Scope*/ 8 let thisTicker = $(this), intervalID, timeoutID, isPause = false; 9 10 /*Always wrap, used in many place*/ 11 thisTicker.wrap("<div class='acmeticker-wrap'></div>"); 12 13 /*Wrap is always relative*/ 14 thisTicker.parent().css({ 15 position: 'relative' 16 }) 17 /*Hide expect first*/ 18 thisTicker.children("li").not(":first").hide(); 19 20 /*Lets init*/ 21 init(); 22 function init(){ 23 switch (opts.type) { 24 case 'vertical': 25 case 'horizontal': 26 vertiZontal() 27 break; 28 29 case 'marquee': 30 marQuee() 31 break; 32 33 case 'typewriter': 34 typeWriter() 35 break; 36 37 default: 38 break 39 } 40 } 41 42 /*Vertical - horizontal 43 * **Do not change code lines*/ 44 function vertiZontal(prevNext = false){ 45 let speed = opts.speed, 46 autoplay = opts.autoplay, 47 direction = opts.direction; 48 49 if( prevNext){ 50 speed = 0; 51 autoplay = 0; 52 clearInterval(intervalID); 53 intervalID = false; 54 } 55 56 function play(){ 57 if( isPause){ 58 clearInterval(intervalID); 59 intervalID = false; 60 return false; 61 } 62 let dChild, 63 eqType, 64 mType, 65 mVal; 66 67 dChild = thisTicker.find('li:first'); 68 if(direction === 'up' || direction === 'right'){ 69 eqType = '-='; 70 } 71 else{ 72 eqType = '+='; 73 } 74 if(opts.type === 'horizontal' ){ 75 mType = 'left'; 76 mVal = dChild.outerWidth(true); 77 } 78 else{ 79 mType = 'margin-top'; 80 mVal = dChild.outerHeight(true); 81 } 82 if( prevNext === 'prev'){ 83 thisTicker.find('li:last').detach().prependTo(thisTicker); 84 } 85 else{ 86 dChild.detach().appendTo(thisTicker); 87 } 88 89 thisTicker.find('li').css({ 90 opacity: '0', 91 display: 'none' 92 }); 93 thisTicker.find('li:first').css({ 94 opacity: '1', 95 position: 'absolute', 96 display: 'block', 97 [mType]: eqType + mVal + 'px', 98 }); 99 thisTicker.find('li:first').animate( 100 {[mType]: '0px'}, 101 speed, 102 function () { 103 clearInterval(intervalID); 104 intervalID = false; 105 vertiZontal(); 106 }); 107 } 108 if( intervalID){ 109 return false 110 } 111 intervalID = setInterval(play, autoplay); 112 } 113 114 /*Type-Writer 115 * **Do not change code lines*/ 116 function typeWriter( prevNext = false ) { 117 if( isPause){ 118 return false; 119 } 120 if( prevNext){ 121 clearInterval(intervalID); 122 intervalID = false; 123 124 clearTimeout(timeoutID); 125 timeoutID = false; 126 127 if( prevNext === 'prev'){ 128 thisTicker.find('li:last').detach().prependTo(thisTicker); 129 } 130 else{ 131 thisTicker.find('li:first').detach().appendTo(thisTicker); 132 } 133 } 134 135 let speed = opts.speed, 136 autoplay = opts.autoplay, 137 typeEl = thisTicker.find('li:first'), 138 wrapEl = typeEl.children(), 139 count = 0; 140 141 if( typeEl.attr('data-text')){ 142 wrapEl.text(typeEl.attr('data-text')) 143 } 144 145 let allText = typeEl.text(); 146 147 thisTicker.find('li').css({ 148 opacity: '0', 149 display: 'none' 150 }); 151 152 function tNext() { 153 thisTicker.find('li:first').detach().appendTo(thisTicker); 154 155 clearTimeout(timeoutID); 156 timeoutID = false; 157 158 typeWriter(); 159 } 160 161 function type() { 162 count++; 163 let typeText = allText.substring(0, count); 164 if( !typeEl.attr('data-text')){ 165 typeEl.attr('data-text',allText); 166 } 167 168 if ( count <= allText.length ){ 169 wrapEl.text(typeText); 170 typeEl.css({ 171 opacity: '1', 172 display: 'block', 173 }); 174 } 175 else{ 176 clearInterval(intervalID); 177 intervalID = false; 178 timeoutID = setTimeout(tNext, autoplay); 179 } 180 } 181 if( !intervalID){ 182 intervalID = setInterval(type, speed); 183 } 184 } 185 186 /*marQuee 187 * **Do not change code lines*/ 188 function marQuee() { 189 /*Marquee Special*/ 190 let speed = opts.speed, 191 direction = opts.direction, 192 wrapWidth, 193 dir = 'left', 194 totalTravel, 195 defTiming, 196 listWidth = 0, 197 mPause = false; 198 199 mInit(); 200 function mInit(){ 201 thisTicker.css({ 202 position: 'absolute' 203 }) 204 thisTicker.find('li').css({ 205 display: 'inline-block', 206 marginRight: '10px', 207 }); 208 let tickerList = thisTicker.find("li"); 209 wrapWidth = thisTicker.parent().outerWidth(true); 210 211 if( direction === 'right'){ 212 dir = 'right' 213 } 214 215 /*Calculating ticker width*/ 216 thisTicker.width(10000);/*temporary width to prevent inline elements wrapping to initial width of ticker*/ 217 tickerList.each(function() { 218 listWidth += $(this).outerWidth(true)+5;/*+5 for some missing px*/ 219 }); 220 thisTicker.width(listWidth);
221 222 totalTravel = listWidth + wrapWidth; 223 defTiming = totalTravel / speed; 224 225 marQueeIt(listWidth, listWidth/speed); 226 } 227 228 function marQueeIt(lPos, lSpeed) { 229 thisTicker.animate( 230 { [dir]: '-=' + lPos }, 231 lSpeed, 232 "linear", 233 function() { 234 thisTicker.css({ 235 [dir]: wrapWidth 236 }); 237 marQueeIt(totalTravel, defTiming); 238 } 239 ); 240 } 241 242 function mRestart(){ 243 let offset = thisTicker.offset(), 244 rOffset = direction === 'right'?(listWidth-offset.left):offset.left, 245 remainingSpace = rOffset + listWidth, 246 remainingTime = remainingSpace/speed; 247 248 marQueeIt(remainingSpace, remainingTime); 249 } 250 251 opts.controls.toggle && opts.controls.toggle.on('click', function(e){ 252 mPause = !mPause; 253 $(document).trigger('acmeTickerToggle', thisTicker, mPause) 254 if( mPause){ 255 thisTicker.stop(); 256 } 257 else{ 258 mRestart(); 259 } 260 }); 261 if(opts.pauseOnHover){ 262 thisTicker.mouseenter(function(){ 263 thisTicker.stop(); 264 }).mouseleave(function(){ 265 mRestart(); 266 }); 267 } 268 if(opts.pauseOnFocus){ 269 thisTicker.focusin(function(){ 270 thisTicker.stop(); 271 }).focusout(function(){ 272 mRestart(); 273 }); 274 } 275 } 276 /*marQuee End*/ 277 278 /*Actions/Controls*/ 279 if( opts.type !== 'marquee'){ 280 opts.controls.prev && opts.controls.prev.on('click', function(e){ 281 e.preventDefault(); 282 switch (opts.type) { 283 case 'typewriter': 284 typeWriter('prev') 285 break; 286 287 default: 288 vertiZontal('prev') 289 break 290 } 291 }); 292 opts.controls.next && opts.controls.next.on('click', function(e){ 293 e.preventDefault(); 294 switch (opts.type) { 295 case 'typewriter': 296 typeWriter('next') 297 break; 298 299 default: 300 vertiZontal('next') 301 break 302 } 303 }); 304 function restart(){ 305 if( !isPause){ 306 init(); 307 } 308 } 309 opts.controls.toggle && opts.controls.toggle.on('click', function(e){ 310 e.preventDefault(); 311 isPause = !isPause; 312 $(document).trigger('acmeTickerToggle', thisTicker, isPause) 313 restart(); 314 315 }); 316 if(opts.pauseOnHover){ 317 thisTicker.mouseenter(function(){ 318 isPause = true; 319 }).mouseleave(function(){ 320 isPause = false; 321 }); 322 restart(); 323 } 324 if(opts.pauseOnFocus){ 325 thisTicker.focusin(function(){ 326 isPause = true; 327 }).focusout(function(){ 328 isPause = false; 329 }); 330 restart(); 331 } 332 } 333 }; 334 335 // plugin defaults - added as a property on our plugin function 336 $.fn.AcmeTicker.defaults = { 337 /*Note: Marquee only take speed not autoplay*/ 338 type:'horizontal',/*vertical/horizontal/marquee/typewriter*/ 339 autoplay: 4000,/*true/false/number*/ /*For vertical/horizontal 4000*//*For typewriter 2000*/ 340 speed: 600,/*true/false/number*/ /*For vertical/horizontal 600*//*For marquee 0.05*//*For typewriter 50*/ 341 direction: 'up',/*up/down/left/right*//*For vertical up/down*//*For horizontal/marquee right/left*//*For typewriter direction doesnot work*/ 342 pauseOnFocus: true, 343 pauseOnHover: true, 344 transition:0.9, 345 controls: { 346 prev: '',/*Can be used for vertical/horizontal/typewriter*//*not work for marquee*/ 347 next: '',/*Can be used for vertical/horizontal/typewriter*//*not work for marquee*/ 348 toggle: ''/*Can be used for vertical/horizontal/marquee/typewriter*/ 349 } 350 }; 351})(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.