templates/front/includes/scripts.twig line 1

Open in your IDE?
  1. <!-- jquery.min.js -->
  2. <script src="https://code.jquery.com/jquery-3.6.0.min.js"                                  integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
  3. <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"                               ></script>
  4. <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"    integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
  6. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
  7. <script src="https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.3.1/js/ion.rangeSlider.min.js"></script>
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
  9. <!-- sharethis -->
  10. <script type='text/javascript' src='https://platform-api.sharethis.com/js/sharethis.js#property=63110b5e560f0d00125e74b9&product=sop' async='async'></script>
  11. <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
  12. <!-- script.js -->
  13. <script src="{{ asset('/assets/js/ckeditor4.23/ckeditor.js') }}"></script>
  14. <script src="{{ asset('/assets/js/main.js') }}"></script>
  15. <script>
  16.     $(document).ready(function () {
  17.         if ($('.bulleted_list_textarea').length) {
  18.             $('.bulleted_list_textarea').each(function (index, object) {
  19.                 let placeholder = $(object).attr('placeholder');
  20.                 CKEDITOR.replace(object, {
  21.                     editorplaceholder: placeholder,
  22.                     enterMode: CKEDITOR.ENTER_LIST,
  23.                     shiftEnterMode: CKEDITOR.ENTER_BR,
  24.                     autoParagraph: false,
  25.                     allowedContent: 'ul ol li[*]', // Tylko listy, * oznacza usunięcie atrybutów
  26.                     disallowedContent: '*[!ul,!ol,!li]', // Usunięcie innych elementów
  27.                     versionCheck: false,
  28.                     selector: '.bulleted_list_textarea',
  29.                     height: "280",
  30.                     content_style: "@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@300;400&family=Roboto:wght@300&display=swap'); body {margin-top: 4px; margin-left: 10px; height: 100% !important;  font-family: 'Roboto Condensed', sans-serif !important; font-size: 14px; font-weight: 400; color: #20262d;}" + "ul {margin: 0px; padding: 0.375rem 0.75rem;}" + "body > p {display:none;}" + ".mce-content-body[data-mce-placeholder]{ margin-top: 10px;position: relative;}",
  31.                     mobile: {
  32.                         height: "150",
  33.                         content_style: "@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@300;400&family=Roboto:wght@300&display=swap'); body {margin-top: 4px; margin-left: 10px; height: 100% !important;  font-family: 'Roboto Condensed', sans-serif !important; font-size: 14px; font-weight: 400; color: #20262d}" + "ul {margin: 0px; padding-left: 0px; padding: 0.375rem 0.75rem;}" + "body > p {display:none;}" + ".mce-content-body[data-mce-placeholder]{ margin-top: 10px;position: relative;}",
  34.                     },
  35.                     extraPlugins: "editorplaceholder",
  36.                     toolbar: [{name: 'basicstyles', items: ['BulletedList']}],
  37.                     removePlugins: "elementspath,save,magicline,image,flash,iframe,link,smiley,find,pagebreak,templates,about,maximize,showblocks,newpage,language,blockquote,save,flash,iframe,pagebreak,templates,about,showblocks,newpage,language,print,div'",
  38.                     on: {
  39.                         instanceReady: function (ckeditor) {
  40.                             var idtext = ckeditor.editor.name;
  41.                             let editor = ckeditor.editor;
  42.                             let value  = editor.getData();
  43.                             let id = object.id;
  44.                             if(value == ''){
  45.                                 editor.setData('<ul><li></li></ul>');
  46.                                 $('<textarea id="'+idtext+'" />').html('<ul><li></li></ul>')
  47.                             }
  48.                             createBulletedInput(value, idtext);
  49.                         },
  50.                         paste: function (ckeditor) {
  51.                             /*var idtext = ckeditor.editor.name;
  52.                             let editor  = ckeditor.editor;
  53.                             let valuePaste  = ckeditor.data.dataValue;
  54.                             let value  = editor.getData();
  55.                             let id = object.id;
  56.                             valuePaste = cleanListHtml(valuePaste);
  57.                              if (valuePaste.includes('<ul data-test="aggregate-bullet-model">') != false) {
  58.                                 valuePaste = valuePaste.replaceAll('<ul data-test="aggregate-bullet-model">', '<ul>');
  59.                             }
  60.                             if(valuePaste.includes('<ul data-stringify-type="unordered-list" data-list-tree="true" data-indent="0" data-border="0"><li data-stringify-indent="0" data-stringify-border="0">') != false){
  61.                                 valuePaste = valuePaste.replaceAll('<ul data-stringify-type="unordered-list" data-list-tree="true" data-indent="0" data-border="0"><li data-stringify-indent="0" data-stringify-border="0">', '<ul>');
  62.                             }
  63.                             if(valuePaste.includes('<li data-stringify-indent="0" data-stringify-border="0">') != false){
  64.                                 valuePaste = valuePaste.replaceAll('<li data-stringify-indent="0" data-stringify-border="0">', '<li>');
  65.                             }
  66.                             if (valuePaste.includes('<li') == false) {
  67.                                 valuePaste = '<li>'+ckeditor.data.dataValue+'</li>';
  68.                             }
  69.                             console.log(valuePaste);
  70.                             valuePaste = removeAttributesFromHTML(valuePaste);
  71.                             console.log(valuePaste);
  72.                             if(valuePaste.includes('<br>') != false){
  73.                                 valuePaste = valuePaste.replaceAll('<br>', '</li><li>');
  74.                             }
  75.                             if (valuePaste.includes('</ul><ul>') != false) {
  76.                                 valuePaste = valuePaste.replaceAll('</ul><ul>', '');
  77.                             }
  78.                             if (valuePaste.includes('<li><ul>') != false) {
  79.                                 valuePaste = valuePaste.replaceAll('<li><ul>', '');
  80.                             }
  81.                             if (valuePaste.includes('</ul></li>') != false) {
  82.                                 valuePaste = valuePaste.replaceAll('</ul></li>', '');
  83.                             }
  84.                             if (valuePaste.includes('<br/>') != false){
  85.                                 valuePaste = valuePaste.replaceAll('<br/>', '</li><li>');
  86.                             }
  87.                             if (valuePaste.includes('<br data-cke-eol="1">') != false){
  88.                                 valuePaste = valuePaste.replaceAll('<br data-cke-eol="1">', '');
  89.                             }
  90.                             if (valuePaste.includes('<br />') != false) {
  91.                                 valuePaste = valuePaste.replaceAll('<br />', '</li><li>');
  92.                             }
  93.                             if (valuePaste.includes('<div>') != false) {
  94.                                 valuePaste = valuePaste.replaceAll('<div>', '');
  95.                             }
  96.                             if (valuePaste.includes('</div>') != false) {
  97.                                 valuePaste = valuePaste.replaceAll('</div>', '');
  98.                             }
  99.                             //value += valuePaste;
  100.                             value = value.replaceAll('</ul>', '');
  101.                             value = value.replaceAll('<li><br></li>', '');
  102.                             value = value.replaceAll('<li><br/></li>', '');
  103.                             value = value.replaceAll('<li><br /></li>', '');
  104.                             value = value.replaceAll('<li>&nbsp;</li>', '');
  105.                             value = value.replaceAll('<ul>', '');
  106.                             editor.setData(value);
  107.                             createBulletedInput(value, idtext);*/
  108.                         },
  109.                         change: function (ckeditor) {
  110.                             var idtext = ckeditor.editor.name;
  111.                             let editor = ckeditor.editor;
  112.                             let value  = editor.getData();
  113.                             let id = object.id;
  114.                             if (value.includes('<ul data-test="aggregate-bullet-model">') != false) {
  115.                                 value = value.replaceAll('<ul data-test="aggregate-bullet-model">', '<ul>');
  116.                             }
  117.                             if(value.includes('<br>') != false){
  118.                                 value = value.replaceAll('<br>', '</li><li>');
  119.                             }
  120.                             console.log(value);
  121.                             value = removeAttributesFromHTML(value);
  122.                             console.log(value);
  123.                             if(value.includes('<ul data-stringify-type="unordered-list" data-list-tree="true" data-indent="0" data-border="0"><li data-stringify-indent="0" data-stringify-border="0">') != false){
  124.                                 value = value.replaceAll('<ul data-stringify-type="unordered-list" data-list-tree="true" data-indent="0" data-border="0"><li data-stringify-indent="0" data-stringify-border="0">', '<ul>');
  125.                             }
  126.                             if(value.includes('<li data-stringify-indent="0" data-stringify-border="0">') != false){
  127.                                 value = value.replaceAll('<li data-stringify-indent="0" data-stringify-border="0">', '<li>');
  128.                             }
  129.                             if (value.includes('</ul><ul>') != false) {
  130.                                 value = value.replaceAll('</ul><ul>', '');
  131.                             }
  132.                             if (value.includes('<li><ul>') != false) {
  133.                                 value = value.replaceAll('<li><ul>', '');
  134.                             }
  135.                             if (value.includes('</ul></li>') != false) {
  136.                                 value = value.replaceAll('</ul></li>', '');
  137.                             }
  138.                             if (value.includes('<div>') != false) {
  139.                                 value = value.replaceAll('<div>', '');
  140.                             }
  141.                             if (value.includes('</div>') != false) {
  142.                                 value = value.replaceAll('</div>', '');
  143.                             }
  144.                             if (value.includes('<br/>') != false){
  145.                                 value = value.replaceAll('<br/>', '</li><li>');
  146.                             }
  147.                             if (value.includes('<br data-cke-eol="1">') != false){
  148.                                 value = value.replaceAll('<br data-cke-eol="1">', '');
  149.                             }
  150.                             if (value.includes('<li>&nbsp;</li><li>') != false) {
  151.                                 value = value.replaceAll('<li>&nbsp;</li><li>', '<li>');
  152.                                 editor.setData(value);
  153.                             }
  154.                             if (value.includes('<br />') != false) {
  155.                                 value = value.replaceAll('<br />', '</li><li>');
  156.                             }
  157.                             let decodeText = $('<textarea id="'+idtext+'" />').html(value).text();
  158.                             createBulletedInput(decodeText, idtext);
  159.                         },
  160.                         key: function (ckeditor) {
  161.                             if (ckeditor.data.keyCode == 9 || ckeditor.data.keyCode == (CKEDITOR.SHIFT + 9)) {
  162.                                 ckeditor.cancel();
  163.                                 ckeditor.stop();
  164.                             }
  165.                             let editor = ckeditor.editor;
  166.                             let value  = editor.getData();
  167.                             var idtext = ckeditor.editor.name;
  168.                             if(ckeditor.data.keyCode == 13 && value.includes('<li>&nbsp;</li>') != false){
  169.                             }else{
  170.                                 if(ckeditor.data.keyCode != 1114129 && ckeditor.data.keyCode != 1114198 && ckeditor.data.keyCode != 9){
  171.                                     if ($('.'+editor.name).find('.cke_button__bulletedlist').hasClass('cke_button_off')) {
  172.                                         $('.'+editor.name).find('.cke_button__bulletedlist').click();
  173.                                     }
  174.                                     let id = object.id;
  175.                                     value = removeAttributesFromHTML(value);
  176.                                     if (value.includes('<br>') != false) {
  177.                                         value = value.replaceAll('<br>', '</li><li>');
  178.                                         editor.setData(value);
  179.                                     }
  180.                                     if (value.includes('<div>&nbsp;</div>') != false) {
  181.                                         value = value.replaceAll('<div>&nbsp;</div>', '');
  182.                                         editor.setData(value);
  183.                                     }
  184.                                     if (value.includes('</ul><ul>') != false) {
  185.                                         value = value.replaceAll('</ul><ul>', '');
  186.                                         editor.setData(value);
  187.                                     }
  188.                                     if (value.includes('<p>') != false) {
  189.                                         value = value.replaceAll('<p>', '<li>').replaceAll('</p>', '</li>').replaceAll('<div>', '<li>').replaceAll('</div>', '</li>').replaceAll('<li><br></li>', '');
  190.                                         editor.setData(value);
  191.                                     }
  192.                                     if (value.includes('<div>') != false) {
  193.                                         value = value.replaceAll('<div>', '<li>').replaceAll('</div>', '</li>').replaceAll('<li><br></li>', '');
  194.                                         editor.setData(value);
  195.                                     }
  196.                                     if (value.includes('<ul>') == false) {
  197.                                         editor.setData('<ul><li>'+ value +'</li></ul>');
  198.                                     }
  199.                                     let decodeText = $('<textarea id="'+idtext+'" />').html(value).text();
  200.                                     createBulletedInput(decodeText, idtext);
  201.                                 }
  202.                             }
  203.                         }
  204.                     }
  205.                 });
  206.             });
  207.         }
  208.     });
  209.     const INPUT_HIDDENS = (i, name, value) => {
  210.         return `<input type="hidden" name="offer[`+ name +`][selected][`+ i +`]" value="custom_input`+ value +`" class="input-list-point_`+ name +` input_bulleted_list_`+name+`_`+ i +`">`;
  211.     };
  212.     const BUTTON_NO_CLICK = () => {
  213.         return `
  214.             <button class="navbar-toggler navbar_click_to_change navbar_button_no_clicked" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  215.                 <span class="navbar-toggler-line"></span>
  216.                 <span class="navbar-toggler-line"></span>
  217.                 <span class="navbar-toggler-line"></span>
  218.             </button>
  219.         `;
  220.     }
  221.     let rand = function() {
  222.         return Math.random().toString(36).substr(2); // remove `0.`
  223.     };
  224.     let generateToken = function() {
  225.         return rand() + rand(); // to make it longer
  226.     };
  227.     const BUTTON_CLICK = () => {
  228.         return `
  229.             <button class="navbar-toggler navbar_click_to_change navbar_button_clicked" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  230.               <img src="{{ asset('assets/img/x-white.svg') }}">
  231.             </button>
  232.         `;
  233.     };
  234.     function alertMessage(response, reloadPage = false, waitReloadPage = 600)
  235.     {
  236.         $('.alert').removeClass('alert-danger alert-success');
  237.         $('.alert').addClass('alert-'+response.type);
  238.         $('.alert').show();
  239.         $('.alert_message').html(response.message);
  240.         if(reloadPage){
  241.             setTimeout(function (){
  242.                 location.reload();
  243.             }, waitReloadPage)
  244.         }else{
  245.             setTimeout(function (){
  246.                 $('.alert').hide();
  247.             }, waitReloadPage)
  248.         }
  249.     }
  250.     function removeAttributesFromHTML(htmlString) {
  251.         // Tworzymy tymczasowy element do sparsowania HTML
  252.         const tempDiv = document.createElement('div');
  253.         tempDiv.innerHTML = htmlString;
  254.         // Funkcja rekurencyjna do czyszczenia atrybutów
  255.         function cleanAttributes(element) {
  256.             if (element.nodeType === 1) { // tylko elementy HTML
  257.                 // Usuwamy wszystkie atrybuty
  258.                 while (element.attributes.length > 0) {
  259.                     element.removeAttribute(element.attributes[0].name);
  260.                 }
  261.             }
  262.             // Przechodzimy rekurencyjnie przez dzieci
  263.             for (let child of element.childNodes) {
  264.                 cleanAttributes(child);
  265.             }
  266.         }
  267.         // Czyścimy wszystkie dzieci tymczasowego elementu
  268.         for (let child of tempDiv.childNodes) {
  269.             cleanAttributes(child);
  270.         }
  271.         return tempDiv.innerHTML;
  272.     }
  273.     function cleanListHtml(html) {
  274.         const parser = new DOMParser();
  275.         const doc = parser.parseFromString(html, 'text/html');
  276.         const allowedTags = ['UL', 'OL', 'LI'];
  277.         function cleanElement(el) {
  278.             // Only process element nodes
  279.             if (el.nodeType !== 1) return;
  280.             // If tag is not allowed, unwrap its children
  281.             if (!allowedTags.includes(el.tagName)) {
  282.                 const parent = el.parentNode;
  283.                 while (el.firstChild) {
  284.                     parent.insertBefore(el.firstChild, el);
  285.                 }
  286.                 parent.removeChild(el);
  287.                 return;
  288.             }
  289.             // If tag is allowed, remove all attributes
  290.             while (el.attributes.length > 0) {
  291.                 el.removeAttribute(el.attributes[0].name);
  292.             }
  293.             // Recursively clean children
  294.             Array.from(el.childNodes).forEach(child => cleanElement(child));
  295.         }
  296.         Array.from(doc.body.childNodes).forEach(child => cleanElement(child));
  297.         return doc.body.innerHTML;
  298.     }
  299.     function createBulletedInput(value_data, NameType)
  300.     {
  301.         let clearString = '';
  302.         let R = 0;
  303.         let k = 0;
  304.         let value = value_data.replaceAll('<ul>','').replaceAll('</ul>', '').replaceAll('<li>', '').replaceAll('\n', '').replaceAll('&nbsp;', '').replaceAll('</li>', '\n').replaceAll('<br>', '\n').replaceAll('<br />', '\n').replaceAll('<div>', '').replaceAll('</div>', '');
  305.         let length = value.length;
  306.         $('.input-list-point_'+NameType).remove();
  307.         ListData                = [];
  308.         ResponseData[NameType]  = [];
  309.         for (k; k <= length; k++) {
  310.             if (value.charAt(k) != '\n') {
  311.                 if (value.charAt(k) != '') {
  312.                     clearString += value.charAt(k);
  313.                     ListData[R] = {"id": R, "text": clearString};
  314.                     ResponseData[NameType] = ListData;
  315.                     ResponseData[NameType].forEach((val,key)=>{
  316.                         if(typeof ResponseData[NameType][key].text){
  317.                             if($('.input_bulleted_list_'+NameType+'_'+ResponseData[NameType][key].id).length <= 0){
  318.                                 $('.box-bulleted_list_'+NameType).append(INPUT_HIDDENS(ResponseData[NameType][key].id, NameType, ResponseData[NameType][key].text));
  319.                             }else{
  320.                                 $('.input_bulleted_list_'+NameType+'_'+ResponseData[NameType][key].id).val('custom_input'+ResponseData[NameType][key].text);
  321.                             }
  322.                         }
  323.                     });
  324.                 }
  325.             } else {
  326.                 clearString = '';
  327.                 R ++;
  328.             }
  329.         }
  330.     }
  331.     $(document).on('click', '.check-wrapper img', function(){
  332.         $(this).closest('.check-wrapper').find('label').click();
  333.     });
  334.     $(document).on('click', '.check-wrapper label', function(e){
  335.         e.stopPropagation();
  336.     });
  337.     if (jQuery(window).innerWidth() < 600) {
  338.         $(document).on('click', '.package_range_switch_box img', function(){
  339.             $(this).closest('.package_range_switch_box').find('label.bold').click();
  340.         });
  341.     }
  342.     $(document).on('click', '.navbar_click_to_change', function(){
  343.         if($(this).hasClass('navbar_button_no_clicked')){
  344.             $('.navbar_button_no_clicked').remove();
  345.             $('.navbar-box-button').append(BUTTON_CLICK());
  346.         }else{
  347.             $('.navbar_button_clicked').remove();
  348.             $('.navbar-box-button').append(BUTTON_NO_CLICK());
  349.         }
  350.     });
  351.     $(document).on('click', '.package_box_selected', function (){
  352.         let element = $(this).data('package');
  353.         $('.package_box_selected').removeClass('package_selected');
  354.         $('.package_checkbox_selected').prop('checked', false);
  355.         $('label[data-package="'+element+'"]').addClass('package_selected');
  356.     })
  357.     // GGRZ 2022-10-26
  358.     $(window).bind('beforeunload', function(){
  359.         $('.box-spinner').css("display","block");
  360.     });
  361.     $(window).bind('unload', function(){
  362.         $('.box-spinner').css("display","none");
  363.     });
  364. </script>