1setMediaClass(); 2 3$(document).ready(function () 4{ 5 // Liens 6 Link.initClickHandlers(); 7 8 // Prog Aff 9 const hashParams = new URLSearchParams(window.location.hash.slice(1)); 10 const ref = hashParams.get('ref'); 11 12 if (ref && $.isNumeric(ref)) 13 { 14 const fullUrl = window.location.href; // avec le hash 15 const referer = document.referrer; // meilleure chance dâavoir le vrai referer 16 17 $.ajax({ 18 url: '/actions/check-aff.php', 19 type: 'POST', 20 data: { 21 ref : ref, 22 url : fullUrl, 23 referer : referer 24 }, 25 success: function(response) {}, 26 error: function(err) {} 27 }); 28 } 29 30 // Simple media querie usage 31 $(window).on('resize',function(){setMediaClass();}); 32 33 // GTA TAGS 34 // Listing produits 35 if ( Object.keys(gtagItems).length > 0 ) 36 { 37 var gtagListOption = { 38 action : 'view_item_list', 39 items : Object.values(gtagItems), 40 }; 41 $('body').gtagEvent(gtagListOption); 42 } 43 44 // Clic sur zone 45 $('body').on('click','*[data-gtclick]', function(ev) 46 { 47 var datas = $(this).data('gtclick').split('|'), 48 envDatas = {event: 'block', type : datas[0],name : datas[1]}; 49 50 console.log(envDatas); 51 dataLayer.push(envDatas); 52 }); 53 54 // Select Prod 55 $('body').off('click','.zProd a[href!=""]'); 56 $('body').on('click','.zProd a[href!=""]',function(ev) 57 { 58 var el = $(this), 59 box = el.closest('.zProd'), 60 zone = box.data('zone'), 61 id = box.data('id'); 62 63 // Launch 64 sessionStorage.setItem('gtagItemList',zone); 65 gtagOption = {'action':'select_item','items':[gtagItems[id]]}; 66 $('body').gtagEvent(gtagOption); 67 }); 68 69 // Toggle 70 $('[data-toggle]').each(function () 71 { 72 var $trigger = $(this); 73 74 // Ajouter la classe 75 $trigger.addClass('toggleClickElement'); 76 77 // Découper les sélecteurs 78 var selectors = ($trigger.attr('data-toggle') || '') 79 .trim() 80 .split('|') 81 .map(function (s) { return s.trim(); }) 82 .filter(Boolean); 83 84 // Récupérer toutes les cibles uniques 85 var $targets = $(); 86 selectors.forEach(function (sel) 87 { 88 var $t = $trigger.closest(sel); 89 90 if ($t.length === 0) 91 $t = $trigger.nextAll(sel).first(); 92 93 if ($t.length) 94 $targets = $targets.add($t); 95 }); 96 97 $targets = $targets.filter(function (i, el) 98 { 99 return $targets.index(el) === i; 100 }); 101 102 // Icône initiale 103 var $icon = $('<span class="toggle-icon" style="position:absolute;right:0;top:50%;transform:translateY(-50%);width:16px;text-align:center;"><i class="fa"></i></span>'); 104 $trigger.append($icon); 105 $trigger.css('position', 'relative'); 106 107 // Ãtat initial 108 if ($trigger.is('[data-toggle-deploy]')) 109 { 110 $targets.show(); 111 $icon.find('i').addClass('fa-minus'); 112 $trigger.attr('aria-expanded', 'true'); 113 } else 114 { 115 $targets.hide(); 116 $icon.find('i').addClass('fa-plus'); 117 $trigger.attr('aria-expanded', 'false'); 118 } 119 120 // Clic 121 $trigger.on('click', function (e) 122 { 123 e.preventDefault(); 124 $targets.slideToggle(200); 125 if ($icon.find('i').hasClass('fa-plus')) 126 { 127 $icon.find('i').removeClass('fa-plus').addClass('fa-minus'); 128 $trigger.attr('aria-expanded', 'true'); 129 } else 130 { 131 $icon.find('i').removeClass('fa-minus').addClass('fa-plus'); 132 $trigger.attr('aria-expanded', 'false'); 133 } 134 }); 135 }); 136 137 138 // Tooltip 139 if ($.fn.tooltipster) 140 $('.tooltip').tooltipster({ 141 contentAsHTML : true, 142 }); 143 144 // Editor 145 const richSimpleTextElements = document.querySelectorAll('.richSimpleText'); 146 setSimpleText(richSimpleTextElements); 147 148 // Convertion de devise 149 var options = { 150 target: '.prix_normal, .prix_barre, #shopping_cart_block_right .totaux:not(".no_devise"), div .money', 151 base: 'EUR', 152 }; 153 $('#currency_converter').currencyPAC( options ); 154 155 // Connexion 156 $('body').on('click','#account-connect, .needConnect',function(ev) 157 { 158 ev.preventDefault(); 159 LaunchSideBar({target : "/modules/Customers/quick_login.php"}); 160 }); 161 162 // Bouton Google dans la sidebar : injecter return_to depuis la page courante du navigateur 163 $('body').on('click','#btnGoogleLogin',function(ev) 164 { 165 ev.preventDefault(); 166 var returnTo = encodeURIComponent(window.location.pathname + window.location.search); 167 window.location.href = $(this).attr('href') + '?return_to=' + returnTo; 168 }); 169 170 // Compte 171 $('body').on('click','#account-link',function(ev) 172 { 173 ev.preventDefault(); 174 LaunchSideBar({ 175 target : "/modules/Customers/accountMenu.php", 176 class : "accountSideMenu", 177 }); 178 }); 179 180 // Recherche 181 $('#searchForm').on('submit',function(e) 182 { 183 e.preventDefault(); 184 185 var el = $(this), 186 url = el.attr('action'), 187 key = el.find('#keywords').val() 188 .replace(/&/g,' ') 189 .replace(/\//g,' '); 190 191 window.location.href = url + encodeURIComponent(key); 192 193 }); 194 195 // captcha PCO 196 // Add input to captcha 197 setCaptchaInput(); 198 199 $('body').on('click','.captcha [type="submit"]',function(ev) 200 { 201 var form = $(this).closest('form'), 202 isFormValid = form[0].checkValidity(); 203 204 if(!isFormValid) 205 form[0].reportValidity(); 206 else { 207 ev.preventDefault(); 208
209 captChaToken(form,function() { form.submit() }); 210 } 211 }); 212 213 // Drag File 214 const dropContainers = document.querySelectorAll(".beautifulFile"); 215 216 dropContainers.forEach(container => 217 { 218 const dropContainer = container.querySelector(".drop-container"); 219 const fileInput = container.querySelector(".drop-target"); 220 221 if (!fileInput) return; 222 223 dropContainer.addEventListener("dragover", (e) => { 224 e.preventDefault() 225 }, false) 226 227 dropContainer.addEventListener("dragenter", () => { 228 dropContainer.classList.add("drag-active") 229 }) 230 231 dropContainer.addEventListener("dragleave", () => { 232 dropContainer.classList.remove("drag-active") 233 }) 234 235 dropContainer.addEventListener("drop", (e) => { 236 e.preventDefault() 237 dropContainer.classList.remove("drag-active") 238 239 240 const files = e.dataTransfer.files; 241 if (fileInput.hasAttribute("accept")) { 242 const acceptedFormats = fileInput.getAttribute("accept").toLowerCase().split(',').map(s => s.trim()); 243 for (let i = 0; i < files.length; i++) { 244 const fileType = files[i].type; 245 const fileExtension = "." + files[i].name.split(".").pop().toLowerCase(); 246 247 let isAccepted = acceptedFormats.includes(fileType) || acceptedFormats.includes(fileExtension); 248 249 // Check for generic MIME types 250 if (!isAccepted) { 251 for (const format of acceptedFormats) { 252 if (format.endsWith("/*")) { 253 const typeMain = format.split("/")[0] + "/"; 254 if (fileType.startsWith(typeMain)) { 255 isAccepted = true; 256 break; 257 } 258 } 259 } 260 } 261 262 if (!isAccepted) { 263 console.error("File format not accepted"); 264 return; 265 } 266 } 267 } 268 fileInput.files = files 269 270 const changeEvent = new Event('change'); 271 fileInput.dispatchEvent(changeEvent); 272 }) 273 }); 274 275 // Panier 276 $('body').on('click','#cart-link',function(ev) 277 { 278 ev.preventDefault(); 279 if (Number.parseInt($(this).find('.nb_articles').text()) > 0) 280 LaunchSideBar({ 281 'target' : "/modules/Tunnel/quick_cart.php", 282 'css' : {"width":"550px", "max-width":"100%"} 283 }); 284 }); 285 286 // Ajout le formulaire 287 $('body').on('submit','.buyNow',function(ev) 288 { 289 ev.preventDefault(); 290 291 var el = $(this), 292 parent = el.closest(".zProd"), 293 zone = parent.data('zone'), 294 prodId = el.find('[name^=products_id]').val(), 295 prodQty = el.find('[name^=quantity]').val(), 296 submit = $(ev.originalEvent.submitter), 297 txt = submit.html(); 298 299 // Envoie 300 $.ajax({ 301 type : "post", 302 url : "/actions/checkout.php", 303 data : { 304 "action" : "buyNow", 305 "products_id" : prodId, 306 "qty" : prodQty, 307 "zone" : ((gtagItemList != "noset") ? gtagItemList : ( zone ?? 'noset')) + '|' + zone, 308 }, 309 dataType : "json", 310 beforeSend : function () { 311 // Passage en waiting 312 submit.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 313 submit.attr("disabled","disabled"); 314 }, 315 success : function (response) { 316 317 if (response.status == "success") 318 { 319 $('#cart-link .nb_articles').html(Number.parseInt(response.qty)); 320 321 if (Number.parseInt(response.qty) == 0) 322 $('#cart-link').addClass('clicL'); 323 else 324 $('#cart-link').removeClass('clicL'); 325 326 var qtyTotalProd = response.products[prodId].qty; 327 parent.find('.item_in_cart .number').html(qtyTotalProd); 328 if (qtyTotalProd > 0) 329 parent.find('.item_in_cart').removeClass("hidden"); 330 else 331 parent.find('.item_in_cart').addClass("hidden"); 332 333 // gtag add_to_cart 334 getGtagItems(response.products_added,{method : zone}).then(function(list) { 335 var addToCart = { 336 action: 'add_to_cart', 337 items: Object.values(list), 338 }; 339 340 $('body').gtagEvent(addToCart); 341 }); 342 } 343 else 344 alert(response.message); 345 }, 346 complete : function () { 347 // Passage en waiting 348 submit.html(txt); 349 submit.removeAttr("disabled"); 350 }, 351 error : function (err) { 352 console.table(err); 353 }, 354 }); 355 }); 356 357 // Ajout via le bouton 358 $('.addToCart:not(.disabled)').css("cursor","pointer"); 359 $('body').on('click','.addToCart:not(.disabled)',function(ev) 360 { 361 ev.preventDefault(); 362 363 var el = $(this), 364 parent = el.closest(".zProd"), 365 zone = parent.data("zone"), 366 prodId = el.data('id'), 367 conversionType = el.data('conversiontype'), 368 conversionId = el.data('conversionid'), 369 prodQty = el.parent('div').find('[name^=quantity]').val(), 370 txt = el.html(), 371 needReload = el.closest('.cartItem').hasClass('reload'); 372 373 // Envoie 374 $.ajax({ 375 type : "post", 376 url : "/actions/checkout.php", 377 data : { 378 "action" : "buyNow", 379 "products_id" : prodId, 380 "qty" : prodQty, 381 "conversionType" : conversionType ?? '', 382 "conversionId" : conversionId ?? '', 383 "zone" : ((gtagItemList != "noset") ? gtagItemList : ( zone ?? 'noset')) + '|' + zone, 384 }, 385 dataType : "json", 386 beforeSend : function () { 387 // Passage en waiting 388 el.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 389 }, 390 success : function (response) { 391 if (response.status == "success") 392 { 393 $('#cart-link .nb_articles').html(Number.parseInt(response.qty)); 394 395 var qtyProd = response.products[prodId].qty; 396 parent.find('.item_in_cart .number').html(qtyProd); 397 if (qtyProd > 0) 398 parent.find('.item_in_cart').removeClass("hidden"); 399 else 400 parent.find('.item_in_cart').addClass("hidden"); 401 402 // gtag add_to_cart 403 getGtagItems(response.products_added,{method : zone}).then(function(list) { 404 var addToCart = { 405 action: 'add_to_cart', 406 items: Object.values(list), 407 }; 408 409 $('body').gtagEvent(addToCart); 410 }); 411 412 if (needReload) 413 window.location = window.location.href; 414 } 415 else 416 alert(response.message); 417 }, 418 complete : function () { 419 // Passage en waiting 420 el.html(txt); 421 }, 422 error : function (err) { 423 console.table(err); 424 }, 425 }); 426 }); 427 // Ajout depuis une commande 428 $('.buyFromOrder').css("cursor","pointer"); 429 $('body').on('click','.buyFromOrder',function(ev) 430 { 431 ev.preventDefault(); 432 433 var el = $(this), 434 id = el.data('id'), 435 zone = el.data('zone'), 436 txt = el.html(); 437 438 // Envoie 439 $.ajax({ 440 type : "post", 441 url : "/actions/checkout.php", 442 data : { 443 "action" : "buyFromOrder", 444 "orders_id" : id, 445 "zone" : ((gtagItemList != "noset") ? gtagItemList : ( zone ?? 'noset')) + '|' + zone, 446 }, 447 dataType : "json", 448 beforeSend : function () { 449 // Passage en waiting 450 el.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 451 }, 452 success : function (response) { 453 if (response.status == "success") 454 { 455 $('#cart-link .nb_articles').html(Number.parseInt(response.qty)); 456 // gtag add_to_cart 457 getGtagItems(response.products_added,{method : zone}).then(function(list) { 458 var addToCart = { 459 action: 'add_to_cart', 460 items: Object.values(list), 461 }; 462 463 $('body').gtagEvent(addToCart); 464 }); 465 } 466 else 467 alert(response.message); 468 }, 469 complete : function () { 470 // Passage en waiting 471 setTimeout( function () { 472 el.html(txt); 473 },500); 474 }, 475 error : function (err) { 476 console.table(err); 477 }, 478 }); 479 }); 480 // Ajout depuis un panier save 481 $('.buyFromCart').css("cursor","pointer"); 482 $('body').on('click','.buyFromCart',function(ev) 483 { 484 ev.preventDefault(); 485 486 var el = $(this), 487 id = el.data('id'), 488 zone = el.data('zone'), 489 txt = el.html(); 490 491 // Envoie 492 $.ajax({ 493 type : "post", 494 url : "/actions/checkout.php", 495 data : { 496 "action" : "buyFromCart", 497 "id" : id, 498 "zone" : ((gtagItemList != "noset") ? gtagItemList : ( zone ?? 'noset')) + '|' + zone, 499 }, 500 dataType : "json", 501 beforeSend : function () { 502 // Passage en waiting 503 el.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 504 }, 505 success : function (response) { 506 if (response.status == "success") 507 { 508 $('#cart-link .nb_articles').html(Number.parseInt(response.qty)); 509 // gtag add_to_cart 510 getGtagItems(response.products_added,{method : zone}).then(function(list) { 511 var addToCart = { 512 action: 'add_to_cart', 513 items: Object.values(list), 514 }; 515 516 $('body').gtagEvent(addToCart); 517 }); 518 } 519 else 520 alert(response.message); 521 }, 522 complete : function () { 523 // Passage en waiting 524 setTimeout( function () { 525 el.html(txt); 526 },500); 527 }, 528 error : function (err) { 529 console.table(err); 530 }, 531 }); 532 }); 533 // Ajout en masse 534 $('.buyFromForm').css("cursor","pointer"); 535 $('body').on('click','.buyFromForm',function(ev) 536 { 537 ev.preventDefault(); 538 539 var el = $(this), 540 zone = el.data('zone'), 541 form = el.closest('form'), 542 txt = el.html(), 543 conversionType = form.find("[name=conversionType]"),
544 conversionId = form.find("[name=conversionId]"), 545 formData = {}; 546 547 form.find('input[name^="quantity"]').each(function() { 548 var name = $(this).attr('name'); // Obtient le nom du champ 549 var id = name.match(/\[([^)]+)\]/)[1]; // Extrait l'ID entre crochets 550 var value = $(this).val(); // Obtient la valeur du champ 551 formData[id] = value; // Ajoute l'ID et la valeur à l'objet formData 552 }); 553 554 // Envoie 555 $.ajax({ 556 type : "post", 557 url : "/actions/checkout.php", 558 data : { 559 "action" : "buyFromForm", 560 "products" : formData, 561 "conversionType" : conversionType.val() ?? '', 562 "conversionId" : conversionId.val() ?? '', 563 "zone" : zone, 564 }, 565 dataType : "json", 566 beforeSend : function () { 567 // Passage en waiting 568 el.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 569 }, 570 success : function (response) { 571 if (response.status == "success") 572 { 573 $('#cart-link .nb_articles').html(Number.parseInt(response.qty)); 574 575 // gtag add_to_cart 576 getGtagItems(response.products_added,{method : zone}).then(function(list) { 577 var addToCart = { 578 action: 'add_to_cart', 579 items: Object.values(list), 580 }; 581 582 $('body').gtagEvent(addToCart); 583 }); 584 } 585 else 586 alert(response.message); 587 }, 588 complete : function () { 589 // Passage en waiting 590 setTimeout( function () { 591 el.html(txt); 592 },500); 593 }, 594 error : function (err) { 595 console.table(err); 596 }, 597 }); 598 }); 599 600 // Bouton + et - 601 $('body').off('click','.qtyCartItem .sub_one'); 602 $('body').off('click','.qtyCartItem .add_one'); 603 $('body').on("click",".qtyCartItem .sub_one",function(e) 604 { 605 var inputEl = $(this).next('input'), 606 currentVal = Number.parseInt(inputEl.val()), 607 min = (inputEl.attr("min") !== undefined) ? Number.parseInt(inputEl.attr('min')) : 1, 608 nextVal = Math.max(min, currentVal - 1); 609 610 if (currentVal != nextVal && !inputEl.prop('disabled')) 611 inputEl.val( nextVal ).change(); 612 }); 613 $('body').on("click",".qtyCartItem .add_one",function(e) 614 { 615 var inputEl = $(this).prev('input'), 616 currentVal = Number.parseInt(inputEl.val()), 617 max = (inputEl.attr("max") !== undefined) ? Number.parseInt(inputEl.attr('max')) : 0, 618 nextVal = currentVal + 1; 619 620 if ( nextVal > max && max > 0) nextVal = max; 621 622 if (currentVal != nextVal && !inputEl.prop('disabled')) 623 inputEl.val( nextVal ).change(); 624 }); 625 626 // Ajout/Supp en wishlist 627 $('.add_to_wishlist a').css("cursor","pointer"); 628 $('body').on('click','.add_to_wishlist',function(ev) 629 { 630 ev.preventDefault(); 631 632 var submit = $(this), 633 parent = submit.closest(".zProd"), 634 zone = submit.data('zone'), 635 type = submit.data('type'), 636 id = submit.data('id'), 637 txt = submit.html(); 638 639 // Envoie 640 $.ajax({ 641 type : "post", 642 url : "/actions/customers.php", 643 data : { 644 "action" : "addWishlist", 645 "id" : id, 646 "type" : type, 647 }, 648 dataType : "json", 649 beforeSend : function () { 650 // Passage en waiting 651 submit.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 652 submit.attr("disabled","disabled"); 653 }, 654 success : function (response) { 655 //NEED_LOGIN 656 if (response.status == "not_login") 657 { 658 LaunchSideBar({ 659 'target' : "/modules/Customers/quick_login.php", 660 'post' : { message : response.message} 661 }); 662 } 663 else if (response.status == "success") 664 { 665 submit.html(txt); 666 submit.find('i').toggleClass('fal fas'); 667 668 // gtag add_to_wishlist 669 if(type === 'products_id' && response.isIn == true) 670 getGtagItems({[id]:1},{method : zone}).then(function(list) { 671 var addToWishlist = { 672 action: 'add_to_wishlist', 673 items: Object.values(list), 674 }; 675 676 $('body').gtagEvent(addToWishlist); 677 }); 678 } 679 }, 680 complete : function () { 681 // Passage en waiting 682 setTimeout( function () { 683 submit.removeAttr("disabled"); 684 },500); 685 }, 686 error : function (err) { 687 console.table(err); 688 }, 689 }); 690 }); 691 692 // Suppression mise de coté 693 $('body').on('click','.remove_putaside',function(ev) 694 { 695 ev.preventDefault(); 696 697 var bloc = $(this), 698 parent = bloc.closest(".zProd"), 699 id = bloc.data('id'); 700 701 // Envoie 702 $.ajax({ 703 type : "post", 704 url : "/actions/customers.php", 705 data : { 706 "action" : "removePutaside", 707 "products_id" : id 708 }, 709 dataType : "json", 710 success : function (response) { 711 parent.remove(); 712 }, 713 error : function (err) { 714 console.table(err); 715 }, 716 }); 717 }); 718 719 // FILTERS & TRIE 720 // Refresh on change tri 721 $('body').on('change','#filters .sort select',function(ev) 722 { 723 window.location.href = getRewriteGetUrl({'sort':$(this).val()}); 724 }); 725 // Suppression filtre actif 726 $('body').on('click','#filterSidebar .activeFacetsItem .value',function(ev) 727 { 728 var el = $(this), 729 id = $('#'+el.data('id')); 730 731 if (id.hasClass('checkbox')) 732 id.find('input').prop("checked",false); 733 else if (id.hasClass('minMax')) 734 id.find('input').each(function(){ 735 $(this).val($(this).data('def')); 736 $(this).attr('value',$(this).data('def')); 737 }); 738 else 739 id.prop("checked",false); 740 741 if (typeof ajaxSearch === 'function') ajaxSearch(el.closest('#filterSidebar').find('form')); 742 743 if(el.closest('.activeFacetsItem').find('.value').length === 1) 744 el.closest('.activeFacetsItem').remove(); 745 else 746 el.remove(); 747 748 }); 749 $('body').on('click', '#filterSidebar .facets .filterButton #special', function (e) { 750 ajaxSearch($('#filterSidebar form')); 751 }); 752 $('body').on('click', '.listFilters .filterItem .filter .removeFiler', function (e) { 753 e.preventDefault(); 754 e.stopPropagation(); 755 e.stopImmediatePropagation(); 756 var inputId = $(this).attr('data-id'); 757 var $input = $('#' + $.escapeSelector(inputId)); 758 // checkbox 759 if ($input.length && $input.is(':checkbox')) { 760 $input.prop('checked', false).trigger('change'); 761 } 762 // min / max 763 else { 764 var facetId = String($(this).data('id')).split('-option')[0], 765 $facet = $('#filterSidebar #' + facetId); 766 767 if ($facet.length) { 768 var $min = $facet.find('input.min'), 769 $max = $facet.find('input.max'); 770 771 if ($min.length && $max.length) { 772 var minDef = $min.data('def') ?? $min.attr('min'), maxDef = $max.data('def') ?? $max.attr('max'); 773 $min.val(minDef).attr('value', minDef).trigger('change'); 774 $max.val(maxDef).attr('value', maxDef).trigger('change'); 775 } 776 } 777 } 778 // submit auto 779 $('#filterSidebar form')[0].submit(); 780 }); 781 $('body').on('click','#filterSidebar .deleteActives span',function(ev) 782 { 783 $('#filterSidebar .facetOption input[type=checkbox], #filterSidebar .facetOptionPicture input[type=checkbox]').prop("checked",false); 784 785 if (typeof ajaxSearch === 'function') ajaxSearch($(this).closest('#filterSidebar').find('form')); 786 787 $('#filterSidebar .activeFacets').remove(); 788 }); 789 // Soumission 790 $('body').on('change','#filterSidebar .facetOptions, #filterSidebar .customOptions',function(ev) 791 {
792 if ( typeof xhrFilter !== 'undefined' ) xhrFilter.abort(); 793 794 var el = $(this), 795 form = el.closest('form'); 796 797 if (typeof ajaxSearch === 'function') ajaxSearch(form); 798 }); 799 $('body').on('submit','#filterSidebar form',function(ev) 800 { 801 $(this).find('.filterButton button').html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 802 $(this).find('.filterButton button').prop("disabled",true); 803 $(this).find('.search_facet').prop('disabled', true); 804 805 // minMax 806 $("#filterSidebar .minMax .customOptions").each(function(){ 807 var el = $(this), 808 min = el.find('input.min'), 809 max = el.find('input.max'), 810 valueMin = min.val(), 811 defMin = min.attr('min'), 812 valueMax = max.val(), 813 defMax = max.attr('max'); 814 815 if (valueMin == defMin && valueMax == defMax) 816 { 817 min.prop('disabled', true); 818 max.prop('disabled', true); 819 } 820 }); 821 }); 822 823 // Lancement 824 $('body').on('click','#filters .filtersItem, .listFilters .filterItem .filter, .listFilters .hiddenFitlers',function(e) 825 { 826 e.preventDefault(); 827 disableScroll(); 828 829 var el = $(this), 830 filters_key = el.data('key'); 831 target = "#hiddenFilterSidebar"; 832 833 $('#hiddenFilterSidebar .facetOptions').hide(); 834 $('#hiddenFilterSidebar .facet').removeClass('toShow'); 835 $('#'+filters_key+' .facetOptions').show(); 836 $('#'+filters_key+' .facetOptions').closest('.facet').addClass('toShow'); 837 838 LaunchSideBar({ 839 target : target, 840 type : 'dom', 841 class : 'filtersSidebar', 842 animation : 'fullLeft', 843 css : {"max-width" : "450px","width" : "100%"}, 844 afterLoad : function () { 845 // Lancement des ranges 846 $( ".sliderRange" ).each(function(){ 847 var timer = null, 848 el = $(this), 849 facet = el.closest('.facet'), 850 minEl = facet.find('[name="'+ el.data('min') +'"]'), 851 maxEl = facet.find('[name="'+ el.data('max') +'"]'), 852 min = Number.parseInt(minEl.attr('min')), 853 max = Number.parseInt(minEl.attr('max')), 854 minVal = Number.parseInt(minEl.val()), 855 maxVal = Number.parseInt(maxEl.val()); 856 857 if ($.data(el, "ui-slider")) { 858 el.slider("destroy"); 859 } 860 861 el.slider({ 862 range : true, 863 min : min, 864 max : max, 865 values : [ minVal, maxVal ], 866 slide : function( event, ui ) { 867 minEl.val(ui.values[ 0 ]); 868 maxEl.val(ui.values[ 1 ]); 869 870 clearTimeout(timer); 871 timer = setTimeout(function(){minEl.change()},500); 872 } 873 }); 874 875 // Change, Valide and Auto Size input 876 facet.find('input').on('input change', function() { 877 adjustInputWidth($(this)); 878 879 var min = Math.min(minEl.val(),maxEl.val()), 880 max = Math.max(minEl.val(),maxEl.val()); 881 minEl.val(min); 882 maxEl.val(max); 883 884 el.slider({ 885 values: [ min,max ] 886 }); 887 }).trigger('input'); 888 }); 889 }, 890 onClose : function () { 891 enableScroll(); 892 } 893 }); 894 895 // Cas un seul filtre 896 var countFilters = $("#hiddenFilterSidebar .facets form").children('.facet').length; 897 if (countFilters == 1) 898 $("#filterSidebar .facets .facetOptions .seeMore").click(); 899 }); 900 901 // Affiche les options 902 $('body').on('click','#filterSidebar .facetTitle',function() 903 { 904 $(this).closest('.facet').find('.facetOptions').toggle(); 905 }); 906 907 // On cache les options > 5 908 $('#filterSidebar .facetOptions:not(.checkbox) .seeMoreOption').each(function(){$(this).hide()}); 909 $('body').on('click','#filterSidebar .facetOptions .seeMore',function(e) 910 { 911 e.preventDefault(); 912 $(this).closest('.facetOption').hide(); 913 $(this).closest('.facetOptions').find('.seeMoreOption').toggle(); 914 }); 915 $('body').on('click','#filterSidebar .facetOptions .seeMinus',function(e) 916 { 917 e.preventDefault(); 918 $(this).closest('.facetOptions').find('.seeMore').closest('.facetOption').show(); 919 $(this).closest('.facetOptions').find('.seeMoreOption').toggle(); 920 }); 921 922 // Recherche dans les options 923 $("body").on("keyup","#filterSidebar .facet .search_facet",function() 924 { 925 var el = $(this), 926 val = el.val(); 927 928 if(val.length > 0) 929 el.next('a.reset-search-facet').fadeIn(); 930 else 931 el.next('a.reset-search-facet').fadeOut(); 932 933 searchInFacet(val,el); 934 }); 935 $("body").on("click","#filterSidebar .facet .reset-search-facet",function(){ 936 $(this).prev('input').val(''); 937 $(this).fadeOut(); 938 searchInFacet('',$(this).prev('input')); 939 return false;
940 }); 941 942 // FAQ 943 $(".itemFaq .ask").click(function () { 944 var answer = $(this).next(".answer"), 945 icon = $(this).find("i"), 946 isOpen = answer.is(":visible"); 947 948 // Ferme tous les autres 949 $(".answer").slideUp(); 950 $(".ask i").removeClass("fa-chevron-down").addClass("fa-chevron-right"); 951 952 // Si fermé, on ouvre 953 if (!isOpen) { 954 answer.slideDown(); 955 icon.removeClass("fa-chevron-right").addClass("fa-chevron-down"); 956 } 957 }); 958}); 959 960function setSimpleText(elements) 961{ 962 if (elements instanceof jQuery) 963 elements = elements.toArray(); 964 else if (NodeList.prototype.isPrototypeOf(elements)) 965 elements = Array.from(elements); 966 else if (!Array.isArray(elements)) 967 elements = [elements]; 968 969 if (typeof ClassicEditor !== 'undefined') 970 elements.forEach(element => { 971 if (element && element.tagName === 'TEXTAREA') 972 { 973 let maxLength = element.getAttribute('maxlength'); 974 975 ClassicEditor 976 .create(element, {}) 977 .then(editor => { 978 // Créer le compteur si maxlength existe 979 let counter = null; 980 if (maxLength) { 981 counter = document.createElement('div'); 982 counter.classList.add('char-counter'); 983 counter.style.marginTop = "4px"; 984 985 // Insérer APRES le conteneur ck-editor 986 let editorContainer = element.nextElementSibling; // CKEditor wrapper 987 if (editorContainer && editorContainer.classList.contains('ck-editor')) { 988 editorContainer.insertAdjacentElement('afterend', counter); 989 } 990 } 991 992 // Fonction de mise à jour du compteur 993 function updateCounter() { 994 let content = editor.getData(), 995 parsed = stripTagsAndConvertEntities(content); 996 997 element.value = parsed.length > 0 ? content : ''; 998 999 if (maxLength && counter) { 1000 let currentLength = content.length; // HTML compris 1001 counter.textContent = currentLength + " / " + maxLength; 1002 1003 if (currentLength > maxLength) { 1004 counter.classList.add('errorLength'); 1005 } else { 1006 counter.classList.remove('errorLength'); 1007 } 1008 } 1009 1010 $(element).trigger('change'); 1011 } 1012 1013 // Initialiser directement le compteur 1014 updateCounter(); 1015 1016 // Réagir sur modification 1017 editor.model.document.on('change:data', updateCounter); 1018 }) 1019 .catch(handleSampleError); 1020 } 1021 else { 1022 console.log(element); 1023 } 1024 }); 1025} 1026 1027function handleSampleError( error ) { 1028 const issueUrl = 'https://github.com/ckeditor/ckeditor5/issues'; 1029 1030 const message = [ 1031 'Oops, something went wrong!', 1032 `Please, report the following error on ${ issueUrl } with the build id "p9y771iug0kn-c2hkrx1gk860" and the error stack trace:` 1033 ].join( '\n' ); 1034 1035 console.error( message ); 1036 console.error( error ); 1037} 1038function stripTagsAndConvertEntities(input) { 1039 // Utilisez DOMParser pour analyser la chaîne HTML 1040 const parser = new DOMParser(); 1041 const doc = parser.parseFromString(input, "text/html"); 1042 1043 // Récupérez le texte brut du document 1044 const plainText = doc.body.textContent || ""; 1045 1046 // Décodez les entités HTML spéciales 1047 const decodedText = new DOMParser().parseFromString(plainText, "text/html").documentElement.textContent; 1048 1049 // Utilisez trim() pour supprimer les espaces vides au début et à la fin du texte 1050 const trimmedText = decodedText.trim(); 1051 1052 return trimmedText; 1053} 1054 1055var xhrFilter; 1056function ajaxSearch (form) 1057{ 1058 var button = form.find('.filterButton button') 1059 html = button.html(); 1060 1061 // minMax 1062 // form.find(".minMax .customOptions").each(function(){ 1063 // var el = $(this), 1064 // min = el.find('input.min'), 1065 // max = el.find('input.max'), 1066 // valueMin = min.val(), 1067 // defMin = min.attr('min'), 1068 // valueMax = max.val(), 1069 // defMax = max.attr('max'); 1070 1071 // if (valueMin == defMin && valueMax == defMax) 1072 // { 1073 // min.prop('disabled', true); 1074 // max.prop('disabled', true); 1075 // } 1076 // }); 1077 1078 // Data 1079 form.find('.search_facet').prop('disabled', true); 1080 var gets = "ajax_filters=1&" + form.serialize(); 1081 form.find('.search_facet').prop('disabled', false); 1082 1083 // Special ? 1084 let url = new URL(location.href); 1085 if (url.searchParams.get('special') == 1) 1086 gets = "special=1&" + gets; 1087 1088 // Envoi 1089 xhrFilter = $.ajax({ 1090 type : "get", 1091 url : form.attr('action') + "?" + gets, 1092 data : {}, 1093 dataType : "json", 1094 beforeSend : function () { 1095 majFacetSelected(form); 1096 // Passage en waiting 1097 button.prop("disabled",true); 1098 button.html('<i class="fa-solid fa-circle-notch fa-spin"></i>'); 1099 }, 1100 success : function (response) { 1101 button.html(html); 1102 button.find('.counter').html(response.count); 1103 if (response.count > 0)
1104 button.prop("disabled",false); 1105 }, 1106 complete : function () { 1107 }, 1108 error : function (err) { 1109 button.html(html); 1110 console.table(err); 1111 }, 1112 }); 1113} 1114 1115function searchInFacet(val,el) 1116{ 1117 var val = val.toUpperCase(), 1118 facetOption = el.closest('.facet').find('.facetOption'); 1119 1120 if(val == '') 1121 { 1122 facetOption.show(); 1123 facetOption.filter('.seeMoreOption').hide(); 1124 } 1125 else 1126 { 1127 facetOption.hide(); 1128 1129 facetOption.each(function(index){ 1130 var nameElement = $(this).find('span.name,label span.label'); 1131 console.log(nameElement.length); 1132 if(nameElement.length > 0) 1133 { 1134 var txtValue = nameElement.text().toUpperCase(); 1135 1136 if (txtValue.indexOf(val) > -1) 1137 $(this).fadeIn('fast'); 1138 } 1139 }); 1140 } 1141} 1142 1143function majFacetSelected(form) 1144{ 1145 form.find(".facet").each(function(){ 1146 var count = $(this).find('.facetOptions .facetOption input:checked,.facetOptions .facetOptionPicture input:checked').length, value = count; 1147 1148 if(count > 0) 1149 $(this).find(".facetTitle span.nbrFacetSelect").html(value).addClass('active'); 1150 else 1151 $(this).find(".facetTitle span.nbrFacetSelect").html('').removeClass('active'); 1152 }); 1153}
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.