1(function ($) { 2 'use strict'; 3 $(function () { 4 var stars = new StarRating('.star-rating', { 5 tooltip: false, 6 }); 7 8 const countRating = $('select').data('count'); 9 const maxLength = 500; 10 let selectedValue = '0'; 11 let buttonsValues = []; 12 let textarea = $('textarea[name="opinia"]'); 13 let charCount = $('#charCount'); 14 15 16 function getButtons() { 17 18 buttonsValues = []; 19 $('.button_options button.is-active').each(function (k, v) { 20 buttonsValues.push($(this).data('name')); 21 }) 22 23 if (buttonsValues.length > 0) { 24 $('.generate').removeClass('hide'); 25 } else { 26 $('.generate').addClass('hide'); 27 } 28 29 } 30 31 $('input[placeholder], textarea[placeholder]').each(function () { 32 $(this).data('placeholder', $(this).attr('placeholder')); 33 }); 34 35 $('input, textarea').on('focus', function () { 36 $(this).attr('placeholder', ''); 37 }); 38 39 $('input, textarea').on('blur', function () { 40 if ($(this).val() === '') { 41 $(this).attr('placeholder', $(this).data('placeholder')); 42 } 43 }); 44 45 46 47 $('select[name="rating"]').on('change', () => { 48 selectedValue = $(this).find('option:selected').val(); 49 50 if (selectedValue) { 51 $('form .form_data').removeClass('hide'); 52 53 if (selectedValue && selectedValue < countRating) { 54 $('.text_ai').addClass('hide_ai'); 55 $('.button_options').addClass('hide_ai'); 56 $('.generate').addClass('hide'); 57 58 $('.button_options button').each(function (k, v) { 59 $(this).removeClass('is-active'); 60 }) 61 $('form button[type="submit"]').html("Dodaj opiniÄ"); 62 } else { 63 $('.text_ai').removeClass('hide_ai'); 64 $('.button_options').removeClass('hide_ai'); 65 $('form button[type="submit"]').html("Dalej"); 66 } 67 } else { 68 $('form .form_data').addClass('hide'); 69 } 70 }); 71 72 $('input[name="anonim"]').on('click', function (e) { 73 $('.form_signature').toggleClass('hide'); 74 }) 75 76 77 $('.button_options button.term').on('click', function (e) { 78 e.preventDefault(); 79 $(this).toggleClass('is-active'); 80 getButtons(); 81 }) 82 83 $('.segment button').on('click', function (e) { 84 e.preventDefault(); 85 $('.segment button').each(function () { $(this).removeClass("is-active") }); 86 $(this).addClass('is-active'); 87 }) 88 89 $('textarea[name="opinia"').on('keyup', function (e) { 90 if (selectedValue >= countRating) { 91 if ($(this).val().length > 5) { 92 $('button.copy').removeClass('hide'); 93 return; 94 } 95 $('button.copy').addClass('hide'); 96 } else { 97 $('button.copy').addClass('hide'); 98 } 99 }) 100 101 $('button.copy').on('click', function (e) { 102 e.preventDefault(); 103 let text = $('textarea[name="opinia"]').val(); 104 copyToClipboardFallback(text); 105 }) 106 107 108 textarea.on('input', updateCounter); 109 110 function updateCounter() { 111 var text = textarea.val(); 112 var textLength = text.length; 113 114 if (textLength > maxLength) { 115 textarea.val(text.substring(0, maxLength)); 116 textLength = maxLength; 117 } 118 119 var el = textarea[0]; 120 121 textarea.css('height', 'auto'); 122 textarea.css('height', el.scrollHeight + 'px'); 123 124 charCount.text(textLength); 125 } 126 127 128 $('button.generate_button').on('click', function (e) { 129 e.preventDefault(); 130 const $this = $(this); 131 132 $this.prop('disabled', true); 133 const gender = $('.segment button.is-active').data('gender'); 134 const nonce = $('input[name="nonce"]').val(); 135 136 $.ajax({ 137 url: window.ajaxurl_opinion,
138 method: 'POST', 139 dataType: 'json', 140 data: { 141 action: 'ai_opinion_generator', 142 values: JSON.stringify(buttonsValues), 143 rating: selectedValue, 144 gender, 145 nonce 146 }, 147 beforeSend: function () { 148 let text = $this.html(); 149 $this.html(text + '<span class="loader"></span>'); 150 }, 151 success: function (res) { 152 $('span.ai_info').removeClass('hide'); 153 $this.find('.loader').remove(); 154 $this.html('⨠Wygeneruj ponownie opiniÄ AI'); 155 156 if (res && res.success && res.data.text) { 157 const text = res.data.text; 158 $('span.ai_info').removeClass('error'); 159 $('span.ai_info').html('Opinia zostaÅa wygenerowana!'); 160 161 $('textarea[name="opinia"').val(text); 162 $('textarea[name="opinia"').css('height', 'auto'); 163 164 $('button.copy').removeClass('hide'); 165 $('.ai_act').removeClass('hide'); 166 $('#modal .modal_ai_act').removeClass('hide'); 167 168 updateCounter(); 169 170 setTimeout(() => { 171 $('span.ai_info').addClass('hide'); 172 }, 3000); 173 174 } else { 175 $('span.ai_info').addClass('error'); 176 $('span.ai_info').html('WystÄ piÅ bÅÄ d. ProszÄ spróbowaÄ wygenerowaÄ opiniÄ później jeszcze raz.'); 177 $this.prop('disabled', false); 178 } 179 180 $this.prop('disabled', false); 181 }, 182 error: function (xhr) { 183 $this.find('.loader').remove(); 184 $('span.ai_info').removeClass('hide'); 185 $('span.ai_info').addClass('error'); 186 $('span.ai_info').html('WystÄ piÅ bÅÄ d. ProszÄ spróbowaÄ wygenerowaÄ opiniÄ później jeszcze raz.'); 187 $this.prop('disabled', false); 188 } 189 }) 190 }) 191 192 const $form = $('#form'); 193 194 $('button[type="submit"]').on('click', function (e) { 195 let text = $('textarea[name="opinia"]').val(); 196 copyToClipboardFallback(text); 197 }) 198 199 $form.on('submit', function (e) { 200 e.preventDefault(); 201 202 203 204 const fd = new FormData(this); 205 fd.append('action', 'add_opinion'); 206 fd.append('buttons', JSON.stringify(buttonsValues)); 207 208 let anonim = fd.get('anonim'); 209 210 let opinia = fd.get('opinia'); 211 212 if (anonim && anonim == 'on') { 213 fd.set('title', 'Anonim'); 214 } 215 216 if (fd.get('new_type') && fd.get('new_type') !== '') { 217 return false; 218 } 219 220 // for (const [k, v] of fd.entries()) { 221 // console.log(k, v); 222 // } 223 224 const $btn = $form.find('button[type="submit"]'); 225 $btn.prop('disabled', true); 226 227 // let infoSwitch = [ 228 // '', 229 // 'Przykro nam, że nasze usÅugi nie speÅniÅy Twoich oczekiwaÅ. Twoje uwagi sÄ dla nas bardzo ważne i natychmiast zajmiemy siÄ tym, by uniknÄ Ä podobnych sytuacji w przyszÅoÅci.', 230 // 'Przepraszamy, że Twoje doÅwiadczenie z nami nie speÅniÅo oczekiwaÅ. Twoje uwagi sÄ dla nas bardzo ważne.', 231 // 'DziÄkujemy za TwojÄ opiniÄ! Cieszymy siÄ, że czÄÅÄ z naszych usÅug Ci odpowiadaÅa, ale wiemy, że mamy jeszcze nad czym pracowaÄ. BÄdziemy dÄ Å¼yÄ do poprawy!', 232 // 'DziÄkujemy za TwojÄ szczerÄ opiniÄ! Cieszymy siÄ, że doceniasz naszÄ usÅugÄ.', 233 // 'DziÄkujemy! Twoja pozytywna opinia sprawia, że nasza praca ma sens.' 234 // ]; 235 236 237 $.ajax({ 238 url: window.ajaxurl_opinion,
239 type: 'POST', 240 data: fd, 241 processData: false, 242 contentType: false, 243 dataType: 'json' 244 }) 245 .done(function (res) { 246 if (!res || !res.success) { 247 const msg = res && res.data && res.data.message ? res.data.message : 'BÅÄ d wysyÅki'; 248 249 $('#info').addClass('error'); 250 $('#info').html(msg); 251 252 253 254 return; 255 } 256 $('#info').removeClass('error'); 257 258 window.scrollTo({ 259 top: document.querySelector('#info').offsetTop, 260 behavior: 'smooth' 261 }); 262 263 if (bbTextOptions[selectedValue] && bbTextOptions[bbTextOptions] != "") { 264 if (opinia != '' && selectedValue && selectedValue >= countRating) { 265 $('#info').html("Twoja opinia zostaÅa skopiowana do schowka.<br/> " + bbTextOptions[selectedValue]); 266 openModal("", opinia); 267 } else { 268 $('#info').html(bbTextOptions[selectedValue]); 269 } 270 271 } else { 272 $('#info').html("DziÄkujemy za TwojÄ szczerÄ opiniÄ!"); 273 } 274 275 if (res.data && res.data.post_id) { 276 $('.post_id').attr('data-post_id', res.data.post_id); 277 } 278 279 if (selectedValue && selectedValue >= countRating && selectedValue == res.data.rank) { 280 let text = $('textarea[name="opinia"]').val(); 281 282 copyToClipboardFallback(text); 283 $('.bb_opinion__google').removeClass('hide'); 284 } else { 285 $form[0].reset(); 286 } 287 $btn.prop('disabled', false); 288 }) 289 .fail(function (xhr) { 290 const msg = xhr && xhr.responseJSON.data && xhr.responseJSON.data.message ? xhr.responseJSON.data.message : 'BÅÄ d wysyÅki'; 291 292 $('#info').addClass('error'); 293 $('#info').html(msg); 294 $btn.prop('disabled', false); 295 296 }) 297 .always(function () { 298 $btn.prop('disabled', false); 299 }); 300 }); 301 302 $('.bb-trustindex-review-button').on('click', function (e) { 303 304 let postId = $('.post_id').data('post_id'); 305 const nonce = $('input[name="nonce"]').val(); 306 307 308 if (postId && postId != '') { 309 $.ajax({ 310 url: window.ajaxurl_opinion, 311 method: 'POST', 312 dataType: 'json', 313 data: { 314 action: 'opinion_clicked', 315 post_id: postId, 316 nonce 317 }, 318 beforeSend: function () { }, 319 success: function (res) { }, 320 error: function (xhr) { } 321 }) 322 } 323 }) 324 325 const modal = $('#modal'); 326 327 $('#modal .close').on('click', function (e) { 328 e.preventDefault(); 329 closeModal(); 330 }) 331 332 function openModal(text, copy) { 333 modal.find('.copy_opinion').html("<em>\"" + copy + "\"</em>"); 334 modal.find('.copy_opinion').append('<svg width="64px" height="64px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M6 11C6 8.17157 6 6.75736 6.87868 5.87868C7.75736 5 9.17157 5 12 5H15C17.8284 5 19.2426 5 20.1213 5.87868C21 6.75736 21 8.17157 21 11V16C21 18.8284 21 20.2426 20.1213 21.1213C19.2426 22 17.8284 22 15 22H12C9.17157 22 7.75736 22 6.87868 21.1213C6 20.2426 6 18.8284 6 16V11Z" stroke="#000000" stroke-width="1.5"></path> <path d="M6 19C4.34315 19 3 17.6569 3 16V10C3 6.22876 3 4.34315 4.17157 3.17157C5.34315 2 7.22876 2 11 2H15C16.6569 2 18 3.34315 18 5" stroke="#000000" stroke-width="1.5"></path> </g></svg>'); 335 modal.addClass('show'); 336 //startReviewCountdown(); 337 } 338 339 340 function closeModal() { 341 modal.removeClass('show'); 342 } 343 344 function getSecondsText(sec) { 345 if (sec === 1) return '1 sekundÄ'; 346 if ([2, 3, 4].includes(sec)) return `${sec} sekundy`; 347 return `${sec} sekund`; 348 } 349 350 function startReviewCountdown() { 351 const reviewLink = modal.find('.bb-trustindex-review-button'); 352 const secondEl = modal.find('.second'); 353 354 if (!reviewLink || !secondEl) { 355 return; 356 } 357 358 let seconds = 15; 359 360 secondEl.html(getSecondsText(seconds)); 361 362 const countdown = setInterval(() => { 363 seconds--; 364 secondEl.html(getSecondsText(seconds)); 365 366 if (seconds <= 0) { 367 clearInterval(countdown); 368 modal.find('.single_box').addClass('redirect_fallback'); 369 modal.find('.single_box').html("JeÅli Google nie otworzy siÄ automatycznie, kliknij przycisk poniżej."); 370 reviewLink.click(); 371 } 372 }, 1000); 373 } 374 375 376 // function startReviewCountdown() { 377 // const reviewLink = document.querySelector('#modal .bb-trustindex-review-button'); 378 // const secondEl = document.querySelector('#modal .second'); 379 380 // if (!reviewLink || !secondEl) { 381 // return; 382 // } 383 384 // let seconds = 15; 385 386 // secondEl.textContent = getSecondsText(seconds); 387 388 // const countdown = setInterval(() => { 389 // seconds--; 390 // secondEl.textContent = getSecondsText(seconds); 391 392 // if (seconds <= 0) { 393 // clearInterval(countdown); 394 // modal.find('.single_box').html("JeÅli Google nie otworzy siÄ automatycznie, kliknij przycisk poniżej."); 395 // reviewLink.click(); 396 // } 397 // }, 1000); 398 // } 399 400 401 402 function copyToClipboard(text) { 403 navigator.clipboard.writeText(text) 404 .then(function () { 405 console.log("Skopiowano do schowka " + text); 406 }) 407 .catch(function (err) { 408 console.error("BÅÄ d kopiowania: ", err); 409 }); 410 } 411 412 modal.on('click', '.copy_opinion svg', function(e) { 413 e.preventDefault(); 414 415 let text = $('textarea[name="opinia"]').val(); 416 417 copyToClipboardFallback(text); 418 419 const container = $(this).closest('.copy_opinion'); 420 421 let label = container.find('.copy_label'); 422 423 if (!label.length) { 424 label = $('<span class="copy_label">Skopiowano!</span>'); 425 container.append(label); 426 } 427 428 label.addClass('show'); 429 430 clearTimeout(label.data('timeout')); 431 432 const timeout = setTimeout(function() { 433 label.removeClass('show'); 434 }, 2000); 435 436 label.data('timeout', timeout); 437 438 }); 439 440 441 function copyToClipboardFallback(text) { 442 var textarea = document.createElement("textarea"); 443 textarea.value = text; 444 textarea.style.position = "fixed"; 445 textarea.style.opacity = "0"; 446 document.body.appendChild(textarea); 447 textarea.focus(); 448 textarea.select(); 449 450 try { 451 document.execCommand("copy"); 452 //alert("Skopiowano do schowka " + text); 453 } catch (err) { 454 //alert("BÅÄ d kopiowania: ", err); 455 } 456 457 document.body.removeChild(textarea); 458 } 459 }) 460 461})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.