PageSourceSearch

https://discovermartin.com/wp-content/themes/martincounty%202.0/js/jquery.webticker.js?ver=7.1.2

js discovermartin.com collected 2026-09-26 01:42:59 UTC 17,026 bytes, 508 lines download raw bytes

1/*!
2 * webTicker 2.2.0
3 * Examples and documentation at:
4 * http://jonmifsud.com/open-source/jquery/jquery-webticker/
5 * 2011 Jonathan Mifsud
6 * Version: 2.2.0 (15-FEB-2016)
7 * Dual licensed under the Creative Commons and DonationWare licenses:
8 * http://creativecommons.org/licenses/by-nc/3.0/
9 * https://github.com/jonmifsud/Web-Ticker/blob/master/licence.md
10 * Requires:
11 * jQuery v1.4.2 or later
12 *
13 */
14
15
16(function( $ ){
17
18
19	var cssTransitionsSupported = (function() {
20		var s = document.createElement('p').style,
21			v = ['ms','O','Moz','Webkit'];
22
23		if( s.transition === '' ){ return true; }
24		while( v.length ){
25			if( v.pop() + 'Transition' in s ){
26				return true;
27			}
28		}
29		return false;
30	})();
31
32	function getStripWidth($strip){
33		var stripWidth=0;
34		$strip.children('li').each(function(){
35			stripWidth += $(this).outerWidth( true );
36		});
37		return stripWidth;
38	}
39
40	function getItemWidth($strip){ 
41		return Math.max.apply(Math, $strip.children().map(function(){ return $(this).width(); }).get()); 
42	}
43
44	function animationSettings($strip){
45		var settings = $strip.data('settings') || { direction: 'left', speed: 50 };
46		var first = $strip.children().first();
47		var distance =  Math.abs(-$strip.css(settings.direction).replace('px','').replace('auto','0') - first.outerWidth(true));
48		var timeToComplete = distance * 1000 / settings.speed;
49		var animationSettings = {};
50		animationSettings[settings.direction] = $strip.css(settings.direction).replace('px','').replace('auto','0') - distance;
51		return {'css':animationSettings,'time':timeToComplete};
52	}
53
54	function moveFirstElement($strip){
55		var settings = $strip.data('settings') || { direction: 'left' };
56		$strip.css('transition-duration','0s').css(settings.direction, '0');
57		var $first = $strip.children().first();
58		if ($first.hasClass('webticker-init')){
59			$first.remove();
60		}
61		else{
62			$strip.children().last().after($first);
63		}
64
65	}
66
67	function scrollitems($strip,moveFirst){
68		var settings = $strip.data('settings') || { direction: 'left' };
69		if (typeof moveFirst === 'undefined'){
70			moveFirst = false;
71		}
72		if (moveFirst){
73			moveFirstElement($strip);
74		}
75		var options = animationSettings($strip);
76		$strip.animate(options.css, options.time, 'linear', function(){
77			$strip.css(settings.direction, '0');
78			scrollitems($strip,true);
79		});
80	}
81
82	function css3Scroll($strip,moveFirst){
83		if (typeof moveFirst === 'undefined'){
84			moveFirst = false;
85		}
86		if (moveFirst){
87			moveFirstElement($strip);
88		}
89		var options = animationSettings($strip);
90		var time = options.time/1000;
91		time += 's';
92		$strip.css(options.css).css('transition-duration',time);
93	}
94
95	function updaterss(rssurl,type,$strip){
96		var list = [];
97		$.get(rssurl, function(data) {
98			var $xml = $(data);
99			$xml.find('item').each(function() {
100				var $this = $(this),
101					item = {
102						title: $this.find('title').text(),
103						link: $this.find('link').text()
104				};
105				var listItem = '<li><a href="'+item.link+'"">'+item.title+'</a></li>';
106				list += listItem;
107				//Do something with item here...
108			});
109			$strip.webTicker('update', list, type);
110		});
111	}
112
113	function initialize($strip, init){
114		if ($strip.children('li').length < 1) {
115			if (window.console) {
116				// console.log('no items to initialize');
117			}
118			return false;
119		}
120		var settings = $strip.data('settings');
121		settings.duplicateLoops = settings.duplicateLoops || 0;
122
123		$strip.width('auto');
124
125		//Find the real width of all li elements
126		var stripWidth = 0;
127		$strip.children('li').each(function(){
128			stripWidth += $(this).outerWidth( true );
129		});
130
131		var height = $strip.find('li:first').height();
132		var itemWidth;
133		// if(stripWidth < $strip.parent().width() || $strip.children().length == 1){
134		//if duplicate items
135		if (settings.duplicate){
136			//Check how many times to duplicate depending on width.
137			itemWidth = getItemWidth($strip);
138			var duplicateLoops = 0;
139			while (stripWidth - itemWidth < $strip.parent().width() || $strip.children().length === 1 || duplicateLoops < settings.duplicateLoops){
140				var listItems = $strip.children().clone();
141				$strip.append(listItems);
142				stripWidth = 0;
143				stripWidth = getStripWidth($strip);
144				itemWidth = getItemWidth($strip);
145				duplicateLoops++;
146			}
147			settings.duplicateLoops = duplicateLoops;
148		}else {
149			//if fill with empty padding
150			var emptySpace = $strip.parent().width() - stripWidth;
151			emptySpace += $strip.find('li:first').width();
152
153			// $strip.append('<li class="ticker-spacer" style="width:'+emptySpace+'px;height:'+height+'px;"></li>');
154			if ($strip.find('.ticker-spacer').length > 0){
155				// console.log('test');
156				$strip.find('.ticker-spacer').width(emptySpace);
157			}
158			else{
159				// console.log('test2');
160				$strip.append('<li class="ticker-spacer" style="float: '+settings.direction+';width:'+emptySpace+'px;height:'+height+'px;"></li>');
161			}
162		// }
163		}
164
165		if (settings.startEmpty && init){
166			$strip.prepend('<li class="webticker-init" style="float: '+settings.direction+';width:'+$strip.parent().width()+'px;height:'+height+'px;"></li>');
167		}
168		//extra width to be able to move items without any jumps	$strip.find("li:first").width()
169
170		stripWidth = 0;
171		stripWidth = getStripWidth($strip);
172		$strip.width(stripWidth+200);
173		var widthCompare = 0;
174		widthCompare = getStripWidth($strip);
175		//loop to find weather the items inside the list are actually bigger then the size of the whole list. Increments in 200px.
176		//only required when a single item is bigger then the whole list
177		while (widthCompare >= $strip.width()){
178			$strip.width($strip.width()+200);
179			widthCompare = 0;
180			widthCompare = getStripWidth($strip);
181		}
182		return true;
183	}
184
185
186  var methods = {
187	init : function( settings ) { // THIS
188		settings = jQuery.extend({
189			speed: 50, //pixels per second
190			direction: 'left',
191			moving: true,
192			startEmpty: true,
193			duplicate: false,
194			rssurl: false,
195			hoverpause: true,
196			rssfrequency: 0,
197			updatetype: 'reset',
198			transition: 'linear',
199			height: '42px',
200			maskleft: '', // maskleft and maskright require a width setting in your css to work
201			maskright: '',
202			maskwidth: 0
203		}, settings);
204		//set data-ticker a unique ticker identifier if it does not exist
205		return this.each(function(){
206			jQuery(this).data('settings',settings);
207
208				var $strip = jQuery(this);
209				var $mask = $strip.wrap('<div class="mask"></div>');
210				$mask.after('<span class="tickeroverlay-left">&nbsp;</span><span class="tickeroverlay-right">&nbsp;</span>');
211				var $tickercontainer = $strip.parent().wrap('<div class="tickercontainer"></div>');
212				var resizeEvt; 
213				$(window).resize(function() {
214					clearTimeout(resizeEvt);
215					resizeEvt = setTimeout(function() {
216							console.log('window was resized');
217							initialize($strip,false);
218					}, 500);
219				});
220
221				//adding required css rules
222				
223				$strip.children('li').css('white-space','nowrap');
224				$strip.children('li').css('float',settings.direction);
225				$strip.children('li').css('padding','0');
226				$strip.children('li').css('line-height',settings.height);
227
228				$mask.css('position','relative');
229				$mask.css('overflow','hidden');
230
231				$strip.closest('.tickercontainer').css('height', settings.height);
232				$strip.closest('.tickercontainer').css('overflow', 'hidden');
233
234				$strip.css('float',settings.direction);
235				$strip.css('position','relative');
236				$strip.css('font', 'bold 13px Verdana');
237				$strip.css('list-style-type', 'none');
238				$strip.css('margin', '0');
239				$strip.css('padding', '0');
240
241				if ((settings.maskleft !== '') && (settings.maskright !== '')){
242					var backgroundimage='url("'+settings.maskleft+'")';
243					$tickercontainer.find('.tickeroverlay-left').css('background-image',backgroundimage);
244					$tickercontainer.find('.tickeroverlay-left').css('display','block');
245					$tickercontainer.find('.tickeroverlay-left').css('pointer-events','none');
246					$tickercontainer.find('.tickeroverlay-left').css('position','absolute');
247					$tickercontainer.find('.tickeroverlay-left').css('z-index','30');
248					$tickercontainer.find('.tickeroverlay-left').css('height',settings.height);
249					$tickercontainer.find('.tickeroverlay-left').css('width',settings.maskwidth);
250					$tickercontainer.find('.tickeroverlay-left').css('top','0');
251					$tickercontainer.find('.tickeroverlay-left').css('left','-2px');
252
253					backgroundimage='url("'+settings.maskright+'")';
254					$tickercontainer.find('.tickeroverlay-right').css('background-image',backgroundimage);
255					$tickercontainer.find('.tickeroverlay-right').css('display','block');
256					$tickercontainer.find('.tickeroverlay-right').css('pointer-events','none');
257					$tickercontainer.find('.tickeroverlay-right').css('position','absolute');
258					$tickercontainer.find('.tickeroverlay-right').css('z-index','30');
259					$tickercontainer.find('.tickeroverlay-right').css('height',settings.height);
260					$tickercontainer.find('.tickeroverlay-right').css('width',settings.maskwidth);
261					$tickercontainer.find('.tickeroverlay-right').css('top','0');
262					$tickercontainer.find('.tickeroverlay-right').css('right','-2px');
263				}
264				else{
265					$tickercontainer.find('.tickeroverlay-left').css('display','none');
266					$tickercontainer.find('.tickeroverlay-right').css('display','none');
267				}
268
269				//adding the 'last' class will help for future duplicate functions
270				$strip.children('li').last().addClass('last'); 
271				var started = initialize($strip,true);
272
273				if (settings.rssurl){
274					updaterss(settings.rssurl,settings.type,$strip);
275					if (settings.rssfrequency>0){
276						window.setInterval(function(){updaterss(settings.rssurl,settings.type,$strip);},settings.rssfrequency*1000*60);
277					}
278				}
279
280				if (cssTransitionsSupported){
281					//fix for firefox not animating default transitions
282					$strip.css('transition-timing-function',settings.transition);
283					$strip.css('transition-duration','0s').css(settings.direction, '0');
284
285
286					if (started){
287						//if list has items and set up start scrolling
288						css3Scroll($strip,false);
289					}
290					//started or not still bind on the transition end event so it works after update
291					$strip.on('transitionend webkitTransitionEnd oTransitionEnd otransitionend', function(event) {
292						if (!$strip.is(event.target)) {
293							return false;
294						}
295						css3Scroll($(this),true);
296					});
297				} else {
298					if (started){
299						//if list has items and set up start scrolling
300						scrollitems($(this));
301					}
302				}
303
304				if (settings.hoverpause){
305					$strip.hover(function(){
306						if (cssTransitionsSupported){
307							var currentPosition = $(this).css(settings.direction);
308							$(this).css('transition-duration','0s').css(settings.direction,currentPosition);
309						} else{
310							jQuery(this).stop();
311						}
312					},
313					function(){
314						if (jQuery(this).data('settings').moving){
315							if (cssTransitionsSupported){
316								css3Scroll($(this),false);
317								// $(this).css("-webkit-animation-play-state", "running");
318							} else {
319								//usual continue stuff
320								scrollitems($strip);
321							}
322						}
323					});
324				}
325		});
326	},
327	stop : function( ) {
328		var settings = $(this).data('settings');
329		if (settings.moving){
330			settings.moving = false;
331			return this.each(function(){
332				if (cssTransitionsSupported){
333					var currentPosition = $(this).css(settings.direction);
334					$(this).css('transition-duration','0s').css(settings.direction,currentPosition);
335				} else{
336					$(this).stop();
337				}
338			});
339		}
340	},
341	cont : function( ) {
342		var settings = $(this).data('settings');
343		if (!settings.moving){
344			settings.moving = true;
345			return this.each(function(){
346				if (cssTransitionsSupported){
347					css3Scroll($(this),false);
348				} else {
349					scrollitems($(this));
350				}
351			});
352		}
353	},
354	transition : function(transition){
355		var $strip = $(this);
356		if (cssTransitionsSupported){
357			//fix for firefox not animating default transitions
358			$strip.css('transition-timing-function',transition);
359		}
360},
361	update : function( list, type, insert, remove) {
362		type = type || 'reset';
363		if (typeof insert === 'undefined'){
364			insert = true;
365		}
366		if (typeof remove === 'undefined'){
367			remove = false;
368		}
369		if( typeof list === 'string' ) {
370			list = $(list);
371		}
372		var $strip = $(this);
373		$strip.webTicker('stop');
374		var settings = $(this).data('settings');
375
376		if (type === 'reset'){
377			//this does a 'restart of the ticker'
378			$strip.html(list);
379			initialize($strip,true);
380		} else if (type === 'swap'){
381			var id;
382			var match;
383			var $listItem;
384			var stripWidth;
385			if (window.console) {
386				// console.log('trying to update');
387			}
388			if ($strip.children('li').length < 1){
389				//no <li> items found. Treat as new
390				$strip.html(list);
391				$strip.css(settings.direction, '0');
392				initialize($strip,true);
393			} 
394			else if (settings.duplicate === true)
395			{ 
396				// should the update be a 'hot-swap' or use replacement for IDs (in which case remove new ones)
397				$strip.children('li').addClass('old');
398				for (var i = list.length - 1; i >= 0; i--) {
399					id = $(list[i]).data('update');
400					match = $strip.find('[data-update="'+id+'"]');//should try find the id or data-attribute.
401					if (match.length < 1){
402						if (insert){
403							//we need to move this item into the dom
404							if ($strip.find('.ticker-spacer:first-child').length === 0 && $strip.find('.ticker-spacer').length > 0){
405								$strip.children('li.ticker-spacer').before(list[i]);
406							}
407							else {
408								//check for last class ...
409								//$strip.append(list[i]));
410								$listItem = $(list[i]);
411								if(i===list.length-1)
412								{
413									$listItem.addClass('last');
414								}
415								$strip.find('last').after($listItem);
416								$strip.find('last').removeClass('last');
417							}
418						}
419					} else{ 
420					$strip.find('[data-update="'+id+'"]').replaceWith(list[i]);
421					}
422				}
423				$strip.children('li.webticker-init, li.ticker-spacer').removeClass('old');
424				if (remove){
425					$strip.children('li').remove('.old');
426				}
427				stripWidth = 0;
428				stripWidth = getStripWidth($strip);
429				$strip.width(stripWidth+200);
430
431				//resetting $strip so that duplication works according to new width
432				
433				if ($strip.find('li.webticker-init').length < 1){ // checks if the strip's width is populated and handles the update accordingly
434					settings.startEmpty=false;
435				}
436				$strip.html(list);
437				//setting the css rules
438				$strip.children('li').css('white-space','nowrap');
439				$strip.children('li').css('float',settings.direction);
440				$strip.children('li').css('padding','0px');
441				$strip.children('li').css('line-height',settings.height);
442				initialize($strip,true);
443			}
444			else 
445			{ 
446				// should the update be a 'hot-swap' or use replacement for IDs (in which case remove new ones)
447				$strip.children('li').addClass('old');
448				for (var x = 0 ; x < list.length; x++) {
449					id = $(list[x]).data('update');
450					match = $strip.find('[data-update="'+id+'"]');//should try find the id or data-attribute.
451					if (match.length < 1){
452						if (insert){
453							//we need to move this item into the dom
454							if ($strip.find('.ticker-spacer:first-child').length === 0 && $strip.find('.ticker-spacer').length > 0){
455								$strip.children('li.ticker-spacer').before(list[x]);
456							}
457							else {
458								//check for last class ...
459								//$strip.append(list[i]));
460								$listItem = $(list[x]);
461								if(x===list.length-1)
462								{
463									$listItem.addClass('last');
464								}
465								$strip.find('.old.last').after($listItem);
466								$strip.find('.old.last').removeClass('last');
467							}
468						}
469					} else {
470					$strip.find('[data-update="'+id+'"]').replaceWith(list[x]);
471					}
472				}
473				$strip.children('li.webticker-init, li.ticker-spacer').removeClass('old');
474
475				//setting the css rules
476				$strip.children('li').css('white-space','nowrap');
477				$strip.children('li').css('float',settings.direction);
478				$strip.children('li').css('padding','0px');
479				$strip.children('li').css('line-height',settings.height);
480
481				if (remove){
482					$strip.children('li').remove('.old');
483				}
484				stripWidth = 0;
485				stripWidth = getStripWidth($strip);
486				$strip.width(stripWidth+200);
487
488			}
489		}
490
491		$strip.webTicker('cont');
492	}
493  };
494
495  $.fn.webTicker = function( method ) {
496
497	// Method calling logic
498	if ( methods[method] ) {
499	  return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
500	} else if ( typeof method === 'object' || ! method ) {
501	  return methods.init.apply( this, arguments );
502	} else {
503	  $.error( 'Method ' +  method + ' does not exist on jQuery.webTicker' );
504	}
505
506  };
507
508})( 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.