PageSourceSearch

https://lawis.at/scripts/basic/globalEffectsHandling.js?v=2.3.5-HF1

js lawis.at collected 2026-10-02 10:29:21 UTC 14,747 bytes, 523 lines download raw bytes

1var KGISglobalEffectsHandling = function () {
2	var filterModel = null;
3	var filterView = null;
4	var tableAnimationActive = false;
5	var filterAnimationActive = false;
6
7	var initSearch = function (startActive) {
8		var searchView = new SearchView({ model: filterModel });
9		searchView.render();
10	};
11
12	var initTable = function (startActive) {
13		if (startActive != $('#tableSpace').hasClass('active')) {
14			toggleTable();
15		}
16		if ($('#tableSpace').hasClass('active')) {
17			KGISapp.addEventHandler('table:modelReady', function () {
18				$('.contentViewer').addClass('state_table_active');
19				KGISapp.triggerEvent('table:activate', true);
20			});
21		}
22	};
23
24	var initFilter = function (startActive) {
25		filterView = new FilterView({ model: filterModel });
26		filterView.render();
27
28		if (startActive) {
29			toggleFilter();
30		}
31	};
32
33
34	var toggleTable = function () {
35		var deferred = $.Deferred();
36
37		if (tableAnimationActive) {
38			return deferred.reject().promise();
39		}
40		tableAnimationActive = true;
41
42		if ($('#tableSpace').hasClass('active')) {
43			$('header #switch #list').removeClass('table_active');
44			$('#mapSpace').css({ height: '' });
45			var finalize = function () {
46				$('.contentViewer').removeClass('state_table_active');
47				$('#tableSpace').removeClass('active');
48				checkElements().then(function () {
49					tableAnimationActive = false;
50					$('#list').removeClass('current');
51					KGISapp.triggerEvent('table:activate', false);
52					deferred.resolve();
53				});
54			};
55			window.setTimeout(finalize, (KGISviewState.isMobileView() ? 0 : 500));
56		} else {
57			$('#tableSpace').addClass('active');
58			$('.contentViewer').addClass('state_table_active');
59			$('header #switch #list').addClass('table_active');
60			$('#list').addClass('current');
61			var finalize = function () {
62				checkElements().then(function () {
63					tableAnimationActive = false;
64					KGISapp.triggerEvent('table:activate', true);
65					deferred.resolve();
66				});
67			};
68			window.setTimeout(finalize, (KGISviewState.isMobileView() ? 0 : 500));
69		}
70
71		return deferred.promise();
72	};
73
74
75	var toggleFilter = function () {
76		var deferred = $.Deferred();
77
78		if (filterAnimationActive) {
79			return deferred.reject().promise();
80		}
81		filterAnimationActive = true;
82
83		var filter = $('#filterBar');
84		if (filter.hasClass('active')) {
85			var finalize = function () {
86				filter.removeClass('active');
87				$('#filter').removeClass('current');
88				$('#filter .arrow').removeClass('arrow_current');
89				$('#filter .arrow_down').removeClass('arrow_down_active');
90				filterAnimationActive = false;
91				deferred.resolve();
92			};
93			window.setTimeout(finalize, 0); // no animation
94		} else {
95			filter.addClass('active');
96			$('#filter').addClass('current');
97			$('#filter .arrow').addClass('arrow_current');
98			$('#filter .arrow_down').addClass('arrow_down_active');
99
100			// make sure that current filter values and select boxes are synced
101			filterModel.trigger('change');
102
103			var finalize = function () {
104				if (filterView) {
105					filterView.scale();
106				}
107				filterAnimationActive = false;
108				deferred.resolve();
109			};
110			window.setTimeout(finalize, 0); // no animation				
111		}
112		return deferred.promise();
113	};
114
115	var toggleMenu = function () {
116		$('#nav_down').toggleClass('active');
117		$('a#nav').toggleClass('active');
118	};
119
120	var viewStateChangeHandler = function (oldState, newState) {
121		$('#filter_down').removeClass('portraitView');
122
123		switch (newState) {
124			case 'mobile':
125				if ($('#filterBar').hasClass('active')) {
126					toggleFilter();
127				}
128
129				var nav = $('#nav_down').detach();
130				$('#sub_header>.container').prepend(nav);
131
132				break;
133
134			case 'portrait':
135				$('#filter_down').addClass('portraitView');
136			// don't break - fall through
137
138			case 'default':
139			default:
140				if (oldState) {
141					var nav = $('#nav_down').detach();
142					$('#main_header #logo_container').after(nav);
143				}
144				break;
145		}
146
147		window.setTimeout(function () {
148			// this will invalidate the map and adjust table entries, if necessary
149			$(window).trigger('resize');
150		}, 500);
151	};
152
153	var scaleHeader = function () {
154		if (!KGISviewState.isMobileView()) {
155			var container = $('#nav_down');
156			var headerTabs = container.find('li');
157
158			if (headerTabs.length > 0) {
159				var parent = container.parent();
160				var containerMaxWidth = parent.width();
161				$.each(parent.children(':visible').not('#nav_down'), function () {
162					containerMaxWidth -= $(this).outerWidth();
163				});
164
165				var width = 130 * headerTabs.length;
166
167				if (width > containerMaxWidth) {
168					container.addClass('narrow');
169				} else {
170					container.removeClass('narrow');
171				}
172			}
173		}
174	};
175
176	var checkElements = function () {
177		var deferred = $.Deferred();
178		var mapCss = { height: '', width: '' };
179		var tableCss = { height: '', width: '' };
180		var infoCss = { height: '', width: '' };
181
182		if (!KGISviewState.isMobileView() && $('#mapSpace').length > 0) {
183			var width = ($('#infoSpace').hasClass('active')) ? $.infoSpaceWidth() : 0;
184			tableCss.width = (100 - width) + '%';
185			infoCss.width = width + '%';
186
187			if (KGISviewState.isDefaultView()) {
188				var mapSpaceHeight = $.mapSpaceHeight();
189				mapCss.width = (100 - width) + '%';
190				mapCss.height = mapSpaceHeight + '%';
191				tableCss.height = (100 - mapSpaceHeight) + '%';
192			}
193		}
194
195		$('#mapSpace').css(mapCss);
196		$('#tableSpace').css(tableCss);
197		window.requestAnimationFrame(function () { $('#infoSpace').css(infoCss); }, 0);
198
199		window.setTimeout(function () {
200			if (!KGISviewState.isMobileView() || !$('#tableSpace').hasClass('active')) {
201				// omit resize in mobile view, if table is active
202				if (KGISvariables.map) {
203					window.setTimeout(function () {
204						KGISvariables.map.invalidateSize({ pan: false });
205					}, 600);
206				}
207			}
208			deferred.resolve();
209		}, 0);
210
211		return deferred.promise();
212	};
213
214	return {
215		initialize: function () {
216			filterModel = new Backbone.Model();
217
218			// open table if table=true URL Parameter is set or if KGISconfig.table is set
219			var tableActive = KGISUrlParams.has('table') ? (KGISUrlParams.get('table') == 'true') : Boolean(KGISConfig.table);
220			initTable(tableActive);
221			if ($('#search_down').length != 0) {
222				initSearch(false);
223			}
224
225			viewStateChangeHandler(null, KGISviewState.getState());
226
227			$('a#nav').on('click', function (e) {
228				toggleMenu();
229			});
230			$('#nav_down li a').on('click', function (e) {
231				if ($('#nav_down').hasClass('active')) {
232					toggleMenu();
233				}
234			});
235			$('#search_down input').on('focus', function (e) {
236				if (!$('#tableSpace').hasClass('active')) {
237					toggleTable();
238				}
239			});
240			$('#search_down .delete').on('click', function (e) {
241				if ($('#mapSpace').length > 0) {
242					if ($('#tableSpace').hasClass('active') && !$('#infoSpace').hasClass('active')) {
243						toggleTable();
244					}
245				}
246			});
247			$('#list').on('click', function (e) {
248				toggleTable();
249			});
250			$('#dateRange').on('change', function (e) {
251				var target = $(e.target);
252				// todo filter
253				var url = window.location.href;
254				var lang = KGISUrlParams.has('lang') ? KGISUrlParams.get('lang') : 'de';
255				if (url.indexOf('?') > -1) {
256					url += '&season=' + target.val() + '&lang='+lang;
257				} else {
258					url += '?season=' + target.val() + '&lang='+lang;
259				}
260				filterModel.set('date', target.val());
261				window.location.href = url;
262
263				// if (target.closest('#dateRangeFilter').hasClass('inline')) {
264				// 	filterModel.set('date', target.val());
265				// }
266			});
267			$('#filter').on('click', function (e) {
268				toggleFilter();
269			});
270			$('#filterBar').on('click', function (e) {
271				var target = $(e.target);
272				if (target.prop('id') == 'filterBar') {
273					toggleFilter();
274				}
275			});
276			$('.button_subnav').on('click', function (e) {
277				var target = $(e.currentTarget);
278				switch (target.attr('id')) {
279					case 'search':
280						if ($('#filterBar').hasClass('active')) {
281							toggleFilter();
282						}
283						break;
284					case 'filter':
285						if ($('#search_down').hasClass('active')) {
286							//toggleSearch();
287						}
288						break;
289					case 'list':
290						if ($('#filterBar').hasClass('active')) {
291							toggleFilter();
292						}
293						break;
294				}
295			});
296
297
298			$('#tableSpace').on('keydown', function (e) {
299				switch (e.keyCode) {
300					case 40:
301						KGISapp.triggerEvent("keyEvent:cursorDown", null);
302						break;
303					case 38:
304						KGISapp.triggerEvent("keyEvent:cursorUp", null);
305						break;
306					case 37:
307						KGISapp.triggerEvent("keyEvent:cursorLeft", null);
308						break;
309					case 39:
310						KGISapp.triggerEvent("keyEvent:cursorRight", null);
311						break;
312					case 13:
313						KGISapp.triggerEvent("keyEvent:enter", null);
314						break;
315				}
316
317				return false;
318			});
319
320			$(document).on('keyup', function (e) {
321				var slider = $('.imageSlider');
322				if (slider.length > 0) {
323					if (e.keyCode == 37) { // LEFT
324						slider.parent().find('.prev').trigger('click');
325					} else if (e.keyCode == 39) { // RIGHT
326						slider.parent().find('.next').trigger('click');
327					}
328				}
329			});
330
331			KGISapp.addEventHandler('setFullscreenMap', function (flag) {
332				if (flag && $('#infoSpace').hasClass('active')) {
333					KGISapp.triggerEvent('forceInfoClose');
334				}
335				if (flag == $('#tableSpace').hasClass('active')) {
336					toggleTable();
337				}
338			});
339
340			KGISapp.addEventHandler('view:stateChange', function (states) {
341				viewStateChangeHandler(states.oldState, states.newState);
342			});
343
344			KGISapp.addEventHandler('quickglance:profileSelected', function (model) {
345				if (model) {
346					if (!$('#tableSpace').hasClass('active') && !KGISviewState.isMobileView()) {
347						toggleTable();
348					}
349				}
350			});
351			KGISapp.addEventHandler('table:modelReady', function () {
352				initFilter(false);
353				var initialFilters = {};
354
355				if (KGISUrlParams.has('subregion') && $('#subregion').length > 0) {
356					var val = KGISUrlParams.get('subregion');
357					var values = [];
358					if (val.match(/^\d+(,\d+)*$/)) {
359						// list of ids
360						values = _.map(val.split(','), function (v) { return parseInt(v); });
361					} else {
362						//legacy
363						var o = $('#subregion option').filter(function () { return $(this).html() == val; }).val();
364						if (o) {
365							values.push(parseInt(o));
366						}
367					}
368					if (values.length > 0) {
369						initialFilters['subregion'] = values;
370					}
371				}
372				if (KGISUrlParams.has('region') && $('#region').length > 0) {
373					var val = KGISUrlParams.get('region');
374					var values = [];
375					if (val.match(/^\d+(,\d+)*$/)) {
376						// list of ids
377						values = _.map(val.split(','), function (v) { return parseInt(v); });
378					} else {
379						//legacy
380						var o = $('#region option').filter(function () { return $(this).html() == val; }).val();
381						if (o) {
382							values.push(parseInt(o));
383						}
384					}
385					if (values.length > 0) {
386						initialFilters['region'] = values;
387					}
388				}
389				if (KGISUrlParams.has('country') && $('#country').length > 0) {
390					var val = KGISUrlParams.get('country');
391					var values = [];
392					if (val.match(/^\d+(,\d+)*$/)) {
393						// list of ids
394						values = _.map(val.split(','), function (v) { return parseInt(v); });
395					}
396					if (values.length > 0) {
397						initialFilters['country'] = values;
398					}
399				}
400
401				if (KGISUrlParams.has('altitude') && $('#hoehenstufe').length > 0) {
402					var val = KGISUrlParams.get('altitude');
403					if ($('#hoehenstufe option[value=' + val + ']').length > 0) {
404						initialFilters['altitude'] = val;
405					}
406				}
407
408				if (KGISUrlParams.has('search')) {
409					var searchText = KGISUrlParams.get('search');
410					if (searchText) {
411						//initialFilters['search'] = searchText;
412						// toggleSearch();
413					}
414				}
415				if ($('#dateRange').length > 0) {
416					if (KGISUrlParams.has('zeit')) {
417						if (KGISUrlParams.get('zeit') != 'Infinity' && $('#dateRange option[value="' + KGISUrlParams.get('zeit') + '"]').length > 0) {
418							initialFilters['date'] = KGISUrlParams.get('zeit');
419						} else if ($('#dateRange option[value=""]').length == 0 && typeof (KGISConfig.default_period) !== 'undefined') {
420							initialFilters['date'] = KGISConfig.default_period;
421						} // else -> archive mode, do not set filters
422					} else if (typeof (KGISConfig.default_period) !== 'undefined') {
423						initialFilters['date'] = KGISConfig.default_period;
424					}
425				}
426
427				var otherFilters = ['exposition', 'involved', 'trainings', 'status'];
428				_.each(otherFilters, function (key) {
429					if (KGISUrlParams.has(key)) {
430						var val = KGISUrlParams.get(key);
431						if (val && $('#' + key + ' option[value=' + val + ']').length > 0) {
432							initialFilters[key] = val;
433						}
434					}
435				});
436
437				var otherMultiFilters = ['commission', 'roles'];
438				_.each(otherMultiFilters, function (key) {
439					if (KGISUrlParams.has(key)) {
440						var val = KGISUrlParams.get(key).split(',');
441						if (_.isArray(val) && val.length > 0) {
442							initialFilters[key] = val;
443						}
444					}
445				});
446
447				if (_.isEmpty(initialFilters)) {
448					filterModel.trigger('change');
449				} else {
450					filterModel.set(initialFilters);
451				}
452			});
453
454			KGISapp.addEventHandler('filter:update', function (filters) {
455				// close Filter view on update
456				if ($('#filterBar').hasClass('active')) {
457					toggleFilter();
458				}
459				// add/remove active class to/from subnavigation button
460				var filtersActive = _.some(filters, function (el) { return el != null; });
461				if (filtersActive) {
462					$('#subnav #filter').addClass('active');
463				} else {
464					$('#subnav #filter').removeClass('active');
465				}
466			});
467
468			KGISapp.addEventHandler('filter:open', function () {
469				if (!$('#filterBar').hasClass('active')) {
470					toggleFilter();
471				}
472			});
473
474			KGISapp.addEventHandler('filter:close', function () {
475				if ($('#filterBar').hasClass('active')) {
476					toggleFilter();
477				}
478			});
479
480			KGISapp.addEventHandler('info:activate', function (flag) {
481				if (!flag) {
482					if ($('#search_down').hasClass('inline') && $('#searchText').length > 0 && $('#searchText').val()) {
483						filterModel.set({ search: '' });
484					}
485
486					if (!KGISviewState.isMobileView() && $('#tableSpace').hasClass('active')) {
487						toggleTable();
488					} else {
489						checkElements();
490					}
491
492					if (KGISviewState.isMobileView()) {
493						KGISapp.triggerEvent('quickglance:noSelection');
494					}
495				}
496			});
497
498			var doResize = function () {
499				var elements = $('.contentViewer').children();
500				elements.css({
501					transition: 'none'
502				});
503
504				window.setTimeout(function () {
505					checkElements().then(function () {
506						KGISapp.triggerEvent('globalResize');
507
508						window.setTimeout(function () {
509							// restore all css transitions
510							elements.css({
511								transition: ''
512							});
513						}, 400);
514					});
515					scaleHeader();
516				}, 0);
517			};
518
519			$(window).on('orientationchange', doResize);
520			$(window).on('resize', _.debounce(doResize, 40));
521		}
522	};
523}();

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.