PageSourceSearch

https://teenchallenge.org.uk/components/com_roksprocket/layouts/tabs/themes/default/tabs.js

js teenchallenge.org.uk collected 2026-10-10 02:08:42 UTC 9,187 bytes, 285 lines download raw bytes

1/*!
2 * @version   $Id: tabs.js 10889 2013-05-30 07:48:35Z btowles $
3 * @author    RocketTheme http://www.rockettheme.com
4 * @copyright Copyright (C) 2007 - 2015 RocketTheme, LLC
5 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
6 */
7((function(){
8	if (typeof this.RokSprocket == 'undefined') this.RokSprocket = {};
9	else Object.merge(this.RokSprocket, {Tabs: null});
10
11	var Tabs = new Class({
12
13		Implements: [Options, Events],
14
15		options: {
16			settings: {}
17		},
18
19		initialize: function(options){
20			this.setOptions(options);
21
22			this.tabs = document.getElements('[data-tabs]');
23			this.settings = {};
24			this.timers = {};
25			this.statuses = {};
26		},
27
28		attach: function(tab, settings){
29			tab = typeOf(tab) == 'number' ?
30					document.getElements('[data-tabs=' + this.getID(tab) + ']')
31					:
32					tab;
33
34			settings = typeOf(settings) == 'string' ? JSON.decode(settings) : settings;
35			var containers = (tab ? new Elements([tab]).flatten() : this.tabs);
36
37			containers.each(function(container){
38				container.store('roksprocket:tabs:attached', true);
39
40				this.setSettings(container, settings, 'restore');
41
42				var relay = {
43					mouseenter: container.retrieve('roksprocket:tabs:mouseenter', function(event){
44						this.stopTimer.call(this, container);
45						this.pause.call(this, container);
46					}.bind(this)),
47
48					mouseleave: container.retrieve('roksprocket:tabs:mouseleave', function(event){
49						this.resume.call(this, container);
50						this.startTimer.call(this, container);
51					}.bind(this)),
52
53					navigation: container.retrieve('roksprocket:tabs:relay', function(event, tab){
54						this.toTab.call(this, event, container, tab);
55					}.bind(this)),
56
57					next: container.retrieve('roksprocket:tabs:next', function(event, element){
58						this.direction.call(this, event, container, element, 'next');
59					}.bind(this)),
60
61					previous: container.retrieve('roksprocket:tabs:previous', function(event, element){
62						this.direction.call(this, event, container, element, 'previous');
63					}.bind(this)),
64
65					swipe: container.retrieve('roksprocket:tabs:swipe', function(event, element){
66						event.preventDefault();
67						this.direction.call(this, event, container, element, (event.direction == 'right' ? 'previous' : 'next'));
68					}.bind(this))
69				};
70
71				['mouseenter', 'mouseleave'].each(function(type){
72					container.addEvent(type, relay[type]);
73				});
74
75				['navigation', 'next', 'previous'].each(function(dir, i){
76					var query = '[data-tabs-' + dir + ']';
77					if (i > 0) query += ', [data-' + dir + ']';
78
79					container.addEvent('click:relay(' + query + ')', relay[dir]);
80				}, this);
81
82				if (Browser.Features.Touch) container.getElements('[data-tabs-panel]').addEvent('swipe', relay['swipe']);
83
84				var active = container.getElement('[data-tabs-navigation].active');
85				if (!active) this.toPosition(container, 0);
86				else {
87					if (this.getSettings(container).autoplay && this.getSettings(container).autoplay.toInt())
88						this.startTimer(container);
89				}
90
91			}, this);
92		},
93
94		detach: function(tab){
95			tab = typeOf(tab) == 'number' ?
96					document.getElements('[data-tabs=' + this.getID(tab) + ']')
97					:
98					tab;
99
100			var containers = (tab ? new Elements([tab]).flatten() : this.tabs);
101
102			containers.each(function(container){
103				container.store('roksprocket:tabs:attached', false);
104				var relay = {
105					mouseenter: container.retrieve('roksprocket:tabs:mouseenter'),
106					mouseleave: container.retrieve('roksprocket:tabs:mouseleave'),
107					navigation: container.retrieve('roksprocket:tabs:relay'),
108					next: container.retrieve('roksprocket:tabs:next'),
109					previous: container.retrieve('roksprocket:tabs:previous')
110				};
111
112				['mouseenter', 'mouseleave'].each(function(type){
113					container.removeEvent(type, relay[type]);
114				});
115
116				['navigation', 'next', 'previous'].each(function(dir, i){
117					var query = '[data-tabs-' + dir + ']';
118					if (i > 0) query += ', [data-' + dir + ']';
119
120					container.removeEvent('click:relay(' + query + ')', relay[dir]);
121				}, this);
122
123				if (Browser.Features.Touch) container.getElements('[data-tabs-panel]').removeEvent('swipe', relay['swipe']);
124
125			}, this);
126		},
127
128		setSettings: function(container, settings, restore){
129			var id = this.getID(container),
130				options = Object.clone(this.options.settings);
131
132			if (!restore || !this.settings['id-' + id]){
133				this.settings['id-' + id] = Object.merge(options, settings || options);
134			}
135		},
136
137		getSettings: function(container){
138			var id = this.getID(container);
139
140			return this.settings['id-' + id];
141		},
142
143		getContainer: function(container){
144			if (!container) container = document.getElements('[data-tabs]');
145			if (typeOf(container) == 'number') container = document.getElement('[data-tabs='+container+']');
146			if (typeOf(container) == 'string') container = document.getElement(container);
147
148			return container;
149		},
150
151		getID: function(id){
152			if (typeOf(id) == 'number') id = document.getElement('[data-tabs='+id+']');
153			if (typeOf(id) == 'string') id = document.getElement(id);
154			return !id ? id : id.get('data-tabs');
155		},
156
157		toPosition: function(container, position){
158			container = this.getContainer(container);
159			if (!container.retrieve('roksprocket:tabs:attached')) return;
160
161			var tabs = container.getElements('[data-tabs-navigation]'),
162				panels = container.getElements('[data-tabs-panel]'),
163				settings = this.getSettings(container);
164
165			if (!tabs.length || !panels.length) return;
166			if (tabs[position].hasClass('active')) return;
167
168			if (position > tabs.length - 1) position = 0;
169			if (position < 0) position = tabs.length - 1;
170
171			tabs.removeClass('active');
172			panels.removeClass('active');
173			tabs[position].addClass('active');
174			panels[position].addClass('active');
175
176			if (settings.autoplay && settings.autoplay.toInt()) this.startTimer(container);
177		},
178
179		toTab: function(event, container, tab){
180			if (event) event.preventDefault();
181			container = this.getContainer(container);
182			if (!container.retrieve('roksprocket:tabs:attached')) return;
183
184			var tabs = container.getElements('[data-tabs-navigation]'),
185				panels = container.getElements('[data-tabs-panel]'),
186				position = tabs.indexOf(tab);
187
188			if (position == -1) throw new Error('RokSprocket Tabs: Instance ID "' + container.get('data-tabs') + '", index not found.');
189
190			this.toPosition(container, position);
191		},
192
193		direction: function(event, container, element, dir){
194			if (event) event.preventDefault();
195
196			dir = dir || 'next';
197			this[dir](container, element);
198		},
199
200		next: function(container, element){
201			container = this.getContainer(container);
202			if (!container.retrieve('roksprocket:tabs:attached')) return;
203			if (typeOf(container) == 'elements') return this.nextAll(container, element);
204
205			var tabs = container.getElements('[data-tabs-navigation]'),
206				active = tabs.filter(function(tab){ return tab.hasClass('active'); }),
207				position = tabs.indexOf(active.length ? active[0] : '') || 0,
208				next = position + 1;
209
210			if (next > tabs.length - 1) next = 0;
211			this.toPosition(container, next);
212		},
213
214		nextAll: function(containers, element){
215			containers = this.getContainer(containers);
216			if (typeOf(containers) == 'element') return this.next(containers, element);
217
218			containers.each(function(container){
219				this.next(container, element);
220			}, this);
221		},
222
223		previous: function(container, element){
224			container = this.getContainer(container);
225			if (!container.retrieve('roksprocket:tabs:attached')) return;
226			if (typeOf(container) == 'elements') return this.nextAll(container, element);
227
228			var tabs = container.getElements('[data-tabs-navigation]'),
229				active = tabs.filter(function(tab){ return tab.hasClass('active'); }),
230				position = tabs.indexOf(active.length ? active[0] : '') || 0,
231				previous = position - 1;
232
233			if (previous < 0) previous = tabs.length - 1;
234			this.toPosition(container, previous);
235		},
236
237		previousAll: function(containers, element){
238			containers = this.getContainer(containers);
239			if (typeOf(containers) == 'element') return this.previous(containers, element);
240
241			containers.each(function(container){
242				this.previous(container, element);
243			}, this);
244		},
245
246		startTimer: function(container){
247			container = this.getContainer(container);
248			if (!container.retrieve('roksprocket:tabs:attached')) return;
249
250			var settings = this.getSettings(container),
251				id = this.getID(container),
252				status = this.statuses['id-' + id],
253				autoplay = settings.autoplay.toInt(),
254				delay = (settings.delay.toInt()) * 1000;
255
256			clearTimeout(this.timers['id-' + id]);
257			if (autoplay && status != 'pause') this.timers['id-' + id] = this.next.delay(delay, this, container);
258		},
259
260		stopTimer: function(container){
261			container = this.getContainer(container);
262
263			var id = this.getID(container);
264			clearTimeout(this.timers['id-' + id]);
265		},
266
267		pause: function(container){
268			container = this.getContainer(container);
269
270			var id = this.getID(container);
271			this.statuses['id-' + id] = 'pause';
272		},
273
274		resume: function(container){
275			container = this.getContainer(container);
276
277			var id = this.getID(container);
278			this.statuses['id-' + id] = 'play';
279		}
280
281	});
282
283	this.RokSprocket.Tabs = Tabs;
284
285})());

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.