PageSourceSearch

https://forstservice-gisbrecht.de/templates/tenth/roksprocket/layouts/headlines/themes/default/headlines.js

js forstservice-gisbrecht.de collected 2026-10-08 03:33:10 UTC 9,090 bytes, 277 lines download raw bytes

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

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.