PageSourceSearch

https://www.quebec-cite.com/themes/custom/base_otq/js/app.js?tlqbc5

js quebec-cite.com collected 2026-09-24 18:19:24 UTC 8,916 bytes, 265 lines download raw bytes

1/*-----------------------------------------------------------------------------------------------------------
2		MAIN APP
3-----------------------------------------------------------------------------------------------------------*/
4let CossetteApp = (function ($, Drupal) {
5	let self = this;
6	let lastScrollY = 0;
7	let didScroll = false;
8	let didResize = false;
9
10	// Sticky maps variables
11	self.$stickyMap = null;
12	self.$stickySteps = null;
13	self.$stickyStepsWithMarker = null;
14	self.$stickyOffset = null;
15	self.stickyMapLoaded = false;
16	self.stickyOffsetTop = null;
17	self.stickyOffsetBottom = null;
18
19	self.maps = [];
20
21	/** ------------------------------
22   * Constructor
23   --------------------------------- */
24
25	self.construct = function () {
26		document.addEventListener('DOMContentLoaded', onAppReady);
27		window.onload = onAppLoaded;
28
29		return self;
30	};
31
32	/** ------------------------------
33   * App Events
34   --------------------------------- */
35
36	let onAppReady = function (ev) {
37		// Global variables
38		self.langCode = drupalSettings.path.currentLanguage;
39
40		// Global elements
41		self.$document = $(document);
42		self.$window = $(window);
43		self.$html = $('html');
44		self.$body = $('body');
45		self.$layout = $('#layout-main');
46		self.$layoutHeader = $('#layout-header');
47		self.$layoutFooter = $('#layout-footer');
48		self.$mediaCredit = $('.media-credit');
49		self.$toggleButton = $('.toggle-button');
50
51		self.$window.on('scroll', onWindowScroll);
52		self.$window.on('resize', onWindowResize);
53
54		if (Modernizr.touchevents) {
55			self.$mediaCredit.on('click', onShowCredit);
56		}
57
58		self.$toggleButton.on('click', onClickToggleButton);
59
60		CossetteRouter.init();
61		self.setVh();
62
63		detectEdge();
64	};
65
66	let onAppLoaded = function (ev) {
67		const Navigation = CossetteRouter.getClassReference('OtqNavigation');
68		Navigation.actionsHeightOnLoad();
69	};
70
71	/** ------------------------------
72   * Events
73   --------------------------------- */
74
75	/** ------------------------------
76   * Public
77   --------------------------------- */
78	self.scrollTo = function (element, parent = null, offset = 0, duration = 300) {
79		let $el = $(element);
80
81		if ($el.length) {
82			if (parent) {
83				let $parentContainer = $el.closest(parent);
84				let pos = $el.position().top;
85				pos = pos - offset + $parentContainer.scrollTop();
86
87				$parentContainer.animate({ scrollTop: pos }, duration);
88			} else {
89				let pos = $el.offset().top - self.$layoutHeader.height();
90				if (!Modernizr.touchevents) {
91					self.$body.addClass('is-scrolling');
92					$('html, body').animate({ scrollTop: pos }, duration, function () {
93						self.$body.removeClass('is-scrolling');
94					});
95				} else {
96					$('html, body').scrollTop(pos);
97				}
98			}
99		}
100	};
101
102	self.setVh = function () {
103		document.documentElement.style.setProperty('--vh', `${window.innerHeight / 100}px`);
104	};
105
106	/** ------------------------------
107   * Private
108   --------------------------------- */
109
110	let onShowCredit = function (e) {
111		let $this = $(e.currentTarget);
112		$this.toggleClass('showing');
113	};
114
115	let onClickToggleButton = function (e) {
116		let $this = $(e.currentTarget);
117		let $checkbox = $this.children('input[type="checkbox"]');
118		$checkbox.prop('checked', !$checkbox.prop('checked'));
119		$this.toggleClass('is-on');
120	};
121
122	let detectEdge = function () {
123		if (document.documentMode || /Edge/.test(navigator.userAgent)) {
124			self.$html.addClass('is-edge');
125		}
126	};
127
128	/** ------------------------------
129   * Window events
130   --------------------------------- */
131
132	let onWindowScroll = function () {
133		requestScrollTick();
134	};
135
136	let onWindowResize = function () {
137		requestResizeTick();
138	};
139
140	let requestScrollTick = function () {
141		if (!didScroll) {
142			window.requestAnimationFrame(update);
143			didScroll = true;
144		}
145	};
146
147	let requestResizeTick = function () {
148		if (!didResize) {
149			didResize = true;
150			window.requestAnimationFrame(update);
151		}
152	};
153
154	let update = function () {
155		if (didScroll) {
156			let currentScroll =
157				window.scrollY || window.pageYOffset || document.body.scrollTop + ((document.documentElement && document.documentElement.scrollTop) || 0);
158
159			// Actions for reveal setup
160			if (CossetteRouter.initiliazedClasses['OtqReveal'] !== undefined) {
161				CossetteRouter.initiliazedClasses['OtqReveal'].handleReveal(lastScrollY, currentScroll);
162			}
163
164			// Actions for main navigation sticky
165			CossetteRouter.initiliazedClasses['OtqNavigation'].setStickyMenu(lastScrollY, currentScroll);
166
167			// Actions for audio player
168			if (CossetteRouter.initiliazedClasses['OtqAudioPlayer'] !== undefined) {
169				CossetteRouter.initiliazedClasses['OtqAudioPlayer'].setStickyAudioPlayer(lastScrollY, currentScroll);
170			}
171
172			// Actions for sticky map
173			if (CossetteRouter.initiliazedClasses['OtqMap'] !== undefined) {
174				if (CossetteApp.$stickyOffset !== null) {
175					CossetteRouter.initiliazedClasses['OtqMap'].adjustMapStickyness(lastScrollY, currentScroll);
176				}
177			}
178
179			lastScrollY = currentScroll;
180			didScroll = false;
181		}
182
183		if (didResize) {
184			self.setVh();
185
186			if (CossetteRouter.initiliazedClasses['OtqNavigation'] !== undefined) {
187				CossetteRouter.initiliazedClasses['OtqNavigation'].actionsHeightOnResize();
188			}
189
190			if (CossetteRouter.initiliazedClasses['OtqSlider'] !== undefined) {
191				// CossetteRouter.initiliazedClasses["OtqSlider"].adjustSliderProperties();
192
193				// If there is a sticky  map in the page, special behavior
194				if (self.stickyMapLoaded) {
195					CossetteRouter.initiliazedClasses['OtqSlider'].checkListSlider();
196				}
197			}
198
199			if (CossetteRouter.initiliazedClasses['OtqMap'] !== undefined) {
200				if (CossetteApp.$stickyOffset !== null) {
201					CossetteRouter.initiliazedClasses['OtqMap'].handleStickyHeightChange();
202				}
203			}
204
205			didResize = false;
206		}
207	};
208
209	return self.construct();
210})(jQuery, Drupal);
211
212// Closest to Offset
213jQuery.fn.closestToOffset = function (offset) {
214	let yAdjust = CossetteApp.stickyYAdjust;
215	let scrollOffset = CossetteApp.stickyOffsetTop;
216
217	let el = null,
218		elOffset,
219		x = offset.left,
220		y = offset.top - scrollOffset - yAdjust,
221		distance,
222		dx,
223		dy,
224		minDistance;
225
226	this.each(function () {
227		let $this = jQuery(this);
228		elOffset = $this.position();
229		elOffset.bottom = elOffset.top + $this.height();
230
231		if (x >= elOffset.left && x <= elOffset.right && y >= elOffset.top && y <= elOffset.bottom) {
232			el = $this;
233			return false;
234		}
235
236		var offsets = [
237			[elOffset.left, elOffset.top],
238			[elOffset.right, elOffset.top],
239			[elOffset.left, elOffset.bottom],
240			[elOffset.right, elOffset.bottom]
241		];
242		for (var off in offsets) {
243			dx = offsets[off][0] - x;
244			dy = offsets[off][1] - y;
245			distance = Math.sqrt(dx * dx + dy * dy);
246			if (minDistance === undefined || distance < minDistance) {
247				minDistance = distance;
248				el = $this;
249			}
250		}
251	});
252
253	return el;
254};
255
256// Browser detection
257(function (a) {
258	(jQuery.browser = jQuery.browser || {}).mobile =
259		/(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
260			a
261		) ||
262		/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
263			a.substr(0, 4)
264		);
265})(navigator.userAgent || navigator.vendor || window.opera);

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.