1/*************************************************************************/ 2/********************** FIX POWERMAIL IN POPINS **************************/ 3/*************************************************************************/ 4 5const APP_DEV_CONF = { 6 autoscroll_offset: 90, 7 anim_duration: 250, 8}; 9 10// il faut le paramêtre 'e' pour pouvoir initialiser powermail, ne pas changer l'event donc 11$(document).ready(function (e) { 12 13 let formUri = undefined; 14 let contentTitle = undefined; 15 let jobReference = undefined; 16 17 // POWERMAIL - Initialize again powermail 18 let setupForms = function ($el, isPopin) { 19 20 /** 21 * Scroll smoothly to given anchor 22 * 23 * @param $anchor jQuery element 24 */ 25 let scrollToAnchor = function ($anchor) { 26 let offset = 0; 27 let $scrolledElement = $("html"); 28 if (isPopin) { 29 if (Foundation.MediaQuery.current === "small") { 30 $scrolledElement = $el; 31 offset = $anchor.offset().top + $scrolledElement.scrollTop(); 32 } else { 33 $scrolledElement = $el.closest($('.reveal-overlay')); 34 offset = $anchor.offset().top + $scrolledElement.scrollTop(); 35 } 36 } else { 37 offset = $anchor.offset().top - $("#data-sticky-header").outerHeight(); 38 } 39 offset -= APP_DEV_CONF.autoscroll_offset; 40 41 $scrolledElement.animate({ 42 scrollTop: offset, 43 }, 250); 44 }; 45 46 let $form = $el.find('form.powermail_form, form.form-parsley-validation'); 47 48 // return if no form to set up 49 if ($form.length === 0) 50 return; 51 52 let $submit = $form.find('input[type="submit"], button[type="submit"]'); 53 let $loader = $form.find('.loading_div .sk-circle'); 54 // is powermail using parsley 55 let isParsleyPowermail = ($form.attr('data-parsley-validate') !== undefined); 56 // is powermail using its own version of parsley-like front validation 57 let isLatestPowermail = ($form.attr('data-powermail-validate') !== undefined); 58 // is it a powermail form ? 59 let isPowermail = (isParsleyPowermail || isLatestPowermail); 60 61 // Job 62 let $contentTitle = $el.find("#powermail_field_contenttitle"); 63 let $jobReference = $el.find("#powermail_field_jobreference"); 64 65 // Elected 66 let $electedSelect = $el.find('#powermail_field_eluemail'); 67 let $electedTitle = $el.find("#powermail_field_elutitle"); 68 69 let formUriTemp = $('#formContentUri').val() || undefined; 70 let contentTitleTemp = $('#contentTitle').val() || undefined; 71 let jobReferenceTemp = $('#jobReference').val() || undefined; 72 73 if (formUriTemp !== undefined && formUriTemp !== '') { 74 formUri = formUriTemp; 75 } 76 77 if (contentTitleTemp !== undefined && contentTitleTemp !== '') { 78 contentTitle = contentTitleTemp; 79 } 80 81 if (jobReferenceTemp !== undefined && jobReferenceTemp !== '') { 82 jobReference = jobReferenceTemp; 83 } 84 85 if ($electedSelect.find('option:selected').length) { 86 $electedTitle.val($electedSelect.find('option:selected').get(0).text); 87 } 88 89 /** 90 * Form accessibility for latest version of powermail (^10.0) 91 * 92 * @param focusOnError 93 */ 94 let updateFormAccessibility = function (focusOnError) { 95 let formHasErrors = false; 96 97 // update field accessibility 98 $form.find('.powermail_field').each(function () { 99 let $field = $(this); 100 let $wrapper = $field.parents('.powermail_fieldwrap'); 101 let $input = $field.find('input, textarea, select'); 102 let id = $input.attr('id'); 103 let idErrors = id + '_errors'; 104 let $errorsWrapper = $wrapper.find('.parsley-errors-list, .powermail-errors-list'); 105 let hasErrors = $errorsWrapper.hasClass('filled'); 106 107 if (hasErrors) { 108 formHasErrors = true; 109 } 110 111 $input 112 .attr('aria-describedby', idErrors) 113 .attr('aria-invalid', hasErrors); 114 $errorsWrapper 115 .attr('id', idErrors) 116 .attr('aria-live', 'polite') 117 .attr('aria-hidden', !hasErrors) 118 .addClass('parsley-errors-list'); 119 $errorsWrapper.find('li') 120 .addClass('parsley-required'); 121 }); 122 123 // scroll to first error 124 if (focusOnError && formHasErrors) { 125 let $firstField = $form.find('.parsley-errors-list li, .powermail-errors-list li').eq(0).parents('.powermail_fieldwrap'); 126 let $anchor = $firstField.find('label').eq(0); 127 let $input = $firstField.find('input, textarea, select').eq(0); 128 129 $input.select(); 130 scrollToAnchor($anchor) 131 } 132 133 return formHasErrors; 134 } 135 136 // $form setup / override initialization 137 if ($form.length > 0) { 138 139 // update ajax uri 140 if (formUri !== undefined && isPowermail) { 141 $form 142 .attr('action', formUri) 143 .attr('data-powermail-ajax-uri', formUri); 144 $submit.prop('disabled', false); 145 $loader.addClass('hide is-hidden'); 146 } 147 148 if (isLatestPowermail) { 149 150 updateFormAccessibility(false); 151 152 $form.find('.powermail_field input, .powermail_field textarea, .powermail_field select') 153 .on('change blur', function () { 154 setTimeout(function () { 155 updateFormAccessibility(false); 156 }, 1); 157 }); 158 159 $form.on('submit', function () { 160 setTimeout(function () { 161 let formHasErrors = updateFormAccessibility(true); 162 163 if (!formHasErrors) { 164 $submit.prop('disabled', true); 165 $loader.removeClass('hide is-hidden'); 166 } else { 167 $submit.prop('disabled', false); 168 $loader.addClass('hide is-hidden'); 169 } 170 }, 1); 171 }); 172 173 } 174 175 // for parsley validation 176 if ((!isLatestPowermail || isPopin) && $.fn.parsley) { 177 $form.parsley(); 178 } 179 180 // form js validation: success 181 $form.on('form:success', function (formInstance) { 182 183 // on désactive le submit 184 $submit.prop('disabled', true); 185 $loader.removeClass('hide is-hidden'); 186 187 // scroll seulement si powermail à cause du callback de l'ajax de powermail 188 if (isPowermail) { 189 // on retire les erreurs sinon on ne peut pas envoyer de nouveau le formulaire (pb init icheck) 190 $('.powermail_message').remove(); 191 192 let interval = setInterval(function () { 193 194 let $anchor = $el.find('.powermail_create, .powermail_message'); 195 196 if ($anchor.length > 0) { 197 $anchor = $anchor.eq(0); 198 199 // init icheck 200 $el.find('.ligne_form.checkbox input, .ligne_form.radio input, .powermail_field .checkbox input, .powermail_field .radio input').iCheck({ 201 checkboxClass: 'icheckbox icheckbox_minimal', 202 radioClass: 'iradio iradio_minimal' 203 }); 204 205 // on bind de nouveau 206 setupForms($el, isPopin); 207 scrollToAnchor($anchor); 208 clearInterval(interval); 209 } 210 }, 50); 211 } 212 }); 213 214 // form js validation: error 215 $form.on('form:error', function (formInstance) { 216 217 // on active le submit 218 $submit.prop('disabled', false); 219 $loader.addClass('hide is-hidden'); 220 221 let $anchor = $form.find('.parsley-errors-list.filled, .powermail-errors-list.filled'); 222 223 if ($anchor.length) { 224 $anchor = $anchor.eq(0).closest('.powermail_fieldwrap, .femanager_fieldset, .ligne_form').eq(0); 225 let $input = $anchor.find('input, textarea, select'); 226 $input.select(); 227 scrollToAnchor($anchor); 228 } 229 230 }); 231 232 // form checkboxes : icheck 233 $form.find('.ligne_form.checkbox input, .ligne_form.radio input, .powermail_field .checkbox input, .powermail_field .radio input').iCheck({ 234 checkboxClass: 'icheckbox icheckbox_minimal', 235 radioClass: 'iradio iradio_minimal' 236 }); 237 } 238 239 if (isPowermail) { 240 if ($contentTitle.length > 0 && contentTitle !== undefined) { 241 $contentTitle 242 .val(contentTitle) 243 .prop('readonly', true); 244 } 245 246 if ($jobReference.length > 0 && jobReference !== undefined) { 247 $jobReference 248 .val(jobReference) 249 .prop('readonly', true); 250 } 251 252 if ($form.length > 0 && formUri !== undefined && isPopin) { 253 254 $(document).unbind('submit', 'form[data-parsley-ajax], form[data-powermail-ajax]'); 255 $(document).off('submit', 'form[data-parsley-ajax], form[data-powermail-ajax]'); 256 257 if ($el.attr('id') === 'popin_detail' || $el.attr('id') === 'popin_elu') { 258 if (typeof window.PowermailForm !== 'undefined') { 259 let form = new window.PowermailForm($); 260 form.initialize(); 261 } 262 } 263 } 264 265 // The return from the powermail confirmation page (POST) 266 // by settings the field's value from the url params 267 let updateFormActionFromUrlParams = function () { 268 // get url params list 269 const currentUriSegments = window.location.search.split('?'); 270 const currentQueryString = currentUriSegments[1]; 271 const currentUrlParams = new URLSearchParams(currentQueryString); 272 273 // set the input values from url params 274 for (const key of currentUrlParams.keys()) { 275 let $input = $form.find('[name="tx_powermail_pi1[field][' + key + ']"]'); 276 $input.val(currentUrlParams.get(key)); 277 } 278 }; 279 updateFormActionFromUrlParams(); 280 281 } 282 283 updatePowermailFormActions(); 284 } 285 286 setTimeout(function () { 287 setupForms($('#content_page'), false); 288 }, 10); 289 290 // POWERMAIL - Fix: When form is loaded in popins, the JS for powermail is not triggered 291 $(document).on('open.zf.reveal', '[id^="popin_"]', function () { 292 let $popin = $(this); 293 setTimeout(function () { 294 setupForms($popin, true); 295 }, 200); 296 }); 297 298 // disabled des boutons "Modifier" et "Confirmer" sur la page de confirmation des formulaires powermail 299 $(document).on('click', '.powermail_confirmation form input[type="submit"]', function () { 300 setTimeout(function () { 301 $('.powermail_confirmation form input[type="submit"]').prop('disabled', true); 302 }, 10); 303 }); 304 305 /** 306 * Remplace les attributs action des formulaires powermail afin d'éviter les erreurs sur page de confirmation 307 * quand module posé sur une page de détail (candidature à une offre, contact élu...) 308 */ 309 const updatePowermailFormActions = function () { 310 let formUriForm = $('#formContentUri_form').val() || undefined; 311 let formUriConfirmation = $('#formContentUri_confirmation').val() || undefined; 312 let formUriCreate = $('#formContentUri_create').val() || undefined; 313 314 $('input.powermail_form_action').each(function () { 315 let $input = $(this); 316 let $form = $input.parents('form'); 317 let type = $input.val(); 318 319 if (type === 'form' && formUriForm !== undefined) { 320 $form.attr('action', formUriForm, $form); 321 $form.attr('data-powermail-ajax-uri', formUriForm, $form); 322 } else if (type === 'confirmation' && formUriConfirmation !== undefined) { 323 $form.attr('action', formUriConfirmation, $form); 324 $form.attr('data-powermail-ajax-uri', formUriConfirmation, $form); 325 } else if (type === 'create' && formUriCreate !== undefined) { 326 $form.attr('action', formUriCreate, $form); 327 $form.attr('data-powermail-ajax-uri', formUriCreate, $form); 328 } 329 }); 330 }; 331 332 /** 333 * 334 */ 335 let updatePowermailReadonlyFields = function () { 336 $("#powermail_field_jobreference").prop('readonly', true); 337 $("#powermail_field_contenttitle").prop('readonly', true); 338 }; 339 340 /** 341 * Retire l'attribut required des champs fichier* lorsque revient sur le formulaire après confirmation 342 */ 343 let updateFileInputToAvoidConfirmationErrors = function () { 344 $('.powermail_file').each(function () { 345 let $parent = $(this).closest('div'); 346 let fileExist = $parent.find('.powermail_fieldwrap_file_list').length > 0; 347 if (fileExist) { 348 $(this).prop('required', false); 349 $parent.find('.powermail_fieldwrap_file_list').remove(); 350 } 351 }); 352 }; 353 354 // on form inserted into DOM 355 $(document).on('DOMNodeInserted', function (e) { 356 let $form = $(e.target); 357 if ($form.hasClass('powermail_form') || $form.hasClass('powermail_confirmation')) { 358 updatePowermailFormActions(); 359 updatePowermailReadonlyFields(); 360 updateFileInputToAvoidConfirmationErrors(); 361 362 let PowermailForm = new window.PowermailForm($); 363 PowermailForm.initialize(); 364 365 // scroll to top of the form 366 let $anchor = $form; 367 let isPopin = ($form.parents('[id^="popin_"]').length === 0); 368 let offset = 0; 369 let $scrolledElement = $("html"); 370 if (isPopin) { 371 if (Foundation.MediaQuery.current === "small") { 372 $scrolledElement = $el; 373 offset = $anchor.offset().top + $scrolledElement.scrollTop(); 374 } else { 375 $scrolledElement = $el.closest($('.reveal-overlay')); 376 offset = $anchor.offset().top + $scrolledElement.scrollTop(); 377 } 378 } else { 379 offset = $anchor.offset().top - $("#data-sticky-header").outerHeight(); 380 } 381 offset -= APP_DEV_CONF.autoscroll_offset; 382 383 setTimeout(function () { 384 $scrolledElement.animate({ 385 scrollTop: offset, 386 }, 1000); 387 }, APP_DEV_CONF.anim_duration); 388 } 389 }); 390}); 391 392/*************************************************************************/
393/************************ FIX POWERMAIL DATEPICKER ***********************/ 394/*************************************************************************/ 395 396$(document).bind('_js_ready popin', function () { 397 398 /** 399 * cim_form 400 * correction de l'URL de l'action du form, dans une page détail (autre plugin) 401 * car les params de l'autre plugin sont écrasés 402 */ 403 $('.cim_form').each((i,form) => { 404 const $form = $(form) 405 const currentUrlWithoutParams = window.location.href.split('?')[0] ?? '' 406 const actionUrlParams = $form.attr('action').split('?')[1] ?? '' 407 const mergedUrl = `${currentUrlWithoutParams}?${actionUrlParams}` 408 $form.attr('action', mergedUrl) 409 }) 410 411 $(function () { 412 // fix for IE : remove the default browser datepicker 413 $('.powermail_date') 414 .datepicker('destroy') 415 .click(function (e) { 416 e.preventDefault(); 417 }) 418 .fdatepicker({ 419 format: 'dd/mm/yyyy', 420 language: 'fr', 421 disableDblClickSelection: true 422 }); 423 // remove the default IE datepicker 424 $('.xdsoft_timepicker, .xdsoft_datetimepicker').remove(); 425 }); 426}); 427 428/*************************************************************************/ 429/****************** POWERMAIL - INITIALIZE FDATEPICKER *******************/ 430/*************************************************************************/ 431const initializePowermailDatepicker = function (selector) { 432 const initializedClass = 'datepicker-initialized'; 433 434 $(selector).each(function () { 435 let $field = $(this); 436 437 if (!$field.hasClass(initializedClass)) { 438 let type = $field.attr('data-type'); 439 let isDatetime = (type === 'datetime' || type === 'datetime-local'); 440 let isTime = type === 'time'; 441 let startView = 2; 442 443 // date 444 let format = 'dd/mm/yyyy'; 445 446 // date & time 447 if (isDatetime) { 448 format = 'dd/mm/yyyy hh:ii'; 449 } 450 451 // time 452 if (type === 'time') { 453 format = 'hh:ii'; 454 startView = 0; 455 } 456 457 let config = { 458 language: 'fr', 459 format: format, 460 disableDblClickSelection: true, 461 weekStart: 1, 462 pickTime: (isDatetime || isTime), 463 startView: startView, 464 }; 465 466 $field 467 .datepicker('destroy') 468 .fdatepicker(config) 469 .addClass(initializedClass); 470 } 471 }); 472}; 473$(document).on('_page_ready popin', function () { 474 initializePowermailDatepicker('.field_date'); 475}); 476$(document).on('DOMSubtreeModified', '.tx-powermail', function () { 477 initializePowermailDatepicker('.field_date'); 478}); 479 480/*************************************************************************/ 481/************************* POWERMAIL VALIDATION **************************/ 482/*************************************************************************/ 483 484$(document).bind('_js_ready', function () { 485 /** 486 * Add accessibility attributes on invalid field 487 * 488 * @since 1.5.0.9 489 */ 490 window.Parsley.on('field:error', function () { 491 this.$element.attr('aria-describedby', this._ui.errorsWrapperId).attr('aria-invalid', 'true'); 492 this._ui.$errorsWrapper.attr('aria-live', 'polite'); 493 }); 494 495 /** 496 * If field is valid and was marked invalid, remove aria.invalid 497 * 498 * @since 1.5.0.9 499 */ 500 window.Parsley.on('field:success', function () { 501 if (this.$element.attr('aria-invalid')) { 502 this.$element.removeAttr('aria-invalid'); 503 } 504 }); 505}); 506 507/*************************************************************************/ 508/******************** FIX POWERMAIL - QUALITY TOKEN **********************/ 509/*************************************************************************/ 510$('.tx-powermail').on('submitted.powermail.form', function () { 511 var url = window.location.href + "/?type=620&tx_cimquality_displayquality%5Baction%5D=generateNewToken"; 512 $.ajax({ 513 type: 'POST', 514 url: url, 515 contentType: false, 516 processData: false, 517 success: function (data) { 518 var newToken = data.newToken; 519 $("input[name='tx_cimquality_displayquality[token]']").val(newToken); 520 } 521 }); 522}) 523 524/*************************************************************************/ 525/******************** SF_REGISTER - SCROLL ON ERROR *********-************/ 526/*************************************************************************/ 527$(document).on("_page_ready", function () { 528 setTimeout(function () { 529 let $error = $('.tx_evoweb_sfregister .errorMessage'); 530 531 if ($error.length) { 532 533 let $anchor = $error.parents('.ligne_form'); 534 535 let offset = 0; 536 let $scrolledElement = $("html"); 537 offset = $anchor.offset().top - $("#data-sticky-header").outerHeight() - 60; 538 539 $scrolledElement.animate({ 540 scrollTop: offset, 541 }, APP_DEV_CONF.anim_duration); 542 543 } 544 }, 500); 545}); 546 547/*************************************************************************/ 548/****************** PAUSE VIDEO WHEN VIDEO START PLAYING *****************/ 549/*************************************************************************/ 550 551$(document).on("_page_ready", function () { 552 $(document).on('beforeChange', '.slider-for-videos', function (event, slick, currentSlide, nextSlide) { 553 554 let $containerSlide = $(this).find('.bloc_video_cont[data-slick-index="' + currentSlide + '"]'); 555 556 // pause the video 557 let $iframe = $containerSlide.find('iframe'); 558 let $video = $containerSlide.find('video'); 559 560 if ($iframe.length) { 561 562 // youtube 563 $iframe[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*'); 564 565 // vimeo 566 $iframe[0].contentWindow.postMessage('{"method":"pause"}', '*'); 567 568 // dailymotion 569 $iframe[0].contentWindow.postMessage('{"command":"pause","parameters":[]}', "*"); 570 571 } else if ($video && $video[0] !== undefined) { 572 573 // <video> native 574 $video[0].pause(); 575 576 } 577 }); 578}); 579 580 581/*************************************************************************/ 582/************************* ACCESSIBILITY POPIN ***************************/ 583/*************************************************************************/ 584 585// Formulaire: Ecrire à un élu
586// Marker champs email (typoscript + lib.listeElus): eluemail 587// Marker champs nom (hidden): elutitle 588 589$(document).on('_page_ready', function () { 590 $(document).on('change', '#powermail_field_eluemail', function () { 591 let $fieldEmail = $(this); 592 let $fieldTitle = $('#powermail_field_elutitle'); 593 594 if ($fieldTitle.length) { 595 let $selected = $fieldEmail.find('option:selected'); 596 $fieldTitle.val($selected.text()); 597 } 598 }); 599}); 600 601 602/*************************************************************************/ 603/******************************** CKEDITOR *******************************/ 604/*************************************************************************/ 605 606$(document).on('_page_ready', function () { 607 if (typeof ClassicEditor !== 'undefined') { 608 let allEditors = document.querySelectorAll('.form_ckeditor'); 609 for (let editorId = 0; editorId < allEditors.length; ++editorId) { 610 ClassicEditor 611 .create(allEditors[editorId], { 612 toolbar: ['heading', '|', 'bold', 'link', 'bulletedList', 'numberedList', 'blockQuote'], 613 heading: { 614 options: [ 615 {model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph'}, 616 {model: 'heading2', view: 'h2', title: 'Titre 2', class: 'ck-heading_heading2'}, 617 {model: 'heading3', view: 'h3', title: 'Titre 3', class: 'ck-heading_heading3'}, 618 ] 619 } 620 }) 621 .then(function (editor) { 622 }) 623 .catch(function (error) { 624 console.error(error); 625 }); 626 } 627 } 628}); 629 630 631/*************************************************************************/ 632/*************************** EMAIL PROTECTION ****************************/ 633/*************************************************************************/ 634 635$(document).bind('_js_ready popin', function () { 636 $('span.at').replaceWith("@"); 637 $('span.dot').replaceWith("."); 638}); 639 640// correction d'un bug en page de détail quand on fait retour après un F5 sur une popin liste : 641// l'url change mais on reste en page détail 642$(window).on('popstate', function () { 643 if (typeof list === 'undefined' && window.location.hash === '') { 644 window.location = window.location.href; 645 } 646}); 647 648/*************************************************************************/ 649/**************************** FIX HUNT POPIN *****************************/ 650/*************************************************************************/ 651 652$(window).scroll(function () { 653 $(document).trigger('_scroll'); 654}); 655 656$('#list_items, #first_display_carto, #first_display').scroll(function () { 657 $(document).trigger('_scroll'); 658}); 659 660$(window).on("load", function () { 661 662 var scroll; 663 664 $("#filters, #list_items, #first_display_carto, .reveal-overlay").scroll(function () { 665 if (typeof scroll !== "undefined") { 666 clearTimeout(scroll); 667 } 668 669 scroll = setTimeout(function () { 670 let images = document.querySelectorAll('img.lazy'); 671 let observer = new Hunt(images, { 672 enter: function (image) { 673 image.src = image.dataset.src; 674 } 675 }); 676 }, 25); 677 }); 678});
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.