1jQuery.fn.endlessRiver = function (settings) { 2 // Settings before everything else 3 settings = jQuery.extend({ 4 speed: 100, 5 pause: true, 6 buttons: false 7 }, settings); 8 9 // Shared vars 10 var $buttons = $('<ul class="er-controls">' + 11 '<li class="prev glyphicon glyphicon-chevron-left"></li>' + 12 '<li class="pause glyphicon glyphicon-pause"></li>' + 13 '<li class="next glyphicon glyphicon-chevron-right"></li>' + 14 '</ul>'); 15 var clonesClassName = "tick-clones"; 16 var event_pause = "click.erPause"; 17 var event_play = "click.erPlay"; 18 var event_prev = "click.erPrev"; 19 var event_next = "click.erNext"; 20 var events_mouse = "mouseenter mouseleave"; 21 var playBtnClassNames = "play glyphicon-play pause glyphicon-pause"; 22 var tickerClassName = "tickercontainer"; 23 24 // Utils 25 var getFirstLi = function ($el) { 26 return $el.children("li:first"); 27 }; 28 29 var getTime = function (space) { 30 return space / settings.speed * 1000; 31 }; 32 33 return this.each(function () { 34 // Local reference to avoid conflicts 35 var $ = jQuery; 36 var $body = $("body"); 37 var $line = $(this); 38 // Local vars 39 var currentSpazio, currentTempo; 40 var uniqueId = "ER_" + +new Date(); 41 var run = true; 42 // 43 $line.wrap("<div id='" + uniqueId + "'></div>"); 44 $line.css({ 45 margin: "0 !important", 46 padding: "0 !important" 47 }); 48 var initialOffset = $line.offset().left; 49 var lineWidth = 1; 50 $line.children("li." + clonesClassName).remove(); 51 // Remove existing clones in case content is updated dynamically 52 $line.addClass("newsticker"); 53 var $mask = $line.wrap("<div class='mask'></div>"); 54 var $tickerContainer = $line.parent().wrap("<div class='" + tickerClassName + "'></div>"); 55 var $liElements = $line.children("li"); 56 57 // Function to fill the line with cloned items 58 var fill = function () { 59 lineWidth = 0; 60 var containerWidth = $tickerContainer.outerWidth(true); 61 while (lineWidth < containerWidth) { 62 $liElements.each(function () { 63 var $clone = $(this).clone(true).addClass(clonesClassName); 64 $line.append($clone); 65 lineWidth += $clone.outerWidth(true); 66 if (lineWidth >= containerWidth) { 67 return false; // Break loop if we fill the container 68 } 69 }); 70 } 71 }; 72 73 fill(); 74 $line.width(lineWidth); 75 $line.height($line.parent().height()); 76 77 function scrollContent(space, time) { 78 $line.animate({left: '-=' + space}, time, "linear", function () { 79 getFirstLi($line).appendTo($line); 80 $line.css("left", 0); 81 currentSpazio = getFirstLi($line).outerWidth(true); 82 currentTempo = time / space * currentSpazio; 83 if (run) { 84 scrollContent(currentSpazio, currentTempo); 85 } 86 }); 87 } 88 89 //BOOT 90 currentSpazio = getFirstLi($line).outerWidth(true); 91 currentTempo = currentSpazio / settings.speed * 1000; 92 scrollContent(currentSpazio, currentTempo); 93 94 function setHover() { 95 $line.off(events_mouse); 96 $line.hover(pause, resume); 97 } 98 99 function pause() { 100 $("#" + uniqueId + " .er-controls > .pause").toggleClass(playBtnClassNames); 101 run = false; 102 $line.stop(); 103 } 104 105 function resume() { 106 $("#" + uniqueId + " .er-controls > .play").toggleClass(playBtnClassNames); 107 run = true; 108 var offset = $line.offset().left; 109 var spaceLeft = offset + getFirstLi($line).outerWidth(true) - initialOffset; 110 var timeLeft = currentTempo / currentSpazio * spaceLeft; 111 scrollContent(spaceLeft, timeLeft); 112 } 113 114 if (settings.pause) { 115 setHover(); 116 } 117 118 if (settings.buttons) { 119 $buttons.insertAfter($tickerContainer); 120 // Delegate is better! 121 $body.on(event_pause, "#" + uniqueId + " .er-control
121s > .pause", function () { 122 if (!run) return false; 123 $(this).toggleClass(playBtnClassNames); 124 $line.off(events_mouse); 125 run = false; 126 }); 127 // Delegate is better! 128 $body.on(event_play, "#" + uniqueId + " .er-controls > .play", function () { 129 if (run) return false; 130 $(this).toggleClass(playBtnClassNames); 131 run = true; 132 setHover(); 133 var offset = $line.offset().left; 134 var spaceLeft = offset + getFirstLi($line).outerWidth(true) - initialOffset; 135 var timeLeft = currentTempo / currentSpazio * spaceLeft; 136 scrollContent(spaceLeft, timeLeft); 137 }); 138 139 var moving = false; 140 141 $body.on(event_next, "#" + uniqueId + " .er-controls > .next", function () { 142 if (run) { 143 $("#" + uniqueId + " .er-controls > .pause").toggleClass(playBtnClassNames); 144 run = false; 145 return; 146 } 147 if (moving) { 148 return false; 149 } 150 var space = getFirstLi($line).outerWidth(true); 151 moving = true; 152 $line.stop(true, true).animate({left: '-=' + space}, getTime(space), "linear", function () { 153 getFirstLi($line).appendTo($line); 154 $line.css("left", 0); 155 moving = false; 156 }); 157 158 }); 159 160 $body.on(event_prev, "#" + uniqueId + " .er-controls > .prev", function () { 161 if (run) { 162 $("#" + uniqueId + " .er-controls > .pause").toggleClass(playBtnClassNames); 163 run = false; 164 return; 165 } 166 if (moving) { 167 return false; 168 } 169 var space = $line.children("li:last").outerWidth(true); 170 $line.css("left", "-" + space + "px"); 171 $line.children("li:last").prependTo($line); 172 moving = true; 173 $line.stop(true, true).animate({left: '+=' + space}, getTime(space), "linear", function () { 174 moving = false; 175 }); 176 177 }); 178 } 179 180 }); 181};
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.