1/*! 2 * jQuery Conveyor Ticker (jConveyorTicker) 3 * Description: jQuery plugin to create simple horizontal conveyor belt animated tickers. 4 * 5 * Copyright (c) 2017 Luis Luz - UXD Lda 6 * 7 * Licensed under the MIT license: 8 * http://www.opensource.org/licenses/mit-license.php 9 * 10 * Project home: 11 * https://github.com/lluz/jquery-conveyor-ticker 12 * 13 * Version: 1.0.2 14 * 15 */ 16 17(function($, window, document, undefined) { 18 19 $.fn.jConveyorTicker = function(options) { 20 if ( this === undefined || this.length === 0 ) { 21 console.log('jquery.jConveyorTicker() INITIALIZATION ERROR: You need to select one or more elements. See documentation form more information.'); 22 return false; 23 } 24 25 var settings = { 26 anim_duration: 200, 27 reverse_elm: false, 28 force_loop: false 29 }; 30 var cycle_duration = settings.anim_duration; 31 var reverse_commute = settings.reverse_elm; 32 var initialization_forced = settings.force_loop; 33 34 if (options) { 35 if ( options.anim_duration !== undefined ) { 36 cycle_duration = options.anim_duration; 37 } 38 39 if ( options.reverse_elm !== undefined ) { 40 reverse_commute = options.reverse_elm; 41 } 42 43 if ( options.force_loop !== undefined ) { 44 initialization_forced = options.force_loop; 45 } 46 47 $.extend(settings, options); 48 } 49 50 this.each(function(){ 51 var $wrap = $(this); 52 var $list = $wrap.children('ul'); 53 54 $list 55 .css({ 56 'margin': '0', 57 'padding': '0', 58 'list-style': 'none' 59 }) 60 .children('li') 61 .css({ 62 'display': 'inline-block' 63 }); 64 65 var $listRawWidth = $list.width(); 66 var $parentWidth = $list.parent().width(); 67 var $parent1stThreshold = ($parentWidth / 2) - 20; 68 69 $list 70 .removeAttr('style') 71 .children('li') 72 .removeAttr('style'); 73 74 $wrap.addClass('jctkr-wrapper'); 75 76 var conveyorInit = function(){ 77 var $listItems1stClone = $list.clone().children('li'); 78 $list.append($listItems1stClone); 79 80 var listTotalWidth = 0; 81 $list.children().each(function(){ 82 listTotalWidth += $(this).outerWidth(); 83 }); 84 $list.width(listTotalWidth); 85 86 var conveyorAnimate = function(action){ 87 var tw = $list.width(); 88 var tp = $list.position().left; 89 var operator = '-'; 90 var direction = 'normal'; 91 var tcal; 92 93 if (action !== undefined && action === 'reverse'){ 94 tcal = (tw / 2); 95 if (tp > 0){ 96 $list.css('left', '-' + tcal + 'px'); 97 conveyorAnimate('reverse'); 98 return; 99 } 100 operator = '+'; 101 direction = 'reverse'; 102 } 103 else { 104 tcal = -1 * (tw / 2); 105 if (tp < tcal){ 106 var toffs = -1 * (tcal - tp); 107 $list.css('left', toffs + 'px'); 108 conveyorAnimate(direction); 109 return; 110 } 111 } 112 113 $list.animate({ 114 left: operator + '=10px' 115 }, cycle_duration, 'linear', function(){ 116 conveyorAnimate(direction); 117 }); 118 }; 119 120 $wrap 121 .hover(function(){ 122 $list.stop(); 123 }, function(){ 124 $list.stop(); 125 conveyorAnimate('normal'); 126 }); 127 128 if ( reverse_commute ){ 129 $wrap.prev('.jctkr-label') 130 .hover(function(){ 131 $list.stop(); 132 conveyorAnimate('reverse'); 133 }, function(){ 134 $list.stop(); 135 conveyorAnimate('normal'); 136 }).click(function(){ 137 return false;
138 }); 139 } 140 conveyorAnimate('normal'); 141 }; 142 143 if ( $listRawWidth >= $parent1stThreshold ){ 144 conveyorInit(); 145 } 146 else if ( initialization_forced ){ 147 var $itemsWidth, $containerWidth = 0; 148 var itemsReplicate = function(){ 149 var $listItems1stClone = $list.clone().children('li'); 150 $list.append($listItems1stClone); 151 152 $itemsWidth = $list.width(); 153 $containerWidth = $list.parent().width(); 154 155 if ( $itemsWidth < $containerWidth ){ 156 itemsReplicate(); 157 } 158 else { 159 conveyorInit(); 160 return false; 161 } 162 }; 163 164 itemsReplicate(); 165 166 while ( $itemsWidth < $containerWidth ) { 167 if ( $itemsWidth >= $parent1stThreshold ) { 168 conveyorInit(); 169 break; 170 } 171 itemsReplicate(); 172 } 173 } 174 $wrap.addClass('jctkr-initialized'); 175 }); 176 }; 177 178})(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.