PageSourceSearch

https://www.eldercarereview.com/jsweb/jquery.easy-ticker.js

js eldercarereview.com collected 2026-10-08 03:33:21 UTC 7,373 bytes, 274 lines download raw bytes

1/*
2 * jQuery - Easy Ticker plugin - v3.5.0
3 * https://www.aakashweb.com/
4 * Copyright 2022, Aakash Chakravarthy
5 * Released under the MIT License.
6 */
7
8;(function ($, window, document, undefined) {
9    
10    var name = "easyTicker",
11        defaults = {
12            direction: 'up',
13            easing: 'swing',
14            speed: 'slow',
15            interval: 2000,
16            height: 'auto',
17            visible: 0,
18            mousePause: true,
19            autoplay: true,
20            controls: {
21                up: '',
22                down: '',
23                toggle: '',
24                playText: 'Play',
25                stopText: 'Stop'
26            },
27            callbacks: {
28                before: false,
29                after: false,
30                finish: false
31            }
32        };
33
34    // Constructor
35    function EasyTicker(el, options) {
36        
37        var s = this;
38        
39        s.opts = $.extend({}, defaults, options);
40        s.elem = $(el);
41        s.targ = $(el).children(':first-child');
42        s.timer = 0;
43        s.moving = false;
44        
45        init();
46        start();
47        tabFocusHandle();
48        
49        if(s.opts.mousePause){
50            s.elem.on('mouseenter', function(){
51                s.timerTemp = s.timer;
52                stop();
53            }).on('mouseleave', function(){
54                if(s.timerTemp !== 0)
55                    start();
56            });
57        }
58        
59        $(s.opts.controls.up).on('click', function(e){
60            e.preventDefault();
61            moveDir('up');
62        });
63        
64        $(s.opts.controls.down).on('click', function(e){
65            e.preventDefault();
66            moveDir('down');
67        });
68        
69        $(s.opts.controls.toggle).on('click', function(e){
70            e.preventDefault();
71            if(s.timer == 0) start();
72            else stop();
73        });
74        
75        function init(){
76            
77            s.elem.children().css('margin', 0).children().css('margin', 0);
78            
79            s.elem.css({
80                position: 'relative',
81                height: s.opts.height,
82                overflow: 'hidden'
83            });
84            
85            s.targ.css({
86                'position': 'absolute',
87                'margin': 0
88            });
89            
90            adjustHeight(false);
91        
92        }
93        
94        function start(){
95
96            if(!s.opts.autoplay)
97                return;
98
99            startForce();
100
101        }
102        
103        function startForce(){
104
105            if(s.timer != 0)
106                return;
107
108            s.timer = setInterval(function(){
109                move(s.opts.direction);
110            }, s.opts.interval);
111
112            $(s.opts.controls.toggle).addClass('et-run').html(s.opts.controls.stopText);
113
114        }
115
116        function stop(){
117            clearInterval(s.timer);
118            s.timer = 0;
119            $(s.opts.controls.toggle).removeClass('et-run').html(s.opts.controls.playText);
120        }
121        
122        function move(dir){
123            var sel, eq, appType;
124
125            if(s.moving) return;
126
127            if(!s.elem.is(':visible')) return;
128
129            if(dir == 'up'){
130                sel = ':first-child';
131                eq = '-=';
132                appType = 'appendTo';
133            }else{
134                sel = ':last-child';
135                eq = '+=';
136                appType = 'prependTo';
137            }
138
139            var selChild = s.targ.children(sel);
140            var height = selChild.outerHeight();
141
142            if(typeof s.opts.callbacks.before === 'function'){
143                s.opts.callbacks.before.call(s, s.targ, selChild);
144            }
145
146            s.moving = true;
147
148            s.targ.stop(true, true).animate({
149                'top': eq + height + 'px'
150            }, s.opts.speed, s.opts.easing, function(){
151                
152                selChild.hide()[appType](s.targ).fadeIn();
153                s.targ.css('top', 0);
154                
155                adjustHeight(true);
156
157                s.moving = false;
158
159                if(typeof s.opts.callbacks.after === 'function'){
160                    s.opts.callbacks.after.call(s, s.targ, selChild);
161                }
162
163            });
164        }
165        
166        function moveDir(dir){
167            stop();
168            if(dir == 'up') move('up'); else move('down');
169            // start();
170        }
171        
172        function setFullHeight(){
173            var height = 0;
174            var tempDisplay = s.elem.css('display'); // Get the current el display value
175            
176            s.elem.css('display', 'block');
177            
178            s.targ.children().each(function(){
179                height += $(this).outerHeight();
180            });
181            
182            s.elem.css({
183                'display': tempDisplay,
184                'height': height
185            });
186        }
187        
188        function setVisibleHeight(animate){
189            var wrapHeight = 0;
190            var visibleItemClass = 'et-item-visible';
191
192            s.targ.children().removeClass(visibleItemClass);
193
194            s.targ.children(':lt(' + s.opts.visible + ')').each(function(){
195                wrapHeight += $(this).outerHeight();
196                $(this).addClass(visibleItemClass);
197            });
198            
199            if(animate){
200                s.elem.stop(true, true).animate({height: wrapHeight}, s.opts.speed, function(){
201                    finish();
202                });
203            }else{
204                s.elem.css('height', wrapHeight);
205            }
206        }
207        
208        function adjustHeight(animate){
209
210            if(s.opts.height == 'auto'){
211                if(s.opts.visible > 0){
212                    setVisibleHeight(animate);
213                }else{
214                    setFullHeight();
215                }
216            }
217
218            if(!animate){
219                finish();
220            }
221
222        }
223        
224        function tabFocusHandle(){
225
226            var hidden, visibilityChange;
227
228            if(typeof document.hidden !== 'undefined'){
229                hidden = 'hidden';
230                visibilityChange = 'visibilitychange';
231            }else if (typeof document.msHidden !== 'undefined'){
232                hidden = 'msHidden';
233                visibilityChange = 'msvisibilitychange';
234            }else if (typeof document.webkitHidden !== 'undefined'){
235                hidden = 'webkitHidden';
236                visibilityChange = 'webkitvisibilitychange';
237            }
238            
239            document.addEventListener(visibilityChange, function(){
240                if(document[hidden]){
241                    stop();
242                }else{
243                    start();
244                }
245            }, false);
246
247        }
248
249        function finish(){
250            if(typeof s.opts.callbacks.finish === 'function'){
251                s.opts.callbacks.finish.call(s, s.targ);
252            }
253        }
254
255        return {
256            up: function(){ moveDir('up'); },
257            down: function(){ moveDir('down'); },
258            start: startForce,
259            stop: stop,
260            options: s.opts
261        };
262        
263    }
264
265    // Attach the object to the DOM
266    $.fn[name] = function(options) {
267        return this.each(function () {
268            if (!$.data(this, name)) {
269                $.data(this, name, new EasyTicker(this, options));
270            }
271        });
272    };
273
274})(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.