PageSourceSearch

https://www.saltsmedilink.co.uk/Files/Templates/Designs/MedilinkCore/scripts/jquery.webticker.js

js saltsmedilink.co.uk collected 2026-10-08 22:55:27 UTC 13,132 bytes, 310 lines download raw bytes

1// JavaScript Document
2/*!
3 * webTicker 2.1.1
4 * Examples and documentation at: 
5 * http://jonmifsud.com/open-source/jquery/jquery-webticker/
6 * 2011 Jonathan Mifsud
7 * Version: 2.1.1 (23-MAY-2013)
8 * Dual licensed under the Creative Commons and DonationWare licenses:
9 * http://creativecommons.org/licenses/by-nc/3.0/
10 * https://github.com/jonmifsud/Web-Ticker/blob/master/licence.md
11 * Requires:
12 * jQuery v1.4.2 or later
13 * 
14 */
15(function ($) {
16
17    var cssTransitionsSupported = (function () {
18        var s = document.createElement('p').style,
19            v = ['ms', 'O', 'Moz', 'Webkit'];
20
21        if (s['transition'] == '') return true;
22        while (v.length)
23            if (v.pop() + 'Transition' in s)
24                return true;
25        return false;
26    })();
27
28    function scrollitems($strip, moveFirst) {
29        var settings = $strip.data('settings');
30        if (typeof moveFirst === 'undefined')
31            moveFirst = false;
32        if (moveFirst) {
33            moveFirstElement($strip);
34        }
35        var options = animationSettings($strip);
36        $strip.animate(options.css, options.time, "linear", function () {
37            $strip.css(settings.direction, '0');
38            scrollitems($strip, true);
39        });
40    }
41
42    function animationSettings($strip) {
43        var settings = $strip.data('settings');
44        var first = $strip.children().first();
45        var distance = Math.abs(-$strip.css(settings.direction).replace('px', '').replace('auto', '0') - first.outerWidth(true));
46        var settings = $strip.data('settings');
47        var timeToComplete = distance * 1000 / settings.speed;
48        var animationSettings = {};
49        animationSettings[settings.direction] = $strip.css(settings.direction).replace('px', '').replace('auto', '0') - distance;
50        return { 'css': animationSettings, 'time': timeToComplete };
51    }
52
53    function moveFirstElement($strip) {
54        var settings = $strip.data('settings');
55        $strip.css('transition-duration', '0s').css(settings.direction, '0');
56        var $first = $strip.children().first();
57        if ($first.hasClass('webticker-init'))
58            $first.remove();
59        else
60            $strip.children().last().after($first);
61    }
62
63    function css3Scroll($strip, moveFirst) {
64        if (typeof moveFirst === 'undefined')
65            moveFirst = false;
66        if (moveFirst) {
67            moveFirstElement($strip);
68        }
69        var options = animationSettings($strip);
70        var time = options.time / 1000;
71        time += 's';
72        $strip.css(options.css).css('-webkit-transition-duration', time);
73        $strip.css(options.css).css('transition-duration', time);
74    }
75
76    function updaterss(rssurl, type, $strip) {
77        var list;
78        $.get(rssurl, function (data) {
79            var $xml = $(data);
80            $xml.find("item").each(function () {
81                var $this = $(this),
82                    item = {
83                        title: $this.find("title").text(),
84                        link: $this.find("link").text()
85                    }
86                listItem = "<li><a href='" + item.link + "'>" + item.title + "</a></li>";
87                list += listItem;
88                //Do something with item here...
89            });
90            $strip.webTicker('update', list, type);
91        });
92    }
93
94    function initalize($strip) {
95        var settings = $strip.data('settings');
96
97        $strip.width('auto');
98
99        //Find the real width of all li elements
100        var stripWidth = 0;
101        $strip.children('li').each(function () {
102            stripWidth += $(this).outerWidth(true);
103        });
104
105        if (stripWidth < $strip.parent().width() || $strip.children().length == 1) {
106            //if duplicate items
107            if (settings.duplicate) {
108                //Check how many times to duplicate depending on width.
109                itemWidth = Math.max.apply(Math, $strip.children().map(function () { return $(this).width(); }).get());
110                while (stripWidth - itemWidth < $strip.parent().width() || $strip.children().length == 1) {
111                    var listItems = $strip.children().clone();
112                    $strip.append(listItems);
113                    stripWidth = 0;
114                    $strip.children('li').each(function () {
115                        stripWidth += $(this).outerWidth(true);
116                    });
117                    itemWidth = Math.max.apply(Math, $strip.children().map(function () { return $(this).width(); }).get());
118                }
119            } else {
120                //if fill with empty padding
121                var emptySpace = $strip.parent().width() - stripWidth;
122                emptySpace += $strip.find("li:first").width();
123                var height = $strip.find("li:first").height();
124
125                $strip.append('<li class="ticker-spacer" style="width:' + emptySpace + 'px;height:' + height + 'px;"></li>');
126            }
127        }
128        if (settings.startEmpty) {
129            var height = $strip.find("li:first").height();
130            $strip.prepend('<li class="webticker-init" style="width:' + $strip.parent().width() + 'px;height:' + height + 'px;"></li>');
131        }
132        //extra width to be able to move items without any jumps  $strip.find("li:first").width()  
133
134        stripWidth = 0;
135        $strip.children('li').each(function () {
136            stripWidth += $(this).outerWidth(true);
137        });
138        $strip.width(stripWidth + 200);
139        widthCompare = 0;
140        $strip.children('li').each(function () {
141            widthCompare += $(this).outerWidth(true);
142        });
143        //loop to find weather the items inside the list are actually bigger then the size of the whole list. Increments in 200px.
144        //only required when a single item is bigger then the whole list
145        while (widthCompare >= $strip.width()) {
146            $strip.width($strip.width() + 200);
147            widthCompare = 0;
148            $strip.children('li').each(function () {
149                widthCompare += $(this).outerWidth(true);
150            });
151        }
152    }
153
154    var methods = {
155        init: function (settings) { // THIS 
156            settings = jQuery.extend({
157                speed: 50, //pixels per second
158                direction: "left",
159                moving: true,
160                startEmpty: true,
161                duplicate: false,
162                rssurl: false,
163                hoverpause: true,
164                rssfrequency: 0,
165                updatetype: "reset"
166            }, settings);
167            //set data-ticker a unique ticker identifier if it does not exist
168            return this.each(function () {
169                jQuery(this).data('settings', settings);
170
171                var $strip = jQuery(this);
172                $strip.addClass("newsticker");
173                var $mask = $strip.wrap("<div class='mask'></div>");
174                $mask.after("<span class='tickeroverlay-left'>&nbsp;</span><span class='tickeroverlay-right'>&nbsp;</span>")
175                var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
176
177                initalize($strip);
178
179                if (settings.rssurl) {
180                    updaterss(settings.rssurl, settings.type, $strip);
181                    if (settings.rssfrequency > 0) {
182                        window.setInterval(function () { updaterss(settings.rssurl, settings.type, $strip); }, settings.rssfrequency * 1000 * 60);
183                    }
184                }
185
186                if (cssTransitionsSupported) {
187                    //fix for firefox not animating default transitions
188                    $strip.css('transition-duration', '0s').css(settings.direction, '0');
189                    css3Scroll($strip, false);
190                    $strip.on('transitionend webkitTransitionEnd oTransitionEnd otransitionend', function (event) {
191                        if (!$strip.is(event.target)) {
192                            return false;
193                        }
194                        css3Scroll($(this), true);
195                    });
196                } else {
197                    scrollitems($(this));
198                }
199
200                if (settings.hoverpause) {
201                    $strip.hover(function () {
202                        if (cssTransitionsSupported) {
203                            var currentPosition = $(this).css(settings.direction);
204                            $(this).css('transition-duration', '0s').css(settings.direction, currentPosition);
205                        } else
206                            jQuery(this).stop();
207                    },
208                    function () {
209                        if (jQuery(this).data('settings').moving) {
210                            if (cssTransitionsSupported) {
211                                css3Scroll($(this), false);
212                                // $(this).css("-webkit-animation-play-state", "running");
213                            } else {
214                                //usual continue stuff
215                                scrollitems($strip)
216                            }
217                        }
218                    });
219                }
220            });
221        },
222        stop: function () {
223            var settings = $(this).data('settings');
224            if (settings.moving) {
225                settings.moving = false;
226                return this.each(function () {
227                    if (cssTransitionsSupported) {
228                        var currentPosition = $(this).css(settings.direction);
229                        $(this).css('transition-duration', '0s').css(settings.direction, currentPosition);
230                    } else
231                        $(this).stop();
232                });
233            }
234        },
235        cont: function () {
236            var settings = $(this).data('settings')
237            if (!settings.moving) {
238                settings.moving = true;
239                return this.each(function () {
240                    if (cssTransitionsSupported) {
241                        css3Scroll($(this), false);
242                    } else {
243                        scrollitems($(this));
244                    }
245                });
246            }
247        },
248        update: function (list, type, insert, remove) {
249            type = type || "reset";
250            if (typeof insert === 'undefined')
251                insert = true;
252            if (typeof remove === 'undefined')
253                remove = false;
254            if (typeof list === 'string') {
255                list = $(list);
256            }
257            var $strip = $(this);
258            $strip.webTicker('stop');
259            var settings = $(this).data('settings');
260            if (type == 'reset') {
261                //this does a 'restart of the ticker'
262                $strip.html(list);
263                $strip.css(settings.direction, '0');
264                initalize($strip);
265            } else if (type == 'swap') {
266                // should the update be a 'hot-swap' or use replacement for IDs (in which case remove new ones)
267                $strip.children('li').addClass('old');
268                for (var i = 0; i < list.length; i++) {
269                    id = $(list[i]).data('update');
270                    match = $strip.find('[data-update="' + id + '"]');//should try find the id or data-attribute.
271                    if (match.length < 1) {
272                        if (insert) {
273                            //we need to move this item into the dom
274                            if ($strip.find('.ticker-spacer:first-child').length == 0 && $strip.find('.ticker-spacer').length > 0) {
275                                $strip.children('li.ticker-spacer').before(list[i]);
276                            }
277                            else {
278                                $strip.append(list[i]);
279                            }
280                        }
281                    } else $strip.find('[data-update="' + id + '"]').replaceWith(list[i]);;
282                };
283                $strip.children('li.webticker-init, li.ticker-spacer').removeClass('old');
284                if (remove)
285                    $strip.children('li').remove('.old');
286                stripWidth = 0;
287                $strip.children('li').each(function () {
288                    stripWidth += $(this).outerWidth(true);
289                });
290                $strip.width(stripWidth + 200);
291            }
292
293            $strip.webTicker('cont');
294        }
295    };
296
297    $.fn.webTicker = function (method) {
298
299        // Method calling logic
300        if (methods[method]) {
301            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
302        } else if (typeof method === 'object' || !method) {
303            return methods.init.apply(this, arguments);
304        } else {
305            $.error('Method ' + method + ' does not exist on jQuery.webTicker');
306        }
307
308    };
309
310})(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.