1/** 2 * @file main.js 3 * 4 * Main JS file for Old Port of Montreal Drupal 8 website 5 * 6 * @author Thierry Parent, Efficio 7 * @since Nov. 30th 8 */ 9(function ($) { 10 var os; 11 12 function moveBackWrapper() { 13 $('.language-switcher-language-url').css('padding-right','0'); 14 $('.map-back-wrapper').css('left', $('.top-header > .left').outerWidth()).css('visibility', 'visible'); 15 } 16 17 $.fn.onPageLoadMain = function () { 18 var $body = $('body'); 19 20 if (jQuery.reCaptchaLoaded) { 21 loadReCaptcha(); 22 } 23 24 $('img').each(function () { 25 setTimeout((function ($self) { 26 return function () { 27 var imgRatio = $self.width() / $self.height(), 28 containerRatio = $self.parent().width() / $self.parent().height(); 29 imgRatio = !isFinite(imgRatio) ? ($self.width() == 0 ? 1 : 10) : imgRatio; 30 containerRatio = !isFinite(containerRatio) ? ($self.parent().width() == 0 ? 1 : 10) : containerRatio; 31 $self.addClass('img-' + (imgRatio > containerRatio ? 'landscape' : 'portrait')); 32 }; 33 })($(this)), 10); 34 }); 35 36 if ($('.map-back-wrapper').length) { 37 moveBackWrapper(); 38 $(window).on('resize orientationchange', function () { 39 setTimeout(moveBackWrapper, 50); 40 }) 41 } 42 const sup = '<sup>', 43 endsup = '</sup>', 44 r = ['\u00AE', '®']; 45 var $wrapper = $body; 46 if (window.location.pathname == '/map' || window.location.pathname == '/carte' || window.location.pathname == '/fr/carte') { 47 $wrapper = $($('.map-navigation-full')[0]); 48 } 49 $wrapper.contents().each(function () { 50 for (var i = r.length - 1; i >= 0; i--) { 51 if (this.nodeType == 3) { 52 if ($(this).text().indexOf(r[i]) != -1) { 53 this.nodeValue = $.trim($(this).text()).replace(new RegExp('/' + r[i] + '/g'), sup + r[i] + endsup); 54 } 55 } 56 if (this.nodeType == 1) { 57 if ($(this).text().indexOf(r[i]) != -1) { 58 $(this).find('p, h1, h2, h3, h4, li').each(function( index ){ 59 $(this).html($(this).html().replace(new RegExp(r[i], 'g'), sup + r[i] + endsup)); 60 }); 61 } 62 } 63 } 64 }); 65 /** 66 * Thanks to Ludwig and kmonsoor from StackOverflow 67 * @see http://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript#answer-18706818 68 * 69 * @type {{screen, browser, browserVersion, browserMajorVersion, 70 * mobile, os, osVersion, cookies, flashVersion}} 71 */ 72 os = (function (window) { 73 { 74 var unknown = '-'; 75 76 // screen 77 var screenSize = ''; 78 if (screen.width) { 79 width = (screen.width) ? screen.width : ''; 80 height = (screen.height) ? screen.height : ''; 81 screenSize += '' + width + " x " + height; 82 } 83 84 // browser 85 var nVer = navigator.appVersion; 86 var nAgt = navigator.userAgent; 87 var browser = navigator.appName; 88 var version = '' + parseFloat(navigator.appVersion); 89 var majorVersion = parseInt(navigator.appVersion, 10); 90 var nameOffset, verOffset, ix; 91 92 // Opera 93 if ((verOffset = nAgt.indexOf('Opera')) != -1) { 94 browser = 'Opera'; 95 version = nAgt.substring(verOffset + 6); 96 if ((verOffset = nAgt.indexOf('Version')) != -1) { 97 version = nAgt.substring(verOffset + 8); 98 } 99 } 100 // Opera Next 101 if ((verOffset = nAgt.indexOf('OPR')) != -1) { 102 browser = 'Opera'; 103 version = nAgt.substring(verOffset + 4); 104 } 105 // Edge 106 else if ((verOffset = nAgt.indexOf('Edge')) != -1) { 107 browser = 'Microsoft Edge'; 108 version = nAgt.substring(verOffset + 5); 109 } 110 // MSIE 111 else if ((verOffset = nAgt.indexOf('MSIE')) != -1) { 112 browser = 'Microsoft Internet Explorer'; 113 version = nAgt.substring(verOffset + 5); 114 } 115 // Chrome 116 else if ((verOffset = nAgt.indexOf('Chrome')) != -1) { 117 browser = 'Chrome'; 118 version = nAgt.substring(verOffset + 7); 119 } 120 // Safari 121 else if ((verOffset = nAgt.indexOf('Safari')) != -1) {
122 browser = 'Safari'; 123 version = nAgt.substring(verOffset + 7); 124 if ((verOffset = nAgt.indexOf('Version')) != -1) { 125 version = nAgt.substring(verOffset + 8); 126 } 127 } 128 // Firefox 129 else if ((verOffset = nAgt.indexOf('Firefox')) != -1) { 130 browser = 'Firefox'; 131 version = nAgt.substring(verOffset + 8); 132 } 133 // MSIE 11+ 134 else if (nAgt.indexOf('Trident/') != -1) { 135 browser = 'Microsoft Internet Explorer'; 136 version = nAgt.substring(nAgt.indexOf('rv:') + 3); 137 } 138 // Other browsers 139 else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) { 140 browser = nAgt.substring(nameOffset, verOffset); 141 version = nAgt.substring(verOffset + 1); 142 if (browser.toLowerCase() == browser.toUpperCase()) { 143 browser = navigator.appName; 144 } 145 } 146 // trim the version string 147 if ((ix = version.indexOf(';')) != -1) 148 version = version.substring(0, ix); 149 if ((ix = version.indexOf(' ')) != -1) 150 version = version.substring(0, ix); 151 if ((ix = version.indexOf(')')) != -1) 152 version = version.substring(0, ix); 153 154 majorVersion = parseInt('' + version, 10); 155 if (isNaN(majorVersion)) { 156 version = '' + parseFloat(navigator.appVersion); 157 majorVersion = parseInt(navigator.appVersion, 10); 158 } 159 160 // mobile version 161 var mobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(nVer); 162 163 // cookie 164 var cookieEnabled = (navigator.cookieEnabled) ? true : false; 165 166 if (typeof navigator.cookieEnabled == 'undefined' && !cookieEnabled) { 167 document.cookie = 'testcookie'; 168 cookieEnabled = (document.cookie.indexOf('testcookie') != -1) ? true : false; 169 } 170 171 // system 172 var os = unknown; 173 var clientStrings = [ 174 {s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/}, 175 {s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/}, 176 {s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/}, 177 {s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/}, 178 {s: 'Windows Vista', r: /Windows NT 6.0/}, 179 {s: 'Windows Server 2003', r: /Windows NT 5.2/}, 180 {s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/}, 181 {s: 'Windows 2000', r: /(Windows NT 5.0|Windows 2000)/}, 182 {s: 'Windows ME', r: /(Win 9x 4.90|Windows ME)/}, 183 {s: 'Windows 98', r: /(Windows 98|Win98)/}, 184 {s: 'Windows 95', r: /(Windows 95|Win95|Windows_95)/}, 185 {s: 'Windows NT 4.0', r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/}, 186 {s: 'Windows CE', r: /Windows CE/}, 187 {s: 'Windows 3.11', r: /Win16/}, 188 {s: 'Android', r: /Android/}, 189 {s: 'Open BSD', r: /OpenBSD/}, 190 {s: 'Sun OS', r: /SunOS/}, 191 {s: 'Linux', r: /(Linux|X11)/}, 192 {s: 'iOS', r: /(iPhone|iPad|iPod)/}, 193 {s: 'Mac OS X', r: /Mac OS X/}, 194 {s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/}, 195 {s: 'QNX', r: /QNX/}, 196 {s: 'UNIX', r: /UNIX/}, 197 {s: 'BeOS', r: /BeOS/}, 198 {s: 'OS/2', r: /OS\/2/}, 199 {s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/} 200 ]; 201 for (var id in clientStrings) { 202 var cs = clientStrings[id]; 203 if (cs.r.test(nAgt)) { 204 os = cs.s; 205 break; 206 } 207 } 208 209 var osVersion = unknown; 210 211 if (/Windows/.test(os)) { 212 osVersion = /Windows (.*)/.exec(os)[1]; 213 os = 'Windows'; 214 } 215 216 try { 217 switch (os) { 218 case 'Mac OS X': 219 osVersion = /Mac OS X (11[\.\_\d]+)/.exec(nAgt)[1]; 220 break; 221 222 case 'Android': 223 osVersion = /Android ([\.\_\d]+)/.exec(nAgt)[1]; 224 break; 225 226 case 'iOS': 227 osVersion = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer); 228 osVersion = osVersion[1] + '.' + osVersion[2] + '.' + (osVersion[3] | 0); 229 break; 230 } 231 }catch(err) { 232 osVersion = unknown; 233 } 234 235 236 // flash (you'll need to include swfobject) 237 /* script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" */ 238 var flashVersion = 'no check'; 239 if (typeof swfobject != 'undefined') { 240 var fv = swfobject.getFlashPlayerVersion(); 241 if (fv.major > 0) { 242 flashVersion = fv.major + '.' + fv.minor + ' r' + fv.release; 243 } else { 244 flashVersion = unknown; 245 } 246 } 247 } 248 249 return { 250 screen: screenSize, 251 browser: browser, 252 browserVersion: version, 253 browserMajorVersion: majorVersion, 254 mobile: mobile, 255 os: os, 256 osVersion: osVersion, 257 cookies: cookieEnabled, 258 flashVersion: flashVersion 259 }; 260 }(this)); 261 $body.addClass('current-browser-' + os.browser.toLowerCase().replace(/\s+/g, '-')); 262 $body.addClass('current-os-' + os.os.toLowerCase().replace(/\s+/g, '-')); 263 264 //**To trigger the vpm.loaded event 265 eventTrigger(); 266 267 if ($body.hasClass('logged-in')) { 268 console.warn('Note: Never mind AJAX HTTP Drupal.error when logged in as admin. Affects only admin navigation bar. (Thierry Parent <[email protected]>)'); 269 } 270 setTimeout(function () { 271 $('#main').removeAttr('data-transition'); 272 273 //They have opacity 0 in template (or else the block loads wrong visually) ; 274 //Hiding them while the page loads, then turn opacity to 1 275 $('.top-header').css('opacity',1); 276 }, 1000); 277 278 // VPM FILTER 279 // ================================================== 280 281 /** 282 * @function vpmFilter() 283 * 284 * Filter elements from data-vpm-tag 285 * The data-vpm-tag data shouldbe entered as "foo bar" 286 * (separate with single space) 287 * 288 * @param tag {string|array} 289 * @param toDelete {boolean} 290 * 291 * @return jQuery 292 */ 293 var results = []; 294 var resultText = ' results found'; 295 if($('html').attr('lang') === 'fr') { 296 resultText = ' résultats trouvés'; 297 } 298 $.fn.vpmFilter = function (tag, toDelete) { 299 300 results = []; 301 toDelete = typeof toDelete !== 'undefined' && toDelete; 302 var deleted = []; 303 if (typeof tag == 'undefined') { 304 $(this).vpmShow(); 305 } else { 306 if (typeof tag == 'string') { 307 tag = [tag]; 308 } 309 $(this).each(function () { 310 var toHide = false;
311 for (var i in tag) { 312 if ($(this).data('vpm-tag')) { 313 314 var tags = $(this).data('vpm-tag'); 315 316 if (typeof tags == 'number') { 317 tags = tags.toString() 318 } 319 if (!(typeof $(this).data('vpm-no-split') != 'undefined' && $(this).data('vpm-no-split') == true)) { 320 tags = tags.split(' '); 321 } 322 if (tags.indexOf(tag[i]) == -1) { 323 toHide = true; 324 break; 325 } 326 } 327 } 328 if (toDelete) { 329 if (toHide) { 330 deleted.push($(this).remove()); 331 } 332 } else { 333 ((xor(toHide, tag.length == 0 && $(this).data('vpm-not-in-all'))) ? ($(this).vpmHide()) : ($(this).vpmShow(), results.push(this))); 334 } 335 }); 336 } 337 338 // Add number of results found into live-region area for screenreader 339 $('.activity-filter-live-region').html(results.length + resultText); 340 setTimeout(() => { 341 $('.activity-filter-live-region').html(''); 342 }, 3000); 343 //end 344 345 $(document).trigger('vpmFilterEnd', [deleted]); 346 if (toDelete) { 347 return deleted; 348 } 349 return $(this); 350 }; 351 352 /** 353 * @function vpmShow() 354 * 355 * Show jQuery elements with VPM custom animations 356 * 357 * @returns jQuery 358 */ 359 360 $.fn.vpmShow = function () { 361 $(this).each(function () { 362 $(this).removeClass('vpm-hidden'); 363 }); 364 return $(this); 365 }; 366 367 /** 368 * @function vpmHide() 369 * 370 * Hide jQuery elements with VPM custom animation 371 * 372 * @returns jQuery 373 */ 374 $.fn.vpmHide = function () { 375 $(this).each(function () { 376 $(this).addClass('vpm-hidden'); 377 }); 378 return $(this); 379 }; 380 381 /** 382 * @function vpmBeginFilter() 383 * 384 * Begin filter process 385 * Aggregate filter data to execute vpmFilter 386 * 387 * @return void 388 */ 389 $.fn.vpmBeginFilter = function (data) { 390 var filter = []; 391 if ($(this).hasClass('vpm-filter-multiple')) { 392 $('body').find('[data-filter-group="' + $(this).data('filter-group') + '"]').each(function () { 393 if ($(this).is('.vpm-filter-checkbox')) { 394 $(this).find('[type="checkbox"]:checked').each(function () { 395 filter.push($(this).data('vpm-tag')); 396 }); 397 } else { 398 filter.push($(this).find('.current').data('vpm-tag')); 399 } 400 }); 401 } else if ($(this).hasClass('vpm-filter-select')) { 402 filter = [$(this).find('select').val()]; 403 } else { 404 filter = [$(this).find('.current').data('vpm-tag')]; 405 } 406 for (var i = filter.length - 1; i >= 0; i--) { 407 if (filter[i] == '') 408 filter.splice(i, 1); 409 } 410 var toDelete = typeof data !== 'undefined' && data.hasOwnProperty('delete') && data.delete === true; 411 $($(this).data('vpm-target')).vpmFilter(filter, toDelete); 412 }; 413 414 /** 415 * @function filterByUrlParam() 416 * 417 * Filter by URL param filter 418 * 419 * @return void 420 */ 421 function filterByUrlParam (filterSelect) { 422 const queryString = window.location.search; 423 const urlParams = new URLSearchParams(queryString); 424 const filterValue = urlParams.get('filter') 425 if (!filterValue) { 426 return; 427 } 428 429 let $targetOpt = filterSelect.find("option[value='"+filterValue+"']"); 430 if ($targetOpt.length) { 431 filterSelect.val(filterValue).trigger("change"); 432 setTimeout(function () { 433 $('html, body').animate({ 434 scrollTop: (filterSelect.offset().top - 150) 435 }, 100); 436 }, 1000) 437 } 438 } 439 440 441 /** 442 * Trigger the filter on event 443 */ 444 $('.vpm-filter').on('dropdown-completed', function () { 445 $(this).vpmBeginFilter(); 446 }); 447 $('.vpm-filter [type="checkbox"]').on('change', function () { 448 449 $(this).parents('.vpm-filter').vpmBeginFilter(); 450 }); 451 452 $('.vpm-filter .filter-btn-submit').on('click', function () { 453 $(this).parents('.vpm-filter').vpmBeginFilter(); 454 }); 455 456 $('#filter-bar').on('change', function () { 457 $(this).parents('.vpm-filter').vpmBeginFilter(); 458 }); 459 460 /** 461 * Trigger the filter by URL param 462 */ 463 let filterSelect = $("#filter-bar"); 464 if (filterSelect.length) { 465 filterByUrlParam(filterSelect); 466 } 467 468 469 var lang = drupalSettings.vpm_d8.global.lang; 470 // Webform required fields 471 var requiredFields = $('.form-item .form-required'); 472 var requiredStar = '<span aria-hidden="true">*</span>' 473 requiredFields.each(function() { 474 if($(this).parents('#user-login-form').length) return; 475 $(this).append(requiredStar); 476 }); 477 478 // Webform select 479 var selects = $('select'); 480 selects.each(function() { 481 var select = $(this); 482 checkIfEmptySelected(select); 483 $(this).on('change', function(){ 484 checkIfEmptySelected(select); 485 }); 486 }); 487 function checkIfEmptySelected(select) { 488 if (select.children('option:selected').val() == '') { 489 select.addClass('empty-option-selected'); 490 } else { 491 select.removeClass('empty-option-selected'); 492 } 493 } 494 495 // Webform honeypot 496 var honeypots = $('.js-form-item-url'); 497 honeypots.each(function() { 498 $(this).find('input').attr('aria-hidden', true); 499 }); 500 501 // Webform validation 502 var webforms = $('form.webform-submission-form'); 503 webforms.each(function() { 504 var form = $(this); 505 form.on('submit', function() { 506 // Exception pour les datepickers 507 var requiredDatepickers = $(this).find('input.js-datepicker-input.required'); 508 requiredDatepickers.each(function() { 509 var datepickerWrapper = $('duet-date-picker.' + $(this).attr('id')); 510 var datepickerInput = datepickerWrapper.find('input'); 511 if (datepickerInput.val() === '') { 512 $(this).addClass('error'); 513 datepickerInput.addClass('error'); 514 if ($(this).closest('.form-item').find('label.error').length === 0) { 515 datepickerWrapper.after('<label class="error">' + $(this).attr('data-msg-required') + '</label>'); 516 } 517 errorMsg = $(this).attr('data-msg-required'); 518 } else { 519 $(this).removeClass('error'); 520 datepickerInput.removeClass('error'); 521 $(this).closest('.form-item').find('label.error').remove(); 522 errorMsg = ''; 523 } 524 }); 525 // Tous les autres champs 526 handleFormChange(form); 527 $('.errors-list-wrapper.' + form.attr('id') + ' .errors-list a')[0].focus(); 528 var fieldsInError = form.find('input.error'); 529 fieldsInError.each(function() { 530 if ($(this).attr('type') === 'checkbox' && $(this).closest('.checkboxes--wrapper').length > 0) { 531 $(this).closest('.checkboxes--wrapper').find('input').on('change', function() { 532 handleFormChange(form); 533 }); 534 } else { 535 $(this).on('change', function() { 536 handleFormChange(form); 537 }); 538 } 539 }); 540 }); 541 }); 542 543 function handleFormChange(form) { 544 var fieldsInError = form.find('input.error'); 545 var errorList = $('.errors-list-wrapper.' + form.attr('id') + ' .errors-list'); 546 if (errorList.length === 0) { 547 form.before('<div class="errors-list-wrapper ' + form.attr('id') + '"><p class="errors-list-title" aria-live="polite"></p><ul class="errors-list"></ul></div>'); 548 } else { 549 errorList.empty(); 550 } 551 var errorList = $('.errors-list-wrapper.' + form.attr('id')).find('.errors-list'); 552 fieldsInError.each(function() { 553 var errorMsg; 554 if ($(this).attr('type') === 'checkbox') { 555 $('.checkboxes--wrapper').removeClass('error'); 556 var inputParent = $(this).closest('.checkboxes--wrapper'); 557 var errorLabel = inputParent.find('label.error'); 558 if (inputParent.length > 0) {
559 if (inputParent.find('input:checked').length === 0) { 560 inputParent.addClass('error'); 561 errorMsg = errorLabel.text(); 562 errorLabel.prependTo(inputParent.find('.fieldset-wrapper')); 563 } else { 564 errorMsg = ''; 565 errorLabel.remove(); 566 $(this).removeClass('error'); 567 } 568 } else { 569 var checkboxParent = $(this).closest('.form-item'); 570 var checkboxLabel = checkboxParent.find('label.error') 571 checkboxLabel.appendTo(checkboxParent); 572 errorMsg = checkboxLabel.text(); 573 } 574 } else if ($(this).attr('type') === 'radio') { 575 var inputParent = $(this).closest('.radios--wrapper'); 576 var errorLabel = inputParent.find('label.error'); 577 errorMsg = errorLabel.text(); 578 errorLabel.prependTo(inputParent.find('.fieldset-wrapper')); 579 } else if ($(this).hasClass('js-datepicker-input')) { 580 var datepickerWrapper = $('duet-date-picker.' + $(this).attr('id')); 581 var datepickerInput = datepickerWrapper.find('input'); 582 if (datepickerInput.val() === '') { 583 datepickerInput.addClass('error'); 584 if ($(this).closest('.form-item').find('label.error').length === 0) { 585 datepickerWrapper.after('<label class="error">' + $(this).attr('data-msg-required') + '</label>'); 586 } 587 errorMsg = $(this).attr('data-msg-required'); 588 } else { 589 datepickerInput.removeClass('error'); 590 $(this).closest('.form-item').find('label.error').remove(); 591 errorMsg = ''; 592 } 593 } else { 594 errorMsg = $('#' + $(this).attr('id') + '-error').text(); 595 } 596 var alreadyInList = errorList.find('a:contains(' + errorMsg + ')').length > 0; 597 if (!alreadyInList) { 598 var inputId = $(this).attr('id') 599 if ($(this).hasClass('js-datepicker-input')) { 600 inputId = $('duet-date-picker.' + $(this).attr('id') + ' input').attr('id'); 601 } 602 errorList.append('<li><a href="#' + inputId + '">' + errorMsg + '</a></li>') 603 } 604 }); 605 var errorListTitle = lang === 'fr' 606 ? ('Il y a ' + errorList.find('li').length + ' erreur(s) dans le formulaire que vous avez soumis.') 607 : ('There are ' + errorList.find('li').length + ' error(s) in the form you have submitted.'); 608 $('.errors-list-wrapper.' + form.attr('id') + ' .errors-list-title').text(errorListTitle); 609 if (errorList.find('li').length === 0) { 610 $('.errors-list-wrapper.' + form.attr('id')).remove(); 611 } 612 } 613 614 // Datepicker 615 var datepickerFR = { 616 buttonLabel: 'Choisir une date', 617 placeholder: 'AAAA-MM-JJ', 618 selectedDateMessage: 'La date sélectionnée est', 619 prevMonthLabel: 'Mois précédent', 620 nextMonthLabel: 'Mois suivant', 621 monthSelectLabel: 'Mois', 622 yearSelectLabel: 'Année', 623 closeLabel: 'Fermer le calendrier', 624 calendarHeading: 'Choisissez une date', 625 dayNames: [ 'dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi' ], 626 monthNames: [ 'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre' ], 627 monthNamesShort: [ 'janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.' ], 628 locale: 'fr-CA', 629 }; 630 var datepickerEN = { 631 buttonLabel: 'Choose date', 632 placeholder: 'YYYY-MM-DD', 633 selectedDateMessage: 'Selected date is', 634 prevMonthLabel: 'Previous month', 635 nextMonthLabel: 'Next month', 636 monthSelectLabel: 'Month', 637 yearSelectLabel: 'Year', 638 closeLabel: 'Close datepicker', 639 calendarHeading: 'Choose a date', 640 dayNames: [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ], 641 monthNames: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], 642 monthNamesShort: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ], 643 locale: 'en-CA', 644 }; 645 646 function addDatePicker() { 647 $('.js-datepicker-input').each(function (index) { 648 var drupalInput = $(this); 649 var datePickerW = $('duet-date-picker.'+$(this).attr('id') ); 650 if (datePickerW.length) { 651 return; 652 } 653 drupalInput.hide(); 654 drupalInput.after('<duet-date-picker class="' + $(this).attr('id') + '" identifier="date-' + index + '"></duet-date-picker>'); 655 var dateInput = $('duet-date-picker[identifier="date-' + index + '"]'); 656 document.querySelector('duet-date-picker').localization = lang === 'fr' ? datepickerFR : datepickerEN; 657 658 dateInput.on('duetChange', function(e) { 659 drupalInput.val(e.detail.value); 660 drupalInput.trigger('change'); 661 }); 662 }); 663 } 664 addDatePicker(); 665 $(document).on("ajaxSuccess", () => { 666 addDatePicker(); 667 }); 668 669 // Form request a proposal (Event informations translation) 670 if (lang === 'fr') { 671 $('.form-item-field-form-event-name-0-value').each(function () { 672 $(this).addClass('fr'); 673 }); 674 } else { 675 $('.form-item-field-form-event-name-0-value').each(function () { 676 $(this).addClass('en'); 677 }); 678 } 679 680 // Form request a proposal WEBFORM (Event informations translation) 681 if (lang === 'fr') { 682 $('.form-item-event-name').each(function () { 683 $(this).addClass('fr'); 684 }); 685 } else { 686 $('.form-item-event-name').each(function () { 687 $(this).addClass('en'); 688 }); 689 } 690 691 // To open attached files in new tab 692 const extensions = [ 693 'jpg', 'jpeg', 'png', 'tif', 'tiff', 'pdf', 'doc', 'docx', 'slx', 'xlsx', 'txt' 694 ]; 695 for (var e = extensions.length - 1; e >= 0; e--) { 696 extensions.push(extensions[e].toUpperCase()); 697 } 698 $('a').each(function () { 699 var h = $(this).attr('href'); 700 if (h) { 701 for (var i = 0; i < extensions.length; i++) { 702 if (h.indexOf('.' + extensions[i]) > -1 && h.lastIndexOf('.' + extensions[i]) == h.length - extensions[i].length - 1) { 703 $(this).attr('target', '_blank'); 704 } 705 } 706 } 707 if (h == 'http://oldportofmontreal.us9.list-manage.com/subscribe?u=e1058dd30474f86b2670a9d6d&id=6be71292fc') { 708 if ($('html').attr('lang') == 'fr') { 709 $(this).attr('href', 'http://centredessciencesdemontreal.us9.list-manage.com/subscribe?u=e1058dd30474f86b2670a9d6d&id=eddd036aef'); 710 } 711 } 712 }); 713 714 var $inputNA = $('input[type="radio"][value="_none"]'); 715 if ($inputNA.length > 0) { 716 $inputNA.each(function () { 717 $(this).parent().hide(); 718 }); 719 } 720 /* 721 $('#user-login-form').on('submit', function(e){ 722 if(!this.hasAttribute('target')) { 723 e.preventDefault(); 724 var me = this; 725 var $frame = $(this).siblings('iframe'); 726 var originalAction = me.getAttribute('action'); 727 me.setAttribute('action', $frame.data('src')); 728 me.setAttribute('target', $frame.attr('name')); 729 me.submit(); 730 } 731 }) 732 */ 733 734 function getParkingData(data) { 735 var classes = { 736 success: 'parking-left-success', 737 warning: 'parking-left-warning', 738 danger: 'parking-left-danger', 739 full: 'parking-left-danger-max' 740 }; 741 742 var r = {}; 743 if (data.occupePourcentage < 50) { 744 r.class = classes.success; 745 r.label = '25%'; 746 } else if (data.occupePourcentage < 75) { 747 r.class = classes.warning; 748 r.label = '50%'; 749 } else if (data.occupePourcentage <= 90) { 750 r.class = classes.danger; 751 r.label = '75%'; 752 } else { 753 r.class = classes.full; 754 r.label = '>90%'; 755 } 756 switch (data.message) { 757 case 'OUVERT': 758 r.label = t('OPEN'); 759 break; 760 case 'FERME': 761 case 'FERMÃ': 762 r.label = t('CLOSED'); 763 break; 764 } 765 r.places = data.capacite; 766 return r; 767 } 768 769 function t(str) { 770 var lang = $('html').attr('lang'); 771 if (lang != 'en') { 772 var trans = { 773 // 'Occupancy rate lower than': 'Occupé à moins de', 774 // 'Occupancy rate higher than': 'Occupé à plus de', 775 'OPEN': 'OUVERT', 776 'CLOSED': 'FERMÃ', 777 'Limited places': 'Places limitées' 778 }; 779 if (trans.hasOwnProperty(str)) { 780 return trans[str]; 781 } 782 } 783 return str; 784 } 785 786 $('body.svpm-microsite').find('.accordion-content.description p').each(function(){ 787 788 if($(this).text() == "Rien à déclarer" || $(this).text() == "Nothing to report"){ 789 $(this).parent().prev('h5').addClass('header-deactivate'); 790 } 791 }); 792 793 //Starts accordions 794 $('.accordion-start').each(function () { 795 $(this).accordion({active: false, collapsible: true, heightStyle: 'content'}); 796 }); 797 $('.menu-accordion').each(function () { 798 $(this).accordion({ 799 active: false, 800 heightStyle: 'content', 801 collapsible: true, 802 classes: null, 803 }); 804 }); 805 $('.accordion-start03').each(function () { 806 $(this).accordion({active: false, collapsible: true, heightStyle: 'content'}); 807 }); 808 809 $('.visitor-accordion .accordion-start03 > h2').addClass('accordion-title'); 810 $('.visitor-accordion .accordion-start03 > div').addClass('accordion-content'); 811 812 813 //Page hall rentals (v2) 814 //adds classes to Capacities table (for CSS) 815 816 $('.location-salles-table .custom-cell span a').each(function(){ 817 $(this).parent().parent('.custom-cell').addClass('link-cell'); 818 819 if($('html').attr('lang') == 'en') { 820 $(this).text('See the plan'); 821 }else { 822 $(this).text('Voir le plan'); 823 } 824 }); 825 826 //Hall rentals capacities table 827 //Check text in first cell to add corresponding class (for icon) 828 var configurations_machine_name = ['cocktail','banquet','theatre','school','conference','u','square','booth']; 829 var configurations_en = ['Cocktail','Banquet','Theatre','School','Conference','U shape','Square shape','Booth']; 830 var configurations_fr = ['Cocktail','Banquet','Théâtre','Ãcole','Conférence','Style U','Style carré','Kiosque']; 831 $('.location-salles-table').find('.custom-cell').each(function(){ 832 if($('html').attr('lang') == 'en') { 833 for (var i = 0; i < configurations_en.length; i++) { 834 if($(this).text().indexOf(configurations_en[i]) !== -1){ 835 $(this).addClass('config-'+configurations_machine_name[i]); 836 } 837 } 838 }else { 839 for (var i = 0; i < configurations_fr.length; i++) { 840 if($(this).text().indexOf(configurations_fr[i]) !== -1){ 841 $(this).addClass('config-'+configurations_machine_name[i]); 842 } 843 } 844 } 845 }); 846 847 //Remove the 'prefooter' (social medias) in hall rentals pages 848 $noPreFooterClasses = ['node-type-halls_v2','node-1794','node-1795','node-1796','node-1797','node-1798'] 849 for (var i = 0; i < $noPreFooterClasses.length; i++){ 850 if($('body').hasClass($noPreFooterClasses[i])){ 851 $('.pre-footer').css('display','none'); 852 } 853 } 854 855 //Adds wrapper to press room images 856 $('.press-room-picture').parent().wrap('<div class="image-wrapper"></div>'); 857 $('.image-link.first-link').each(function(){ 858 $(this).next('.image-link').addBack().wrapAll('<div class="image-full"></div>'); 859 }); 860 $('.image-full .image-link:not(".first-link")').each(function(){ 861 $(this).attr('download',true); 862 }); 863 864 //Custom block 'important message' close on click 865 $('.block-important-message .important-message-close').on('click', function(){ 866 $(this).parents('.block-important-message').addClass('important-message-hidden'); 867 $(this).parents('.block-important-message').fadeOut(200); 868 }); 869 870 setNavigation(); 871 872 873 874 // ****** Début Solution for node link translation in views display- Don't remove It *****// 875 var currentLang = $('html')[0].lang;
876 /// **************Caroussel - 1- ATTRAIT *****************// 877 var labelLink =$('.hide-labelLink').first().text(); 878 $('.hide-labelLink a').addClass('btn-test'); 879 $('.hide-labelLink').vpmHide(); 880 881 /// **************Caroussel - 1- EVENT *****************// 882 $('.custom-carousel-1-link-event').each(function() { 883 var labelLink_event =$(this).find('.hide-labelLink-event').html(); 884 var link = $(this).find('a'); 885 link.addClass('btn-1'); 886 link.html(labelLink_event); 887 $(this).find('.hide-labelLink a').addClass('btn-test'); 888 $(this).find('.hide-labelLink-attrait').vpmHide(); 889 }); 890 // ****** FIN Solution for node link translation in views display- Don't remove It *****// 891 892 }; 893 $(document).ready(function () { 894 $('body').onPageLoadMain(); 895 var lang = $('html').attr('lang'); 896 if ($('.rc-anchor-center-container').length && lang == 'fr') { 897 $('.rc-anchor-center-container').find('rc-anchor-center-item.rc-anchor-checkbox-label').text('Je ne suis pas un robot'); 898 } 899 }); 900 $(document).on('reCaptchaLoaded', function () { 901 loadReCaptcha(); 902 }); 903 904 //** Determines if IE or other browser 905 //** IE need Custom event to trigger 906 function eventTrigger(){ 907 908 if ( typeof window.CustomEvent === "function" && os.browser != 'Microsoft Internet Explorer') { 909 document.body.dispatchEvent(new Event('vpm.loaded')); 910 return false; 911 } //If not IE 912 913 function CustomEvent ( event, params ) { 914 params = params || { bubbles: false, cancelable: false, detail: undefined }; 915 var evt = document.createEvent( 'vpm.loaded' ); 916 evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); 917 return evt; 918 } 919 920 CustomEvent.prototype = window.Event.prototype; 921 window.CustomEvent = CustomEvent; 922 } 923 924 function loadReCaptcha() { 925 var $reCaptcha = $('.g-recaptcha'); 926 if ($reCaptcha.length) { 927 $reCaptcha.each(function () { 928 grecaptcha.render($(this)[0], { 929 'sitekey': $(this).data('sitekey') 930 }); 931 }); 932 } 933 } 934 935 //SVPM MICROSITE OR HALL RENTALS -- Checks URL to add 'active' class on menu item 936 function setNavigation() { 937 var path = window.location.pathname; 938 939 $('#block-svpm-menu-header a, #block-svpm-menu-header-mobile a').each(function () { 940 var element = $(this); 941 var link = $(this).attr('href'); 942 var rightLink = link.indexOf(path); 943 944 if (rightLink != -1 && path != '/') { 945 element.parent().addClass('active'); 946 } 947 }) 948 949 $('#location-menu a').each(function () { 950 var element = $(this); 951 var link = $(this).attr('href'); 952 var path2 = path+'/'; 953 var rightLink = link.indexOf(path); 954 var wrongLink = link.indexOf(path2); 955 956 if (rightLink != -1 && path != '/' && wrongLink == -1) { 957 element.parent().addClass('active'); 958 } 959 }) 960 } 961 962 function accordeonClass() { 963 if ($(window).width() <= 991 - 15) { 964 $('.accordion-start02').each(function () { 965 $(this).accordion({active: 1, heightStyle: 'content'}); 966 }); 967 $(".acc-detail").removeClass("details"); 968 //$('.description').addClass('hidden-mobile'); 969 } else { 970 var isAccordion = $(".accordion-start02").hasClass("ui-accordion"); 971 if (isAccordion) { 972 $(".accordion-start02").accordion("destroy"); 973 } 974 $('.accordion-start02 .accordion-title').addClass('acc-title'); 975 $('.accordion-start02 .accordion-content').addClass('acc-content'); 976 $(".acc-detail").addClass("details"); 977 } 978 } 979 980 $(window).on('load',function(){ 981 accordeonClass(); 982 }); 983 $(window).resize(function () { 984 accordeonClass(); 985 }); 986 987 988 989})(jQuery); 990 991function xor(cond1, cond2) { 992 return (!cond1 && cond2) || (cond1 && !cond2); 993} 994/* Accessibilité */ 995function changeState(e) { 996 const keyCode = e.keyCode; 997 if (!keyCode || keyCode === 9 || keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) { 998 if (document.documentElement.getAttribute('data-state') !== e.type) { 999 document.documentElement.setAttribute('data-state', e.type); 1000 } 1001 } 1002} 1003 1004window.addEventListener('keydown', changeState); 1005window.addEventListener('mousemove', changeState);
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.