PageSourceSearch

https://brightvision.edu.pk/wp-content/plugins/vertical-news-scroller/js/i13_newsTickerV3.js?ver=1.0

js brightvision.edu.pk collected 2026-09-24 15:10:38 UTC 9,398 bytes, 270 lines download raw bytes

1/*
2  Vertical News Ticker v3 - i13 Web Solution
3  Lightweight, dependency-free (besides jQuery) vertical scroller.
4  Designed to be a reliable fallback when vTicker (v1) / vTickerV2 (v2)
5  run into edge cases on certain themes/browsers.
6
7  Usage:
8    jQuery('#news-container').vtickerv3({
9        speed: 1700,      // animation duration in ms
10        pause: 5000,      // delay between ticks in ms
11        height: 200,      // fixed height of the viewport (0 = auto, uses first item height)
12        direction: 'up',  // 'up' or 'down'
13        mousePause: true  // pause scrolling while mouse is over the widget
14    });
15
16  Public API (via data attribute):
17    jQuery('#news-container').data('vtickerv3').stop();
18    jQuery('#news-container').data('vtickerv3').start();
19    jQuery('#news-container').data('vtickerv3').setDirection('down');
20*/
21(function ($) {
22
23    $.fn.vtickerv3 = function (options) {
24
25        var settings = $.extend({
26            speed: 1700,
27            pause: 5000,
28            height: 0,
29            direction: 'up',
30            mousePause: true,
31            mode: 'tick',
32            scrollamount: 1,
33            delay: 60
34        }, options);
35
36        return this.each(function () {
37
38            var $wrap  = $(this);
39            var $list  = $wrap.children('ul').first();
40
41            if (!$list.length) {
42                return;
43            }
44
45            var $items = $list.children('li');
46
47            if ($items.length < 1) {
48                $wrap.css('visibility', 'visible');
49                return;
50            }
51
52            // ----------------------------------------------------------
53            // MODE: continuous (marquee replacement)
54            // Smooth pixel-by-pixel scroll, loops seamlessly, pauses on
55            // hover. Use this for s_type="classic" instead of <marquee>.
56            // ----------------------------------------------------------
57            if (settings.mode === 'continuous') {
58
59                var wrapHeight = settings.height > 0
60                    ? settings.height
61                    : $items.first().outerHeight(true);
62
63                if (!wrapHeight || wrapHeight <= 0) {
64                    wrapHeight = 150;
65                }
66
67                $wrap.css({
68                    overflow: 'hidden',
69                    position: 'relative',
70                    height: wrapHeight + 'px'
71                });
72
73                $list.css({
74                    margin: 0,
75                    padding: 0,
76                    position: 'relative',
77                    top: 0
78                });
79
80                // Duplicate items once so the scroll can loop seamlessly.
81                if (!$list.data('vtickerv3-cloned')) {
82                    $items.each(function () {
83                        $list.append($(this).clone(true));
84                    });
85                    $list.data('vtickerv3-cloned', true);
86                }
87
88                var contentHeight = $list.outerHeight() / 2;
89
90                // Mirror <marquee>'s scrolldelay/scrollamount semantics:
91                // every `delay` ms, move `scrollamount` px. Convert that
92                // into a px-per-millisecond rate for smooth rAF animation.
93                var delayMs       = Math.max(parseFloat(settings.delay) || 60, 1);
94                var amountPx      = Math.max(parseFloat(settings.scrollamount) || 1, 0.2);
95                var pxPerMs       = amountPx / delayMs;
96
97                var paused        = false;
98                var pos           = 0;
99                var dir           = (settings.direction === 'down') ? 'down' : 'up';
100                var rafId         = null;
101                var lastTs        = null;
102
103                function frame(ts) {
104                    if (lastTs === null) {
105                        lastTs = ts;
106                    }
107                    var elapsed = ts - lastTs;
108                    lastTs = ts;
109
110                    if (!paused) {
111                        var delta = pxPerMs * elapsed;
112
113                        if (dir === 'up') {
114                            pos -= delta;
115                            if (Math.abs(pos) >= contentHeight) {
116                                pos += contentHeight;
117                            }
118                        } else {
119                            pos += delta;
120                            if (pos >= contentHeight) {
121                                pos -= contentHeight;
122                            }
123                        }
124                        $list.css('transform', 'translateY(' + pos + 'px)');
125                    }
126                    rafId = requestAnimationFrame(frame);
127                }
128
129                if (settings.mousePause) {
130                    $wrap.on('mouseenter.vtickerv3', function () {
131                        paused = true;
132                    }).on('mouseleave.vtickerv3', function () {
133                        paused = false;
134                    });
135                }
136
137                $wrap.css('visibility', 'visible');
138
139                // Start at the bottom edge if scrolling "down" so content
140                // enters from above, matching marquee direction="down".
141                if (dir === 'down') {
142                    pos = -contentHeight;
143                    $list.css('transform', 'translateY(' + pos + 'px)');
144                }
145
146                rafId = requestAnimationFrame(frame);
147
148                $wrap.data('vtickerv3', {
149                    start: function () { paused = false; },
150                    stop: function () {
151                        paused = true;
152                        if (rafId) { cancelAnimationFrame(rafId); }
153                    },
154                    setDirection: function (d) {
155                        dir = (d === 'down') ? 'down' : 'up';
156                    }
157                });
158
159                return;
160            }
161
162            // ----------------------------------------------------------
163            // MODE: tick (default) - one item slides at a time
164            // ----------------------------------------------------------
165            if ($items.length < 2) {
166                $wrap.css('visibility', 'visible');
167                return;
168            }
169
170            // "height" is the overall visible box height (may show multiple
171            // items at once, like a normal vTicker). If not provided, fall
172            // back to a single item's natural height.
173            var naturalItemHeight = $items.first().outerHeight(true) || 50;
174            var boxHeight = settings.height > 0 ? settings.height : naturalItemHeight;
175
176            // Lock layout: container clips to boxHeight, items keep their
177            // natural height and stack normally inside it.
178            $wrap.css({
179                overflow: 'hidden',
180                position: 'relative',
181                height: boxHeight + 'px'
182            });
183
184            $list.css({
185                margin: 0,
186                padding: 0,
187                position: 'relative',
188                top: 0
189            });
190
191            $items.css({
192                margin: 0,
193                boxSizing: 'border-box'
194            });
195
196            var timer    = null;
197            var paused   = false;
198            var animating = false;
199            var direction = (settings.direction === 'down') ? 'down' : 'up';
200
201            function tick() {
202
203                if (paused || animating) {
204                    return;
205                }
206
207                animating = true;
208
209                if (direction === 'down') {
210
211                    var $last     = $list.children('li').last();
212                    var lastH     = $last.outerHeight(true);
213                    var $clone    = $last.clone(true);
214
215                    $list.prepend($clone);
216                    $list.css('margin-top', '-' + lastH + 'px');
217
218                    $list.animate({ marginTop: 0 }, settings.speed, function () {
219                        $list.children('li').last().remove();
220                        animating = false;
221                    });
222
223                } else {
224
225                    var firstH = $list.children('li').first().outerHeight(true);
226
227                    $list.animate({ marginTop: '-' + firstH + 'px' }, settings.speed, function () {
228                        $list.children('li').first().appendTo($list);
229                        $list.css('margin-top', 0);
230                        animating = false;
231                    });
232                }
233            }
234
235            function start() {
236                stop();
237                timer = setInterval(tick, settings.pause);
238            }
239
240            function stop() {
241                if (timer) {
242                    clearInterval(timer);
243                    timer = null;
244                }
245            }
246
247            if (settings.mousePause) {
248                $wrap.on('mouseenter.vtickerv3', function () {
249                    paused = true;
250                }).on('mouseleave.vtickerv3', function () {
251                    paused = false;
252                });
253            }
254
255            // Make visible (the PHP template hides the container until JS is ready)
256            $wrap.css('visibility', 'visible');
257
258            start();
259
260            $wrap.data('vtickerv3', {
261                start: start,
262                stop: stop,
263                setDirection: function (dir) {
264                    direction = (dir === 'down') ? 'down' : 'up';
265                }
266            });
267        });
268    };
269
270})(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.