PageSourceSearch

https://www.cdrv.ca/typo3conf/ext/cchus_bs3_objects/Resources/Public/js/cchus_bs3_objects.js?1687389057

js cdrv.ca collected 2026-10-04 03:55:46 UTC 11,138 bytes, 288 lines download raw bytes

1jQuery.noConflict();
2
3(function($) {
4	$(function(){
5		// Remove pointer-events state so it gets back to normal state
6		$('.cchus_bs3_modal').css('pointer-events','auto');
7		
8		// * Initialisation *
9		var modalTemplate = $('#cchus_bs3_modal_template .cchus_bs3_modal_content').html(); // Keeps in memory what is the actual modal content template
10		
11		// Setting URL to JSON Web Service
12		var modalJSONURL = 'type=198724399&cchusbs3objects_bs3objectsjson[action]=getContent';
13		if (window.location.href.indexOf('?') >= 0) {
14			modalJSONURL = '&'+modalJSONURL;
15		} else {
16			modalJSONURL = '?'+modalJSONURL;
17		}
18		modalJSONURL = window.location.origin+window.location.pathname+window.location.search+modalJSONURL;
19		
20		var loadedJS = [];
21		initLoadedJS();
22		
23		var jsToReload = [];
24		
25		/**
26		 * Initialize loaded JS files (with src attribute)
27		 */
28		function initLoadedJS() {
29			$scripts = $.find('script');
30			if ($scripts.length > 0) {
31				for (var i=0;i<$scripts.length;i++) {
32					if ($($scripts[i]).attr('src') != '' && loadedJS.indexOf($($scripts[i]).attr('src')) == -1) {
33						loadedJS.push($($scripts[i]).attr('src'))
34					}
35				}
36			}
37		}
38		
39		/**
40		 * This method is called when displaying data from JSON.
41		 * 
42		 * @param PlainObject An object of type received from JSON (no structure defined here...)
43		 */
44		function modalDisplayContent(data) {
45			jsToReload = [];
46			if (data.content != null && data.content != undefined && $.trim(data.content) != '') {
47				// Adds footer scripts to current data content so it can be treated as if they were part of the content
48				// See "parseJS" method.
49				var sFooterScripts = '';
50				if (data.includeJSFooter != null && data.includeJSFooter != undefined && data.includeJSFooter.length > 0) {
51					for (var i=0;i<data.includeJSFooter.length;i++) {
52						var js = data.includeJSFooter[i];
53						if (loadedJS.indexOf(js) == -1) {
54							sFooterScripts += '<script src="'+js+'" type="text/javascript"></script>';
55							loadedJS.push(js);
56						} else {
57							if (js.indexOf('//') == -1 || js.indexOf(window.location.origin) > -1) { // Do not fetch external sources again
58								jsToReload.push(js);
59							}
60						}
61					}
62				}
63				if (data.includeJSFooterLibs != null && data.includeJSFooterLibs != undefined && data.includeJSFooterLibs.length > 0) {
64					for (var i=0;i<data.includeJSFooterLibs.length;i++) {
65						var js = data.includeJSFooterLibs[i];
66						if (loadedJS.indexOf(js) == -1) {
67							sFooterScripts += '<script src="'+js+'" type="text/javascript"></script>';
68							loadedJS.push(js);
69						} else {
70							if (js.indexOf('//') == -1 || js.indexOf(window.location.origin) > -1) { // Do not fetch external sources again
71								jsToReload.push(js);
72							}
73						}
74					}
75				}
76				data.content += sFooterScripts;
77
78				// Read all scripts tag from content (don't forget that footer scripts have been added...)
79				// and then parse them.
80				// If no script, just display the modal window.
81				var aScripts = $(data.content+'<div>'+sFooterScripts+'</div>').find('script');
82				if (aScripts.length > 0) {
83					parseJS(aScripts);
84				} else {
85					displayModal();
86				}
87			}
88			
89			/**
90			 * Parse all javascript tags.
91			 * When there's a "src" attribute then the file is fetched and executed, synchronous way.
92			 * When there's no "src" attribute, then the <script> block is added to content so it's executed automatically by the browser.
93			 * This method is used to change the async way of fetching script file.
94			 * When there's no more script tag to parse / fetch, it displays the modal window.
95			 * 
96			 * @param jQuery A jQuery object containing array of HTMLScriptElement
97			 * @param integer Index to start. No "start" parameter = index 0.
98			 * @return void
99			 */
100			function parseJS(js, start) {
101				var idx = 0;
102				if (start != null && start != undefined) {
103					idx = start;
104				}
105				if (idx < js.length) {
106					if (js.get(idx).src != '') {
107						fetchJS(js, idx);
108					} else {
109						data.content += js.get(idx).outerHTML;
110						parseJS(js, ++idx);
111					}
112				} else {
113					displayModal();
114				}
115			}
116			
117			/**
118			 * Fetch the JS file and parse the next JS tag.
119			 * 
120			 * @param jQuery A jQuery object containing array of HTMLScriptElement
121			 * @param integer Index of the array to fetch.
122			 * @return void
123			 */
124			function fetchJS(js, idx) {
125				$.getScript(js.get(idx).src).done(function() {
126					parseJS(js, ++idx);
127				});
128			}
129
130			/**
131			 * Display the modal window
132			 * 
133			 * @return void
134			 */
135			function displayModal() {
136				var uid = getUidFromURL($('#cchus_bs3_modal_current_cuid').val()).substring(2);
137				$('#cchus_bs3_modal_'+uid).html(modalTemplate.replace(/{{modalTitle}}/g, data.title).replace(/{{modalContent}}/g, data.content));
138				$('#cchus_bs3_modal_'+uid).modal();
139				for (var i=0;i<jsToReload.length;i++) {
140					var js = jsToReload[i];
141					$.getScript(js);
142				}
143			}
144		}
145		
146		/**
147		 * This event traps the click on ".cchus_bs3_modal" class, which is mostly set on anchors,
148		 * then fetch the content from the JSON Web Service and display its content.
149		 */
150		$('body').on('click', '.cchus_bs3_modal, [class="cchus_bs3_modal"]', function(e) {
151			$('#cchus_bs3_modal_current_cuid').val($(this).attr('href'));
152			var iHashPos = $(this).attr('href').indexOf('#');
153			if (iHashPos >= 0) {
154				var uid = getUidFromURL($(this).attr('href')).substring(2);
155				if (document.getElementById('cchus_bs3_modal_'+uid) != null && document.getElementById('cchus_bs3_modal_'+uid) != undefined) {
156					$('#cchus_bs3_modal_'+uid).modal();
157					e.preventDefault();
158				}
159			}
160		});
161
162		/**
163		 * Hide the loading logo when the modal has been shown.
164		 */
165		$('body').on('shown.bs.modal', '.cchus_bs3_modal_content', function(e) {
166			$('div.cchus_bs3_objects.loading').hide(); // Hide when the modal is displayed
167		});
168		
169		$('body').on('hide.bs.modal', '.cchus_bs3_modal_content', function(e) {
170			// Stop all HTML5 videos
171			$(this).find('video').each(function(iIdx, oVideo){
172				oVideo.pause();
173			});
174			
175			// Stop all Youtube videos
176			$(this).find('iframe[src*="youtube.com"], iframe[src*="youtu.be"]').each(function(idx, obj){
177				obj.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*')
178			});			
179		});
180
181		/**
182		 * Traps form submission so the page isn't POST and the content is read through Ajax instead.
183		 */
184		$(document).on('click', '.cchus_bs3_modal_content input[type="submit"]', function(e) {
185			var uid = getUidFromURL($('#cchus_bs3_modal_current_cuid').val()).substring(2);
186			$('#cchus_bs3_modal_'+uid).modal('hide');
187			$('div.cchus_bs3_objects.loading').show();
188			var $form = $(this).closest('form');
189			var sAction = $form.attr('action');
190			if (sAction == null || sAction == undefined || sAction == '') {
191				sAction = window.location.href;
192				sAction = sAction.substr(sAction.indexOf('/', 8));
193			}
194			var sMethod = $form.attr('method');
195			if (sMethod == null || sMethod == undefined || sMethod == '') {
196				sMethod = 'GET';
197			}
198			
199			$('#cchus_bs3_modal_'+uid+' input[id^="powermail_hp_"]').remove(); // Remove the powermail honeypod
200			
201			$.ajax({
202				url: sAction,
203				method: sMethod,
204				data: $form.serialize()
205			})
206			.done(function(data){
207				var dataToParse = {};
208				// Getting content only, without entire page
209				if ($('#cchus_bs3_modal_current_cuid').val().indexOf('#') > -1) {
210					var uid = getUidFromURL($('#cchus_bs3_modal_current_cuid').val());
211
212					var $foundContent = $(data).find(uid);
213					if ($foundContent.length > 0) {
214						dataToParse.content = $foundContent.get(0).outerHTML;
215					}
216					
217					// Adding header scripts
218					var head = data.substring(data.indexOf('<head>')+'<head>'.length, data.indexOf('</head>'));
219					var $scripts = $('<div>'+head+'</div>').find('script');
220					if ($scripts.length > 0) {
221						dataToParse.includeJS = [];
222						for (var i=0;i<$scripts.length;i++) {
223							dataToParse.includeJS.push($($scripts.get(i)).attr('src'));
224						}
225					}
226					
227					// Getting title
228					var pageTitle = $.trim(document.title).replace(/\s/g,' ').replace(/&nbsp;/g,' ');
229					var modalTitle = $.trim(head.substring(head.indexOf('<title>')+'<title>'.length, head.indexOf('</title>'))).replace(/\s/g,' ').replace(/&nbsp;/g,' ');
230					if (modalTitle != null && modalTitle != undefined && modalTitle != '') {
231						// Comparing titles to remove suffix, if needed
232						var i = 0;
233						var stop = false;
234						while (i < Math.min(pageTitle.length, modalTitle.length) && !stop) {
235							i++;
236							var pageTitleTemp = pageTitle.substr(pageTitle.length - i);
237							var modalTitleTemp = modalTitle.substr(modalTitle.length - i);
238							if (pageTitleTemp != modalTitleTemp) {
239								stop = true;
240							}
241						}
242						if (i > 0) {
243							modalTitle = modalTitle.substring(0, modalTitle.length - i + 1);
244						}
245					}
246					dataToParse.title = modalTitle;
247					
248					// Adding footer scripts
249					var body = data.substring(data.indexOf('<body>')+'<body>'.length, data.indexOf('</body>'));
250					$scripts = $('<div>'+body+'</div>').find('script');
251					if ($scripts.length > 0) {
252						dataToParse.includeJSFooter = [];
253						for (var i=0;i<$scripts.length;i++) {
254							var src = $($scripts.get(i)).attr('src');
255							if (dataToParse.content.indexOf(src) == -1) { // This is not a script inside the content
256								dataToParse.includeJSFooter.push(src);
257							}
258						}
259					}
260					
261					modalDisplayContent(dataToParse);
262				} else {
263					$('#cchus_bs3_modal_'+uid).html(modalTemplate).replace(/{{modalTitle}}/g, 'Erreur / Error').replace(/{{modalContent}}/g, '<p>Une erreur est survenue lors de l\'affichage du contenu.<br />An error occured while fetching content.<br /></p><p><b>Ne peut trouver l\'ID du contenu<br />Can\'t find content ID.</b></p><p>Veuillez svp contacter votre administrateur système.<br />Please contact your system administrator.</p><p>Merci.<br />Thank you.</p>');
264					$('#cchus_bs3_modal_'+uid).modal();
265				}
266			})
267			.fail(function(jqXHR, textStatus, errorThrown){
268				$('#cchus_bs3_modal_'+uid).html(modalTemplate).replace(/{{modalTitle}}/g, 'Erreur / Error').replace(/{{modalContent}}/g, '<p>Une erreur est survenue lors de l\'affichage du contenu.<br />An error occured while fetching content.<br /></p><p><b>'+errorThrown+'</b></p><p>Veuillez svp contacter votre administrateur système.<br />Please contact your system administrator.</p><p>Merci.<br />Thank you.</p>');
269				$('#cchus_bs3_modal_'+uid).modal();
270			});
271			e.preventDefault();
272		});
273
274		function getUidFromURL(url) {
275			uid = url.substring(url.indexOf('#'));
276			if (uid.indexOf('/') > -1) {
277				uid = uid.substring(0, uid.indexOf('/'));
278			}
279			if (uid.indexOf('?') > -1) {
280				uid = uid.substring(0, uid.indexOf('?'));
281			}
282			if (uid.indexOf('&') > -1) {
283				uid = uid.substring(0, uid.indexOf('&'));
284			}
285			return uid;
286		}
287	});
288})(jQuery);

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.