PageSourceSearch

https://northernsentinel.com/wp-content/themes/2024-cmg/media/js/vendors/jquery.contentcarousel.js?1773885978

js northernsentinel.com collected 2026-09-25 14:06:40 UTC 8,794 bytes, 259 lines download raw bytes

1(function($) {
2	var	aux		= {
3			// navigates left / right
4			navigate	: function( dir, $el, $wrapper, opts, cache ) {
5				
6				var scroll		= opts.scroll,
7					factor		= 1,
8					idxClicked	= 0;
9					
10				if( cache.expanded ) {
11					scroll		= 1; // scroll is always 1 in full mode
12					factor		= 3; // the width of the expanded item will be 3 times bigger than 1 collapsed item	
13					idxClicked	= cache.idxClicked; // the index of the clicked item
14				}
15				
16				// clone the elements on the right / left and append / prepend them according to dir and scroll
17				if( dir === 1 ) {
18					$wrapper.find('div.ca-item:lt(' + scroll + ')').each(function(i) {
19						$(this).clone(true).css( 'left', ( cache.totalItems - idxClicked + i ) * cache.itemW * factor + 'px' ).appendTo( $wrapper );
20					});
21				}
22				else {
23					var $first	= $wrapper.children().eq(0);
24					
25					$wrapper.find('div.ca-item:gt(' + ( cache.totalItems  - 1 - scroll ) + ')').each(function(i) {
26						// insert before $first so they stay in the right order
27						$(this).clone(true).css( 'left', - ( scroll - i + idxClicked ) * cache.itemW * factor + 'px' ).insertBefore( $first );
28					});
29				}
30				
31				// animate the left of each item
32				// the calculations are dependent on dir and on the cache.expanded value
33				$wrapper.find('div.ca-item').each(function(i) {
34					var $item	= $(this);
35					$item.stop().animate({
36						left	:  ( dir === 1 ) ? '-=' + ( cache.itemW * factor * scroll ) + 'px' : '+=' + ( cache.itemW * factor * scroll ) + 'px'
37					}, opts.sliderSpeed, opts.sliderEasing, function() {
38						if( ( dir === 1 && $item.position().left < - idxClicked * cache.itemW * factor ) || ( dir === -1 && $item.position().left > ( ( cache.totalItems - 1 - idxClicked ) * cache.itemW * factor ) ) ) {
39							// remove the item that was cloned
40							$item.remove();
41						}						
42						cache.isAnimating	= false;
43					});
44				});
45				
46			},
47			// opens an item (animation) -> opens all the others
48			openItem	: function( $wrapper, $item, opts, cache ) {
49				cache.idxClicked	= $item.index();
50				// the item's position (1, 2, or 3) on the viewport (the visible items) 
51				cache.winpos		= aux.getWinPos( $item.position().left, cache );
52				$wrapper.find('div.ca-item').not( $item ).hide();
53				$item.find('div.ca-content-wrapper').css( 'left', cache.itemW + 'px' ).stop().animate({
54					width	: cache.itemW * 2 + 'px',
55					left	: cache.itemW + 'px'
56				}, opts.itemSpeed, opts.itemEasing)
57				.end()
58				.stop()
59				.animate({
60					left	: '0px'
61				}, opts.itemSpeed, opts.itemEasing, function() {
62					cache.isAnimating	= false;
63					cache.expanded		= true;
64					
65					aux.openItems( $wrapper, $item, opts, cache );
66				});
67						
68			},
69			// opens all the items
70			openItems	: function( $wrapper, $openedItem, opts, cache ) {
71				var openedIdx	= $openedItem.index();
72				
73				$wrapper.find('div.ca-item').each(function(i) {
74					var $item	= $(this),
75						idx		= $item.index();
76					
77					if( idx !== openedIdx ) {
78						$item.css( 'left', - ( openedIdx - idx ) * ( cache.itemW * 3 ) + 'px' ).show().find('div.ca-content-wrapper').css({
79							left	: cache.itemW + 'px',
80							width	: cache.itemW * 2 + 'px'
81						});
82						
83						// hide more link
84						aux.toggleMore( $item, false );
85					}
86				});
87			},
88			// show / hide the item's more button
89			toggleMore	: function( $item, show ) {
90				( show ) ? $item.find('a.ca-more').show() : $item.find('a.ca-more').hide();	
91			},
92			// close all the items
93			// the current one is animated
94			closeItems	: function( $wrapper, $openedItem, opts, cache ) {
95				var openedIdx	= $openedItem.index();
96				
97				$openedItem.find('div.ca-content-wrapper').stop().animate({
98					width	: '0px'
99				}, opts.itemSpeed, opts.itemEasing)
100				.end()
101				.stop()
102				.animate({
103					left	: cache.itemW * ( cache.winpos - 1 ) + 'px'
104				}, opts.itemSpeed, opts.itemEasing, function() {
105					cache.isAnimating	= false;
106					cache.expanded		= false;
107				});
108				
109				// show more link
110				aux.toggleMore( $openedItem, true );
111				
112				$wrapper.find('div.ca-item').each(function(i) {
113					var $item	= $(this),
114						idx		= $item.index();
115					
116					if( idx !== openedIdx ) {
117						$item.find('div.ca-content-wrapper').css({
118							width	: '0px'
119						})
120						.end()
121						.css( 'left', ( ( cache.winpos - 1 ) - ( openedIdx - idx ) ) * cache.itemW + 'px' )
122						.show();
123						
124						// show more link
125						aux.toggleMore( $item, true );
126					}
127				});
128			},
129			// gets the item's position (1, 2, or 3) on the viewport (the visible items)
130			// val is the left of the item
131			getWinPos	: function( val, cache ) {
132				switch( val ) {
133					case 0 					: return 1; break;
134					case cache.itemW 		: return 2; break;
135					case cache.itemW * 2 	: return 3; break;
136				}
137			}
138		},
139		methods = {
140			init 		: function( options ) {
141				
142				if( this.length ) {
143					
144					var settings = {
145						sliderSpeed		: 500,			// speed for the sliding animation
146						sliderEasing	: 'easeOutExpo',// easing for the sliding animation
147						itemSpeed		: 500,			// speed for the item animation (open / close)
148						itemEasing		: 'easeOutExpo',// easing for the item animation (open / close)
149						scroll			: 1				// number of items to scroll at a time
150					};
151					
152					return this.each(function() {
153						
154						// if options exist, lets merge them with our default settings
155						if ( options ) {
156							$.extend( settings, options );
157						}
158						
159						var $el 			= $(this),
160							$wrapper		= $el.find('div.ca-wrapper'),
161							$items			= $wrapper.children('div.ca-item'),
162							cache			= {};
163						
164						// save the with of one item	
165						cache.itemW			= $items.width();
166						// save the number of total items
167						cache.totalItems	= $items.length;
168						
169						// add navigation buttons
170						if( cache.totalItems > 3 )	
171							$el.prepend('<div class="ca-nav"><span class="ca-nav-prev">Previous</span><span class="ca-nav-next">Next</span></div>')	
172						
173						// control the scroll value
174						if( settings.scroll < 1 )
175							settings.scroll = 1;
176						else if( settings.scroll > 3 )
177							settings.scroll = 3;	
178						
179						var $navPrev		= $el.find('span.ca-nav-prev'),
180							$navNext		= $el.find('span.ca-nav-next');
181						
182						// hide the items except the first 3
183						$wrapper.css( 'overflow', 'hidden' );
184						
185						// the items will have position absolute 
186						// calculate the left of each item
187						$items.each(function(i) {
188							$(this).css({
189								position	: 'absolute',
190								left		: i * cache.itemW + 'px'
191							});
192						});
193						
194						// click to open the item(s)
195						//$el.find('a.ca-more').live('click.contentcarousel', function( event ) {
196						$el.on('click.contentcarousel', 'a.ca-more', function( event ) {
197							if( cache.isAnimating ) return false;
198							cache.isAnimating	= true;
199							$(this).hide();
200							var $item	= $(this).closest('div.ca-item');
201							aux.openItem( $wrapper, $item, settings, cache );
202							return false;
203						});
204						
205						// click to close the item(s)
206						//$el.find('a.ca-close').live('click.contentcarousel', function( event ) {
207						$el.on('click.contentcarousel', 'a.ca-close', function( event ) {
208							if( cache.isAnimating ) return false;
209							cache.isAnimating	= true;
210							var $item	= $(this).closest('div.ca-item');
211							aux.closeItems( $wrapper, $item, settings, cache );
212							return false;
213						});
214						
215						// navigate left
216						$navPrev.bind('click.contentcarousel', function( event ) {
217							if( cache.isAnimating ) return false;
218							cache.isAnimating	= true;
219							aux.navigate( -1, $el, $wrapper, settings, cache );
220						});
221						
222						// navigate right
223						$navNext.bind('click.contentcarousel', function( event ) {
224							if( cache.isAnimating ) return false;
225							cache.isAnimating	= true;
226							aux.navigate( 1, $el, $wrapper, settings, cache );
227						});
228						
229						// adds events to the mouse
230						//$el.bind('mousewheel.contentcarousel', function(e, delta) {
231							//if(delta > 0) {
232								//if( cache.isAnimating ) return false;
233								//cache.isAnimating	= true;
234								//aux.navigate( -1, $el, $wrapper, settings, cache );
235							//}	
236							//else {
237								//if( cache.isAnimating ) return false;
238								//cache.isAnimating	= true;
239								//aux.navigate( 1, $el, $wrapper, settings, cache );
240							//}	
241							//return false;
242						//});
243						
244					});
245				}
246			}
247		};
248	
249	$.fn.contentcarousel = function(method) {
250		if ( methods[method] ) {
251			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
252		} else if ( typeof method === 'object' || ! method ) {
253			return methods.init.apply( this, arguments );
254		} else {
255			$.error( 'Method ' +  method + ' does not exist on jQuery.contentcarousel' );
256		}
257	};
258	
259})(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.