1jQuery.fn.endlessRiver = function (settings) { 2 // Settings before everything else 3 settings = jQuery.extend({ 4 speed: 100, 5 pause: !0, 6 buttons: !1 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 = !0; 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 // elimina cloni se ci sono - Serve in caso io aggiorni dinamicamente il contenuto 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 var fill = function () { 57 lineWidth = 1; 58 $line.append($liElements.clone(!0).addClass(clonesClassName)); 59 $line.children("li").each(function (i) { 60 lineWidth += $(this, i).outerWidth(!0); 61 // outerWidth con argomento !0 ritorna larghezza compresi margini 62 }); 63 }; 64 65 var tickerOuterWidth = $tickerContainer.outerWidth(!0); 66 while (lineWidth < tickerOuterWidth) { 67 fill(); 68 } 69 $line.width(lineWidth); 70 $line.height($line.parent().height()); 71 72 function scrollContent(space, time) { 73 $line.animate({left: '-=' + space}, time, "linear", function () { 74 getFirstLi($line).appendTo($line); 75 $line.css("left", 0); 76 currentSpazio = getFirstLi($line).outerWidth(!0); 77 currentTempo = time / space * currentSpazio; 78 if (run) { 79 scrollContent(currentSpazio, currentTempo); 80 } 81 }); 82 } 83 84 //BOOT 85 currentSpazio = getFirstLi($line).outerWidth(!0); 86 // Il tempo è in millisecondi, quindi moltiplico per mille 87 currentTempo = currentSpazio / settings.speed * 1000; 88 scrollContent(currentSpazio, currentTempo); 89 90 function setHover() { 91 $line.off(events_mouse); 92 $line.hover(pause, resume); 93 } 94 95 function pause() { 96 $("#" + uniqueId + " .er-controls > .pause").toggleClass(playBtnClassNames); 97 run = !1; 98 $line.stop(); 99 } 100 101 function resume() { 102 $("#" + uniqueId + " .er-controls > .play").toggleClass(playBtnClassNames); 103 run = !0; 104 var offset = $line.offset().left; 105 var spaceLeft = offset + getFirstLi($line).outerWidth(!0) - initialOffset; 106 var timeLeft = currentTempo / currentSpazio * spaceLeft; 107 scrollContent(spaceLeft, timeLeft); 108 } 109 110 if (settings.pause) { 111 setHover(); 112 } 113 114 if (settings.buttons) { 115 $buttons.insertAfter($tickerContainer); 116 // Delegate is better! 117 $body.on(event_pause, "#" + uniqueId + " .er-control
117s > .pause", function () { 118 if (!run) return !1; 119 $(this).toggleClass(playBtnClassNames); 120 $line.off(events_mouse); 121 run = !1; 122 }); 123 // Delegate is better! 124 $body.on(event_play, "#" + uniqueId + " .er-controls > .play", function () { 125 if (run) return !1; 126 $(this).toggleClass(playBtnClassNames); 127 run = !0; 128 setHover(); 129 var offset = $line.offset().left; 130 var spaceLeft = offset + getFirstLi($line).outerWidth(!0) - initialOffset; 131 var timeLeft = currentTempo / currentSpazio * spaceLeft; 132 scrollContent(spaceLeft, timeLeft); 133 }); 134 135 var moving = !1; 136 137 $body.on(event_next, "#" + uniqueId + " .er-controls > .next", function () { 138 if (run) { 139 $("#" + uniqueId + " .er-controls > .pause").toggleClass(playBtnClassNames); 140 run = !1; 141 return; 142 } 143 if (moving) { 144 return !1; 145 } 146 var space = getFirstLi($line).outerWidth(!0); 147 moving = !0; 148 $line.stop(!0, !0).animate({left: '-=' + space}, getTime(space), "linear", function () { 149 getFirstLi($line).appendTo($line); 150 $line.css("left", 0); 151 moving = !1; 152 }); 153 154 }); 155 156 $body.on(event_prev, "#" + uniqueId + " .er-controls > .prev", function () { 157 if (run) { 158 $("#" + uniqueId + " .er-controls > .pause").toggleClass(playBtnClassNames); 159 run = !1; 160 return; 161 } 162 if (moving) { 163 return !1; 164 } 165 var space = $line.children("li:last").outerWidth(!0); 166 $line.css("left", "-" + space + "px"); 167 $line.children("li:last").prependTo($line); 168 moving = !0; 169 $line.stop(!0, !0).animate({left: '+=' + space}, getTime(space), "linear", function () { 170 moving = !1; 171 }); 172 173 }); 174 } 175 176 }); 177};
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.