PageSourceSearch

https://www.altoprofessional.com/themes/site_themes/global/js/jquery.coda-slider-2.0.js

js altoprofessional.com collected 2026-10-01 12:28:45 UTC 9,601 bytes, 234 lines download raw bytes

1/*
2	jQuery Coda-Slider v2.0 - http://www.ndoherty.biz/coda-slider
3	Copyright (c) 2009 Niall Doherty
4	This plugin available for use in all personal or commercial projects under both MIT and GPL licenses.
5*/
6
7$(function(){
8	// Remove the coda-slider-no-js class from the body
9	$("body").removeClass("coda-slider-no-js");
10	// Preloader
11	$(".coda-slider").children('.panel').hide().end().prepend('<p class="loading">Loading...<br /><img src="images/ajax-loader.gif" alt="loading..." /></p>');
12});
13
14var sliderCount = 1;
15
16$.fn.codaSlider = function(settings) {
17
18	settings = $.extend({
19		autoHeight: true,
20		autoHeightEaseDuration: 1000,
21		autoHeightEaseFunction: "easeInOutExpo",
22		autoSlide: false,
23		autoSlideInterval: 7000,
24		autoSlideStopWhenClicked: true,
25		crossLinking: true,
26		dynamicArrows: true,
27		dynamicArrowLeftText: "&#171; left",
28		dynamicArrowRightText: "right &#187;",
29		dynamicTabs: true,
30		dynamicTabsAlign: "center",
31		dynamicTabsPosition: "top",
32		externalTriggerSelector: "a.xtrig",
33		firstPanelToLoad: 1,
34		panelTitleSelector: "h2.title",
35		slideEaseDuration: 1000,
36		slideEaseFunction: "easeInOutExpo"
37	}, settings);
38	
39	return this.each(function(){
40		
41		// Uncomment the line below to test your preloader
42		// alert("Testing preloader");
43		
44		var slider = $(this);
45		
46		// If we need arrows
47		if (settings.dynamicArrows) {
48			slider.parent().addClass("arrows");
49			slider.before('<div class="coda-nav-left" id="coda-nav-left-' + sliderCount + '"><a href="#">' + settings.dynamicArrowLeftText + '</a></div>');
50			slider.after('<div class="coda-nav-right" id="coda-nav-right-' + sliderCount + '"><a href="#">' + settings.dynamicArrowRightText + '</a></div>');
51		};
52		
53		var panelWidth = slider.find(".panel").width();
54		var panelCount = slider.find(".panel").size();
55		var panelContainerWidth = panelWidth*panelCount;
56		var navClicks = 0; // Used if autoSlideStopWhenClicked = true
57		
58		// Surround the collection of panel divs with a container div (wide enough for all panels to be lined up end-to-e
58nd)
59		$('.panel', slider).wrapAll('<div class="panel-container"></div>');
60		// Specify the width of the container div (wide enough for all panels to be lined up end-to-end)
61		$(".panel-container", slider).css({ width: panelContainerWidth });
62		
63		// Specify the current panel.
64		// If the loaded URL has a hash (cross-linking), we're going to use that hash to give the slider a specific starting position...
65		if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
66			var currentPanel = parseInt(location.hash.slice(1));
67			var offset = - (panelWidth*(currentPanel - 1));
68			$('.panel-container', slider).css({ marginLeft: offset });
69		// If that's not the case, check to see if we're supposed to load a panel other than Panel 1 initially...
70		} else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) { 
71			var currentPanel = settings.firstPanelToLoad;
72			var offset = - (panelWidth*(currentPanel - 1));
73			$('.panel-container', slider).css({ marginLeft: offset });
74		// Otherwise, we'll just set the current panel to 1...
75		} else { 
76			var currentPanel = 1;
77		};
78			
79		// Left arrow click
80		$("#coda-nav-left-" + sliderCount + " a").click(function(){
81			navClicks++;
82			if (currentPanel == 1) {
83				offset = - (panelWidth*(panelCount - 1));
84				alterPanelHeight(panelCount - 1);
85				currentPanel = panelCount;
86				slider.siblings('.coda-nav').find('a.current').removeClass('current').parents('ul').find('li:last a').addClass('current');
87			} else {
88				currentPanel -= 1;
89				alterPanelHeight(currentPanel - 1);
90				offset = - (panelWidth*(currentPanel - 1));
91				slider.siblings('.coda-nav').find('a.current').removeClass('current').parent().prev().find('a').addClass('current');
92			};
93			$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
94			if (settings.crossLinking) { location.hash = currentPanel }; // Change the URL hash (cross-linking)
95			return false;
96		});
97			
98		// Right arrow click
99		$('#coda-nav-right-' + sliderCount + ' a').click(function(){
100			navClicks++;
101			if (currentPanel == panelCount) {
102				offset = 0;
103				currentPanel = 1;
104				alterPanelHeight(0);
105				slider.siblings('.coda-nav').find('a.current').removeClass('current').parents('ul').find('a:eq(0)').addClass('current');
106			} else {
107				offset = - (panelWidth*currentPanel);
108				alterPanelHeight(currentPanel);
109				currentPanel += 1;
110				slider.siblings('.coda-nav').find('a.current').removeClass('current').parent().next().find('a').addClass('current');
111			};
112			$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
113			if (settings.crossLinking) { location.hash = currentPanel }; // Change the URL hash (cross-linking)
114			return false;
115		});
116		
117		// If we need a dynamic menu
118		if (settings.dynamicTabs) {
119			var dynamicTabs = '<div class="coda-nav" id="coda-nav-' + sliderCount + '"><ul></ul></div>';
120			switch (settings.dynamicTabsPosition) {
121				case "bottom":
122					slider.parent().append(dynamicTabs);
123					break;
124				default:
125					slider.parent().prepend(dynamicTabs);
126					break;
127			};
128			ul = $('#coda-nav-' + sliderCount + ' ul');
129			// Create the nav items
130			$('.panel', slider).each(function(n) {
131				ul.append('<li class="tab' + (n+1) + '"><a href="#' + (n+1) + '">' + $(this).find(settings.panelTitleSelector).text() + '</a></li>');												
132			});
133			navContainerWidth = slider.width() + slider.siblings('.coda-nav-left').width() + slider.siblings('.coda-nav-right').width();
134			ul.parent().css({ width: navContainerWidth });
135			switch (settings.dynamicTabsAlign) {
136				case "center":
137					ul.css({ width: ($("li", ul).width() + 2) * panelCount });
138					break;
139				case "right":
140					ul.css({ float: 'right' });
141					break;
142			};
143		};
144			
145		// If we need a tabbed nav
146		$('#coda-nav-' + sliderCount + ' a').each(function(z) {
147			// What happens when a nav link is clicked
148			$(this).bind("click", function() {
149				navClicks++;
150				$(this).addClass('current').parents('ul').find('a').not($(this)).removeClass('current');
151				offset = - (panelWidth*z);
152				alterPanelHeight(z);
153				currentPanel = z + 1;
154				$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
155				if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified
156			});
157		});
158		
159		// External triggers (anywhere on the page)
160		$(settings.externalTriggerSelector).each(function() {
161			// Make sure this only affects the targeted slider
162			if (sliderCount == parseInt($(this).attr("rel").slice(12))) {
163				$(this).bind("click", function() {
164					navClicks++;
165					targetPanel = parseInt($(this).attr("href").slice(1));
166					offset = - (panelWidth*(targetPanel - 1));
167					alterPanelHeight(targetPanel - 1);
168					currentPanel = targetPanel;
169					// Switch the current tab:
170					slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (targetPanel - 1) + ') a').addClass('current');
171					// Slide
172					$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
173					if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified
174				});
175			};
176		});
177			
178		// Specify which tab is initially set to "current". Depends on if the loaded URL had a hash or not (cross-linking).
179		if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) {
180			$("#coda-nav-" + sliderCount + " a:eq(" + (location.hash.slice(1) - 1) + ")").addClass("current");
181		// If there's no cross-linking, check to see if we're supposed to load a panel other than Panel 1 initially...
182		} else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) {
183			$("#coda-nav-" + sliderCount + " a:eq(" + (settings.firstPanelToLoad - 1) + ")").addClass("current");
184		// Otherwise we must be loading Panel 1, so make the first tab the current one.
185		} else {
186			$("#coda-nav-" + sliderCount + " a:eq(0)").addClass("current");
187		};
188		
189		// Set the height of the first panel
190		if (settings.autoHeight) {
191			panelHeight = $('.panel:eq(' + (currentPanel - 1) + ')', slider).height();
192			slider.css({ height: panelHeight });
193		};
194		
195		// Trigger autoSlide
196		if (settings.autoSlide) {
197			slider.ready(function() {
198				setTimeout(autoSlide,settings.autoSlideInterval);
199			});
200		};
201		
202		function alterPanelHeight(x) {
203			if (settings.autoHeight) {
204				panelHeight = $('.panel:eq(' + x + ')', slider).height()
205				slider.animate({ height: panelHeight }, settings.autoHeightEaseDuration, settings.autoHeightEaseFunction);
206			};
207		};
208		
209		function autoSlide() {
210			if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
211				if (currentPanel == panelCount) {
212					var offset = 0;
213					currentPanel = 1;
214				} else {
215					var offset = - (panelWidth*currentPanel);
216					currentPanel += 1;
217				};
218				alterPanelHeight(currentPanel - 1);
219				// Switch the current tab:
220				slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
221				// Slide:
222				$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
223				setTimeout(autoSlide,settings.autoSlideInterval);
224			};
225		};
226		
227		// Kill the preloader
228		$('.panel', slider).show().end().find("p.loading").remove();
229		slider.removeClass("preload");
230		
231		sliderCount++;
232		
233	});
234};

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.