1if ($('#commentBoxSetup').length > 0) { 2 initTincyMCE(); 3} 4function initTincyMCE() { 5 var tools = $('#commentBoxSetup').val(); 6 if (tools) { 7 tinymce.init({ 8 selector: 'textarea#comment', 9 height: 350, 10 menubar: false, 11 resize: false, 12 branding: false, 13 plugins: [ 14 'advlist lists', 15 'searchreplace visualblocks' 16 ], 17 relative_urls : 0, 18 // remove_script_host : 0, 19 toolbar: tools, 20 setup: function (ed) { 21 ed.on("blur", function () { 22 var editorContent = tinyMCE.get('comment').getContent(); 23 if ($.trim(editorContent) == '') { 24 $( ".tox" ).append( '<div class="error-msg" style="display:block;" id="comment_error"><p>Comment Is Required!</p></div>' ); 25 $(".tx_nsnewscomments #comment").parent().addClass('has-error'); 26 } else { 27 $(".tx_nsnewscomments #comment").parent().removeClass('has-error'); // remove it 28 $(".tx_nsnewscomments #comment_error").hide(); 29 } 30 }) 31 } 32 }); 33 } 34} 35$(function() { 36 submitnewsComment(); 37 hashnewsValue(); 38 onFocusnewsValidation(); 39 $parentCommentId = ''; 40 replynewsComment(); 41 42 if ($('.tx_nsnewscomments .approvedmessage').length) { 43 $('html, body').stop().animate({ 44 scrollTop: ($('.tx_nsnewscomments .approvedmessage').offset().top) 45 }, 2000); 46 setTimeout(function() { 47 $('.tx_nsnewscomments .approvedmessage').fadeOut("slow"); 48 }, 9000); 49 } 50 51 if ($('.approvenewscomment').length) { 52 shownewspopup(); 53 } 54 $(document).on('click',".approvenewscomment #cancel_button", function (){ 55 hidenewspopup(); 56 }); 57 $(document).on('click',".approvenewscomment #close_button", function(){ 58 hidenewspopup(); 59 }); 60 if ($(".inputfile").length > 0) { 61 setDefaultImageTypes($(".inputfile")); 62 } 63 var fromMail = GetURLParameter('frommail'); 64 if (fromMail) { 65 $('.comment-btn.reply').show(); 66 var hashComment = window.location.hash.substr(1);//This pulls the value of the input/URL with parameters 67 var parentCommentId = hashComment.replace(/[^0-9]/g,''); 68 var commentHTML = $('.active-comment-form').html(); 69 $('.active-comment-form .comment-form')[0].reset(); 70 $('.active-comment-form').html(''); 71 $('.active-comment-form').removeClass('active-comment-form'); 72 $('#reply-form-' + parentCommentId).append(commentHTML); 73 $('#reply-form-' + parentCommentId).addClass('active-comment-form'); 74 $('#comment-form-close-btn').show(); 75 removeDefaultValidation(); 76 77 // Scroll to form position 78 $('html, body').stop().animate({ 79 scrollTop: ($('.tx_nsnewscomments #reply-form-' + parentCommentId).offset().top) 80 }, 1000); 81 82 // Set hidden parentId 83 $('.tx_nsnewscomments #parentId').val(parentCommentId); 84 onFocusnewsValidation(); 85 } 86}); 87 88function imNotARobotnews() { 89 if (grecaptcha.getResponse() == "") { 90 $(".tx_nsnewscomments #googlecaptcha").closest('.ns-form-group').addClass('has-error'); 91 $(".tx_nsnewscomments #googlecaptcha_error").show(); 92 return false; 93 } else { 94 $(".tx_nsnewscomments #googlecaptcha").closest('.ns-form-group').removeClass('has-error'); 95 $(".tx_nsnewscomments #googlecaptcha_error").hide(); 96 } 97}; 98 99$(".popup-star-rating").each(function() { 100 var initRat = 0; 101 if($(this).data('rat') > 0){ 102 var initRat = $(this).data('rat'); 103 } 104 $(this).barrating({ 105 theme: 'css-stars', 106 showSelectedRating: false, 107 allowEmpty: true, 108 emptyValue: 0, 109 initialRating:initRat 110 }); 111}); 112var formRating = $('.form-star-rating'); 113$(".form-comment-star-rating").each(function() { 114 var initRat = 0; 115 if($(this).data('rat') > 0){ 116 var initRat = $(this).data('rat'); 117 } 118 $(this).barrating({ 119 theme: 'css-stars', 120 showSelectedRating: false, 121 allowEmpty: true, 122 emptyValue: 0, 123 initialRating:initRat, 124 readonly: true 125 }); 126}); 127 128if(formRating.length > 0){ 129 formRating.barrating({ 130 theme: 'css-stars', 131 showSelectedRating: false, 132 allowEmpty: true, 133 emptyValue: 0, 134 initialRating:1 135 }); 136} 137 138 139$('.popup-star-rating').on('change', function() { 140 var commentUid = $(this).data('uid'); 141 var updateUrl = $(this).data('link'); 142 143 if ($.cookie('ratingChange_' + commentUid)){ 144 $("#exist-"+commentUid).show(); 145 $("#success-"+commentUid).hide(); 146 } 147 else{ 148 $.ajax({ 149 url: updateUrl, 150 method: 'post', 151 data : { val : this.value }, 152 success:function (res) { 153 data = JSON.parse(res); 154 $("#exist-"+data['out']).hide(); 155 $("#success-"+data['out']).show(); 156 }, 157 error:function (xhr, anscount, thrownError){ 158 if(xhr.status==404 && xhr.responseText) { 159 data = JSON.parse(xhr.responseText); 160 $("#exist-"+data['out']).hide(); 161 $("#success-"+data['out']).show(); 162 } 163 } 164 }); 165 } 166}); 167 168function refreshrenewscaptcha() { 169 var googlecaptcha = document.getElementById("googlecaptcha"); 170 if (googlecaptcha) { 171 setTimeout(function () { 172 $('.g-recaptcha').html(''); 173 sitekey = $('.googlecaptchakey').data('googlesitekey'); 174 grecaptcha.render("googlecaptcha", { 175 "sitekey": sitekey 176 }); 177 grecaptcha.reset(); 178 }, 300); 179 } 180}; 181 182// Show popup div 183function shownewspopup() 184{ 185 $(".approvenewscomment #popup_box").fadeToggle(); 186 $(".approvenewscomment #popup_box").css({"visibility":"visible","display":"block"}); 187} 188 189// Hide popup div 190function hidenewspopup() 191{ 192 $(".approvenewscomment #popup_box").fadeToggle(); 193 $(".approvenewscomment #popup_box").css({"visibility":"hidden","display":"none"}); 194} 195 196function replynewsComment() { 197 $(document).on("click", '.ns-news-comment-reply', function(event) { 198 var parentCommentId = $(this).parent().attr('id'); 199 $('#'+ parentCommentId + ' .comment-btn.reply').hide(); 200 var tools = $('#commentBoxSetup').val(); 201 if (tools) { 202 tinyMCE.remove(); 203 initTincyMCE(); 204 } 205 clearFormFields(); 206 refreshrenewscaptcha(); 207 }); 208} 209 210// Scroll to paramlink 211function hashnewsValue() { 212 // get hash value 213 var hash = window.location.hash; 214 // now scroll to element with that id 215 if (hash != '') { 216 $('html, body').stop().animate({ 217 scrollTop: ($(hash).offset().top) 218 }, 2000); 219 } 220} 221 222// Submit form using ajax 223function submitnewsComment() {
224 // Submit comment 225 $(document).on('submit', '.tx_nsnewscomments #comment-form', function(event) { 226 var captcha = $('.tx_nsnewscomments #captcha').val(); 227 var ajaxURL = $(this).attr('action'); 228 var datatype = $('.tx_nsnewscomments #dataType').val(); 229 var commentHTML = $('.active-comment-form').html(); 230 let formData = new FormData(this); 231 if (!event.isDefaultPrevented()) { 232 if (validatenewsField()) { 233 $.ajax({ 234 type: 'POST', 235 url: ajaxURL, 236 contentType: false, 237 cache: false, 238 processData: false, 239 data: formData, 240 dataType: datatype, 241 beforeSend: function() { 242 $('.tx_nsnewscomments #submit').attr('disabled', true); 243 $('.tx_nsnewscomments #submit').css('cursor', 'default'); 244 }, 245 success: function(response) { 246 if(response.status == 'limitReached'){ 247 $(".tx_nsnewscomments #cookie_error").addClass('has-error'); 248 $('.tx_nsnewscomments #cookie_error').show(); 249 }else { 250 $(".tx_nsnewscomments #cookie_error").removeClass('has-error'); 251 $(".tx_nsnewscomments #cookie_error").hide(); 252 } 253 if ($('.tx_nsnewscomments #approval').val() == 0) {
254 // GET HTML for comment list 255 $(".tx_nsnewscomments #comments-list").load(location.href + " .tx_nsnewscomments #comments-list>*", function(responseTxt, statusTxt, jqXHR) { 256 if(statusTxt == "success"){ 257 $(".popup-star-rating").each(function() { 258 var initRat = 0; 259 if($(this).data('rat') > 0){ 260 var initRat = $(this).data('rat'); 261 } 262 $(this).barrating({ 263 theme: 'css-stars', 264 showSelectedRating: false, 265 allowEmpty: true, 266 emptyValue: 0, 267 initialRating:initRat 268 }); 269 }); 270 271 272 $(".form-comment-star-rating").each(function() { 273 var initRat = 0; 274 if($(this).data('rat') > 0){ 275 var initRat = $(this).data('rat'); 276 } 277 $(this).barrating({ 278 theme: 'css-stars', 279 showSelectedRating: false, 280 allowEmpty: true, 281 emptyValue: 0, 282 initialRating:initRat, 283 readonly: true 284 }); 285 }); 286 $('.popup-star-rating').on('change', function() { 287 var commentUid = $(this).data('uid'); 288 var updateUrl = $(this).data('link'); 289 if ($.cookie('ratingChange_' + commentUid)){ 290 $("#exist-"+commentUid).show(); 291 $("#success-"+commentUid).hide(); 292 } 293 else{ 294 $.ajax({ 295 url: updateUrl, 296 method: 'post', 297 data : { val : this.value }, 298 success:function (res) { 299 data = JSON.parse(res); 300 $("#exist-"+data['out']).hide(); 301 $("#success-"+data['out']).show(); 302 }, 303 error:function (xhr, anscount, thrownError){ 304 if(xhr.status==404 && xhr.responseText) { 305 data = JSON.parse(xhr.responseText); 306 $("#exist-"+data['out']).hide(); 307 $("#success-"+data['out']).show(); 308 } 309 } 310 }); 311 } 312 }); 313 // Scroll to comment 314 $.each(response, function(key, val) { 315 if (val.parentId == '') { 316 $('.tx_nsnewscomments .thanksmsg').show(); 317 $('html, body').stop().animate({ 318 scrollTop: ($('.tx_nsnewscomments .thanksmsg').offset().top) 319 }, 2000); 320 setTimeout(function() { 321 $('.tx_nsnewscomments .thanksmsg').fadeOut("slow"); 322 }, 7000); 323 } else { 324 325 $('.tx_nsnewscomments .thanksmsg-' + val.parentId).show(); 326 $('html, body').stop().animate({ 327 scrollTop: ($('.tx_nsnewscomments .thanksmsg-' + val.parentId).offset().top) 328 }, 2000); 329 setTimeout(function() { 330 $('.tx_nsnewscomments .thanksmsg-' + val.parentId).fadeOut("slow"); 331 }, 7000); 332 $('.tx_nsnewscomments #comments-' + val.parentId).fadeIn('slow'); 333 $('.tx_nsnewscomments #parentId').val(''); 334 } 335 }); 336 } 337 if(statusTxt == "error"){ 338 alert("Error: " + jqXHR.status + " " + jqXHR.statusText); 339 } 340 }); 341 } else { 342 try { 343 data = JSON.parse(response); 344 if (data.status == 'success') { 345 $('.tx_nsnewscomments .approve').show(); 346 $('html, body').stop().animate({ 347 scrollTop: ($('.tx_nsnewscomments .approve').offset().top) 348 }, 2000); 349 setTimeout(function () { 350 $('.tx_nsnewscomments .approve').fadeOut("slow"); 351 }, 7000); 352 } else if (data.status ==='securityerror') { 353 $('.tx_nsnewscomments .security-error .ns-alert-error').html(data.errormsg); 354 $('.tx_nsnewscomments .security-error').show(); 355 $('html, body').stop().animate({ 356 scrollTop: ($('.tx_nsnewscomments .security-error').offset().top) 357 }, 2000); 358 setTimeout(function () { 359 $('.tx_nsnewscomments .security-error').fadeOut("slow"); 360 }, 7000); 361 } else { 362 commentError(); 363 } 364 } catch (e) { 365 commentError(); 366 } 367 } 368 }, 369 error: function(jqXHR, textStatus, errorThrown) { 370 alert(textStatus + " " + errorThrown); 371 }, 372 complete: function(response) { 373 $('.tx_nsnewscomments #comment-form')[0].reset(); 374 var tools = $('#commentBoxSetup').val(); 375 if (tools) { 376 tinyMCE.remove(); 377 } 378 var captcha = document.getElementById("captcha"); 379 if(captcha){ 380 refreshCaptcha(); 381 } 382 $('.tx_nsnewscomments #submit').attr('disabled', false); 383 $('.tx_nsnewscomments #submit').css('cursor', 'pointer'); 384 if(formRating.length > 0){ 385 formRating.barrating('clear'); 386 } 387 addnewsForm(); 388 clearFormFields(); 389 initTincyMCE(); 390 }, 391 }); 392 event.preventDefault(); 393 } else { 394 return false;
395 } 396 } 397 }); 398 399 // Reply form 400 $(document).on("click", '.tx_nsnewscomments .reply', function(event) { 401 $('.comment-btn.reply').show(); 402 var parentCommentId = $(this).parent().attr('id'); 403 $('.active-comment-form').find('.tox-tinymce').remove(); 404 var commentHTML = $('.active-comment-form').html(); 405 $('.active-comment-form .comment-form')[0].reset(); 406 $('.active-comment-form').html(''); 407 $('.active-comment-form').removeClass('active-comment-form'); 408 $(this).parent().parent().parent().parent().find('#reply-form-' + parentCommentId).append(commentHTML); 409 $(this).parent().parent().parent().parent().find('#reply-form-' + parentCommentId).addClass('active-comment-form'); 410 $('#comment-form-close-btn').show(); 411 $('.br-widget').remove(); 412 413 $('.form-star-rating').each(function(e) { 414 $(this).barrating({ 415 theme: 'css-stars', 416 showSelectedRating: false, 417 allowEmpty: true, 418 emptyValue: 0, 419 initialRating:1 420 }); 421 }); 422 removeDefaultValidation(); 423 424 // Scroll to form position 425 $('html, body').stop().animate({ 426 scrollTop: ($('.tx_nsnewscomments #reply-form-' + parentCommentId).offset().top) 427 }, 1000); 428 429 // Set hidden parentId 430 $('.tx_nsnewscomments #parentId').val(parentCommentId); 431 onFocusnewsValidation(); 432 }); 433 434 // Close form 435 $(document).on("click", ".tx_nsnewscomments #comment-form-close-btn", function(event) { 436 var parentCommentIdClose = $('#parentId').val(); 437 $('#'+ parentCommentIdClose + ' .comment-btn.reply').show(); 438 addnewsForm(); 439 }); 440} 441 442// Open form on close button click 443function addnewsForm() { 444 var commentHTML = $('.active-comment-form').html(); 445 $('.tx_nsnewscomments .active-comment-form').html(''); 446 $('.tx_nsnewscomments .active-comment-form').removeClass('active-comment-form'); 447 $('.tx_nsnewscomments #form-comment-view').html(commentHTML); 448 $('.br-widget').remove(); 449 $('.tx_nsnewscomments #form-comment-view').addClass('active-comment-form'); 450 $('.form-star-rating').each(function(e) { 451 $(this).barrating({ 452 theme: 'css-stars', 453 showSelectedRating: false, 454 allowEmpty: true, 455 emptyValue: 0, 456 initialRating:1 457 }); 458 }); 459 $('.tx_nsnewscomments #comment-form-close-btn').hide(); 460 $('.tx_nsnewscomments #parentId').val(''); 461 removeDefaultValidation(); 462 onFocusnewsValidation(); 463 refreshrenewscaptcha(); 464} 465 466function commentError() { 467 $('.tx_nsnewscomments .approve-error').show(); 468 $('html, body').stop().animate({ 469 scrollTop: ($('.tx_nsnewscomments .approve-error').offset().top) 470 }, 2000); 471 setTimeout(function () { 472 $('.tx_nsnewscomments .approve-error').fadeOut("slow"); 473 }, 7000); 474} 475 476// Custom Validation 477function validatenewsField() { 478 var flag = 1; 479 var elementObj; 480 var captcha = document.getElementById("captcha"); 481 var googlecaptcha = document.getElementById("googlecaptcha"); 482 var terms = document.getElementsByName('tx_nsnewscomments_newscomment[newComment][terms]').length; 483 let filesize = 0; 484 var tools = $('#commentBoxSetup').val(); 485 486 if (!$('.tx_nsnewscomments #name').val()) { 487 $(".tx_nsnewscomments #name").parent().addClass('has-error'); 488 $('.tx_nsnewscomments #name_error').show(); 489 var flag = 0; 490 } else { 491 if (!validateName($('.tx_nsnewscomments #name').val())) { 492 $(".tx_nsnewscomments #name_error_msg").show(); 493 $(".tx_nsnewscomments #name_error").hide(); 494 $(".tx_nsnewscomments #name").parent().addClass('has-error'); 495 var flag = 0; 496 } else { 497 $(".tx_nsnewscomments #name").parent().removeClass('has-error'); 498 $(".tx_nsnewscomments #name_error_msg").hide(); 499 $(".tx_nsnewscomments #name_error").hide(); 500 } 501 } 502 503 if (!$('.tx_nsnewscomments #email').val()) { 504 $(".tx_nsnewscomments #email").parent().addClass('has-error'); 505 $(".tx_nsnewscomments #email_error").show(); 506 $(".tx_nsnewscomments #email_error_msg").hide(); 507 var flag = 0; 508 } else { 509 if (!validateEmail($('.tx_nsnewscomments #email').val())) { 510 $(".tx_nsnewscomments #email_error_msg").show(); 511 $(".tx_nsnewscomments #email_error").hide(); 512 $(".tx_nsnewscomments #email").parent().addClass('has-error'); 513 var flag = 0; 514 } else { 515 $(".tx_nsnewscomments #email").parent().removeClass('has-error'); 516 } 517 } 518 519 if (!$('.tx_nsnewscomments #comment').val() && (tools == null)) { 520 $(".tx_nsnewscomments #comment").parent().addClass('has-error'); 521 $(".tx_nsnewscomments #comment_error").show(); 522 var flag = 0; 523 } else if($('.tx_nsnewscomments #comment').val() && (tools == null)){ 524 var length = $.trim($(".tx_nsnewscomments #comment").val()).length; 525 if (length == 0) { 526 $(".tx_nsnewscomments #comment_error").show(); 527 $(".tx_nsnewscomments #comment").parent().addClass('has-error'); 528 var flag = 0; 529 } else { 530 $(".tx_nsnewscomments #comment").parent().removeClass('has-error'); // remove it 531 } 532 } else if(!$('.tx_nsnewscomments #comment').val() && (tools != null)) { 533 $( ".tox" ).append( '<div class="error-msg" style="display:block;" id="comment_error"><p>Comment Is Required!</p></div>' ); 534 $(".tx_nsnewscomments #comment").parent().addClass('has-error'); 535 } else { 536 $(".tx_nsnewscomments #comment").parent().removeClass('has-error'); // remove it 537 } 538 539 if(captcha){ 540 if (!$('.tx_nsnewscomments #captcha').val()) { 541 $(".tx_nsnewscomments #captcha").parent().addClass('has-error'); 542 $(".tx_nsnewscomments #captcha_error").show(); 543 $(".tx_nsnewscomments #captcha_valid_error").hide(); 544 var flag = 0; 545 } else { 546 if (validateCaptcha($('.tx_nsnewscomments #captcha').val()) == 'true') { 547 $(".tx_nsnewscomments #captcha").parent().removeClass('has-error'); // remove it 548 } else { 549 $(".tx_nsnewscomments #captcha_valid_error").show(); 550 $(".tx_nsnewscomments #captcha_error").hide(); 551 $(".tx_nsnewscomments #captcha").parent().addClass('has-error'); 552 var flag = 0; 553 } 554 } 555 } 556 557 if (terms) { 558 if ( !$('.tx_nsnewscomments input[name="tx_nsnewscomments_newscomment[newComment][terms]"]:checked').length ) { 559 $(".tx_nsnewscomments #terms").closest('.ns-form-group').addClass('has-error'); 560 $(".tx_nsnewscomments #terms_error").show(); 561 var flag = 0; 562 } else { 563 $(".tx_nsnewscomments #terms").closest('.ns-form-group').removeClass('has-error'); 564 $(".tx_nsnewscomments #terms_error").hide(); 565 } 566 } 567 568 if (googlecaptcha) { 569 if (grecaptcha.getResponse() == "") { 570 $(".tx_nsnewscomments #googlecaptcha").closest('.ns-form-group').addClass('has-error'); 571 $(".tx_nsnewscomments #googlecaptcha_error").show(); 572 var flag = 0; 573 } else { 574 $(".tx_nsnewscomments #googlecaptcha").closest('.ns-form-group').removeClass('has-error'); 575 $(".tx_nsnewscomments #googlecaptcha_error").hide(); 576 } 577 } 578 579 if($('#customfileupload').length > 0) { 580 let fileField = $('#customfileupload')[0]; 581 let fileLength = fileField.files.length; 582 let files = fileField.files; 583 for (var x = 0; x < fileLength; x++) { 584 filesize += files[x].size; 585 } 586 587 if(filesize > imageMaxSize){ 588 var flag = 0; 589 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').addClass('has-error'); 590 $('.tx_nsnewscomments #maxsize_error').show(); 591 } else { 592 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').removeClass('has-error'); 593 $('.tx_nsnewscomments #maxsize_error').hide(); 594 } 595 } 596 597 if ($('.error-msg-red').length) { 598 var flag = 0; 599 } 600 601 if (flag == 1) { 602 return true; 603 } 604 return false;
605} 606 607// Custom validation for onfocus 608function onFocusnewsValidation() { 609 var tools = $('#commentBoxSetup').val(); 610 $(".tx_nsnewscomments #name").focusout(function() { 611 elementObj = $(this); 612 if (elementObj.val() != '') { 613 if (!validateName($('.tx_nsnewscomments #name').val())) { 614 $(".tx_nsnewscomments #name_error_msg").show(); 615 $(".tx_nsnewscomments #name_error").hide(); 616 $(".tx_nsnewscomments #name").parent().addClass('has-error'); 617 var flag = 0; 618 } else { 619 elementObj.parent().removeClass('has-error'); 620 $(".tx_nsnewscomments #name_error_msg").hide(); 621 $(".tx_nsnewscomments #name_error").hide(); 622 } 623 } else { 624 $(".tx_nsnewscomments #name").parent().addClass('has-error'); 625 $(".tx_nsnewscomments #name_error").show(); 626 $(".tx_nsnewscomments #name_error_msg").hide(); 627 } 628 }); 629 630 $(".tx_nsnewscomments #email").focusout(function() { 631 elementObj = $(this); 632 if (elementObj.val() != '') { 633 if (!validateEmail($('.tx_nsnewscomments #email').val())) { 634 $(".tx_nsnewscomments #email_error_msg").show(); 635 $(".tx_nsnewscomments #email_error").hide(); 636 $(".tx_nsnewscomments #email").parent().addClass('has-error'); 637 var flag = 0; 638 } else { 639 elementObj.parent().removeClass('has-error'); 640 $(".tx_nsnewscomments #email_error_msg").hide(); 641 $(".tx_nsnewscomments #email_error").hide(); 642 } 643 } else { 644 $(".tx_nsnewscomments #email").parent().addClass('has-error'); 645 $(".tx_nsnewscomments #email_error").show(); 646 $(".tx_nsnewscomments #email_error_msg").hide(); 647 } 648 }); 649 650 if (!$('.tx_nsnewscomments #comment').val() && (tools == null)) { 651 $(".tx_nsnewscomments #comment").focusout(function() { 652 elementObj = $(this); 653 if (elementObj.val() != '') { 654 var length = $.trim($(".tx_nsnewscomments #comment").val()).length; 655 if (length == 0) { 656 $(".tx_nsnewscomments #comment_error").show(); 657 $(".tx_nsnewscomments #comment").parent().addClass('has-error'); 658 var flag = 0; 659 } else { 660 $(".tx_nsnewscomments #comment").parent().removeClass('has-error'); // remove it 661 $(".tx_nsnewscomments #comment_error").hide(); 662 } 663 664 } else { 665 $(".tx_nsnewscomments #comment").parent().addClass('has-error'); 666 $(".tx_nsnewscomments #comment_error").show(); 667 } 668 }); 669 } 670 $(".tx_nsnewscomments #captcha").focusout(function() { 671 elementObj = $(this); 672 if (elementObj.val() != '') { 673 var length = $.trim($(".tx_nsnewscomments #captcha").val()).length; 674 if (length == 0) { 675 $(".tx_nsnewscomments #captcha_error").show(); 676 $(".tx_nsnewscomments #captcha").parent().addClass('has-error'); 677 var flag = 0; 678 } else { 679 $(".tx_nsnewscomments #captcha").parent().removeClass('has-error'); // remove it 680 $(".tx_nsnewscomments #captcha_error").hide(); 681 $(".tx_nsnewscomments #captcha_valid_error").hide(); 682 } 683 } else { 684 $(".tx_nsnewscomments #captcha").parent().addClass('has-error'); 685 $(".tx_nsnewscomments #captcha_error").show(); 686 } 687 }); 688 689 $('.tx_nsnewscomments input[name="tx_nsnewscomments_newscomment[newComment][terms]"]').on('change', function(){ 690 if ( !$('.tx_nsnewscomments input[name="tx_nsnewscomments_newscomment[newComment][terms]"]:checked').length ) { 691 $(".tx_nsnewscomments #terms").closest('.ns-form-group').addClass('has-error'); 692 $(".tx_nsnewscomments #terms_error").show(); 693 var flag = 0; 694 } else { 695 $(".tx_nsnewscomments #terms").closest('.ns-form-group').removeClass('has-error'); 696 $(".tx_nsnewscomments #terms_error").hide(); 697 } 698 }); 699 700} 701 702// Remove Default Validation in reply form 703function removeDefaultValidation() { 704 $(".tx_nsnewscomments #name").parent().removeClass('has-error'); // remove it 705 $(".tx_nsnewscomments #name_error").hide(); 706 $(".tx_nsnewscomments #name_error_msg").hide(); 707 708 $(".tx_nsnewscomments #email").parent().removeClass('has-error'); 709 $(".tx_nsnewscomments #email_error").hide(); 710 $(".tx_nsnewscomments #email_error_msg").hide(); 711 712 $(".tx_nsnewscomments #comment").parent().removeClass('has-error'); 713 $(".tx_nsnewscomments #comment_error").hide(); 714 715 $(".tx_nsnewscomments #captcha").parent().removeClass('has-error'); 716 $(".tx_nsnewscomments #captcha_error").hide(); 717 $(".tx_nsnewscomments #captcha_valid_error").hide(); 718 719 $(".tx_nsnewscomments .googlecaptcha").removeClass('has-error'); 720 $(".tx_nsnewscomments #googlecaptcha_error").hide(); 721 722 $(".tx_nsnewscomments #terms").parent().removeClass('has-error'); 723 $(".tx_nsnewscomments #terms_error").hide(); 724} 725 726// Validate Captcha field using ajax request 727function validateCaptcha(captcha) { 728 729 var dataString = 'captcha=' + captcha; 730 var url = $('.verification').val(); 731 var response = $.ajax({ 732 type: 'POST', 733 async: false, 734 url: url, 735 data: dataString, 736 success: function(response) { 737 738 }, 739 error: function() { 740 alert('Captcha not Mathched'); 741 } 742 }); 743 return response.responseText; 744} 745 746// Validate Email field 747function validateEmail($email) { 748 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; 749 return emailReg.test($email); 750} 751 752// Validate Name field 753function validateName($name) { 754 var nameReg = /[^0-9]/g; 755 return nameReg.test($name); 756} 757 758// Referech Captcha 759function refreshCaptcha() { 760 var img = document.images['captchaimg']; 761 img.src = img.src.substring(0, img.src.lastIndexOf("?")) + "?rand=" + Math.random() * 1000; 762} 763 764$(document).on('change', '#customfileupload', function () { 765 var items = $(this)[0].files; 766 var filesize = 0; 767 let typesArray = imageTypes.split(" ").join("").split(','); 768 var allowedTypes = []; 769 var realType = items["0"].type.substring(items["0"].type.indexOf("/") + 1); 770 var find = ["+xml", "vnd.openxmlformats-officedocument.wordprocessingml.document"]; 771 var replace = ["", "docx"]; 772 realType = realType.replaceArray(find, replace); 773 $(typesArray).each(function (g, h) { 774 allowedTypes.push(h.split(" ").join(' +')); 775 }); 776 let fileField = $('#customfileupload')[0]; 777 let fileLength = fileField.files.length; 778 let files = fileField.files; 779 for (var x = 0; x < fileLength; x++) { 780 filesize += files[x].size; 781 } 782 783 if(filesize > imageMaxSize){ 784 var flag = 0; 785 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').addClass('has-error'); 786 $('.tx_nsnewscomments #maxsize_error').show(); 787 } else { 788 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').removeClass('has-error'); 789 $('.tx_nsnewscomments #maxsize_error').hide(); 790 } 791 if (items["0"].type === "" || allowedTypes.indexOf(realType.replace('+xml','')) === -1) { 792 $(this).find('label').css('border', '1px dashed #f32649'); 793 } else { 794 $(this).find('label').css('border', '1px dashed #2a8704'); 795 upload($(this)[0].files); 796 } 797}); 798 799//Drag & Drop Functions for the files 800$(document).on('dragover', '.custom-file-upload', function (e) { 801 e.preventDefault(); 802 e.stopPropagation(); 803 var items = e.originalEvent.dataTransfer.items; 804 let typesArray = imageTypes.split(" ").join("").split(','); 805 var allowedTypes = []; 806 var realType = items["0"].type.substring(items["0"].type.indexOf("/") + 1); 807 808 var find = ["+xml", "vnd.openxmlformats-officedocument.wordprocessingml.document"]; 809 var replace = ["", "docx"]; 810 realType = realType.replaceArray(find, replace); 811 $(typesArray).each(function (g, h) { 812 allowedTypes.push(h.split(" ").join(' +')); 813 }); 814 $.each(items,function (k,v){ 815 if (items[k].kind !== "file" || items[k].type === "" || allowedTypes.indexOf(realType.replace('+xml','')) === -1) { 816 $(this).find('label').css('border', '1px dashed #f32649'); 817 e.originalEvent.dataTransfer.dropEffect = "none"; 818 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').addClass('has-error'); 819 $('.tx_nsnewscomments #invalidfile_error').show(); 820 } 821 }) 822}); 823 824$(document).on('dragenter', '.custom-file-upload', function (e) { 825 e.preventDefault(); 826 e.stopPropagation(); 827}); 828 829$(document).on('drop', '.custom-file-upload', function (e) { 830 if (e.originalEvent.dataTransfer) { 831 if (e.originalEvent.dataTransfer.files.length) { 832 var filesize = 0; 833 e.preventDefault(); 834 e.stopPropagation(); 835 /*UPLOAD FILES HERE*/ 836 var items = e.originalEvent.dataTransfer.items; 837 let typesArray = imageTypes.split(" ").join("").split(','); 838 var allowedTypes = []; 839 var realType = items["0"].type.substring(items["0"].type.indexOf("/") + 1); 840 var find = ["+xml", "vnd.openxmlformats-officedocument.wordprocessingml.document"]; 841 var replace = ["", "docx"]; 842 843 realType = realType.replaceArray(find, replace); 844 $(typesArray).each(function (g, h) { 845 allowedTypes.push(h.split(" ").join(' +')); 846 }); 847 let fileLength = e.originalEvent.dataTransfer.files.length; 848 let files = e.originalEvent.dataTransfer.files; 849 for (var x = 0; x < fileLength; x++) { 850 filesize += files[x].size; 851 } 852 if(filesize > imageMaxSize){ 853 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').addClass('has-error'); 854 $('.tx_nsnewscomments #maxsize_error').show(); 855 } else { 856 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').removeClass('has-error'); 857 $('.tx_nsnewscomments #maxsize_error').hide(); 858 } 859 if (items["0"].kind !== "file" || items["0"].type === "" || allowedTypes.indexOf(realType.replace('+xml','')) === -1) { 860 $(this).find('label').css('border', '1px dashed #f32649'); 861 } else { 862 $(this).find('label').css('border', '1px dashed #2a8704'); 863 uploadDrop(e.originalEvent.dataTransfer.files); 864 $('.tx_nsnewscomments #customfileupload').closest('.ns-form-group').removeClass('has-error'); 865 $('.tx_nsnewscomments #invalidfile_error').hide(); 866 } 867 } 868 } 869}); 870 871 872function upload(files) { 873 $('#file-label').text(files.length + " " + selectedLLL); 874 imagesPreview(document.getElementById('customfileupload'), 'div#nsnewscomment-screenshot-group'); 875} 876 877function uploadDrop(files) { 878 $('#file-label').text(files.length + " " + selectedLLL); 879 $("#customfileupload")[0].files = files; 880 imagesPreview(document.getElementById('customfileupload'), 'div#nsnewscomment-screenshot-group'); 881} 882 883let imagesPreview = function (input, placeToInsertImagePreview) { 884 let filesize = 0; 885 if (input.files) { 886 $('.screenshot-group').css('display', 'inline-block'); 887 $(placeToInsertImagePreview).html(''); 888 let filesAmount = input.files.length; 889 let _i = 0; 890 for (let i = 0; i < filesAmount; i++) { 891 _i = i; 892 let name = input.files[i].name; 893 filesize += input.files[i].size; 894 let reader = new FileReader(); 895 reader.onload = (function (index) { 896 return function (e) { 897 let html = '<div class="screenshot-block">'; 898 var allowedTypes = ['png','svg','jpg','jpeg','webm','gif']; 899 var realType = input.files[index].type.substring(input.files[index].type.indexOf("/") + 1); 900 if (allowedTypes.indexOf(realType.replace('+xml','')) === -1) { 901 html += '<img src="' + pdfIcon + '" alt="" width="57px" height="57px" />'; 902 } else { 903 html += '<img src="' + e.target.result + '" alt="" width="57px" height="57px" />'; 904 } 905 html += ' <span>' + input.files[index].name + '</span>'; 906 html += '</div>'; 907 $($.parseHTML(html)).appendTo(placeToInsertImagePreview); 908 }; 909 })(_i);
910 reader.readAsDataURL(input.files[i]); 911 } 912 } 913}; 914 915function setDefaultImageTypes(elem) { 916 if (elem.length > 0) { 917 let typesArray = imageTypes.split(" ").join("").split(','); 918 var allowedTypes = []; 919 $(typesArray).each(function (g, h) { 920 allowedTypes.push("." + h.split(" ").join(' +')); 921 }); 922 elem.attr('accept', allowedTypes.toString()); 923 } 924} 925 926function GetURLParameter(sParam) 927{ 928 var sPageURL = window.location.search.substring(1); 929 var sURLVariables = sPageURL.split('&'); 930 for (var i = 0; i < sURLVariables.length; i++) 931 { 932 var sParameterName = sURLVariables[i].split('='); 933 if (sParameterName[0] == sParam) 934 { 935 return sParameterName[1]; 936 } 937 } 938} 939 940 941function clearFormFields () { 942 var html = ''; 943 $('.screenshot-group').hide(); 944 $("#file-label").text('Drop files to upload, or'); 945 $(".custom-file-upload label").css('border', '1px dashed #999999'); 946} 947 948$(document).on('submit','#confirmForm',function (e){ 949 e.preventDefault(); 950 951}); 952 953$(document).on('click', '.confirmButton', function (){ 954 url = $("#actionUrl").attr('href'); 955 $.ajax({ 956 url: url, 957 method:'post', 958 data: {confirm: $(this).data('value'), Accesstoken:$(this).data('accesstoken')}, 959 success: function (data) { 960 $('.approvenewscomment #popup_box').remove(); 961 $('.approvenewscomment').html(data); 962 shownewspopup(); 963 } 964 }) 965}) 966String.prototype.replaceArray = function(find, replace) { 967 var replaceString = this; 968 for (var i = 0; i < find.length; i++) { 969 replaceString = replaceString.replace(find[i], replace[i]); 970 } 971 return replaceString; 972}; 973 974// Start Comment Like/Dislike Code..... 975 976$(document).ready(function(){ 977 978 $('.commentLikes').each(function(e) { 979 var idForComment = $(this).data('uid'); 980 var checkupdownvalue = $(this).data('pid'); 981 982 if ($.cookie('rateLikeChange_' + idForComment)){ 983 if (checkupdownvalue == '1'){ 984 $(".rate_id_"+idForComment).attr('disabled', 'disabled'); 985 $(".rate_dislike_id_"+idForComment).removeAttr("disabled"); 986 } 987 else if (checkupdownvalue == '2'){ 988 $(".rate_dislike_id_"+idForComment).attr('disabled', 'disabled'); 989 $(".rate_id_"+idForComment).removeAttr("disabled"); 990 } 991 } 992 else{ 993 $(".rate_id_"+idForComment).removeAttr("disabled"); 994 $(".rate_dislike_id_"+idForComment).removeAttr("disabled"); 995 } 996 }); 997 998 $(document).on('click','#comment-like-btn', function (e) { 999 var commentUid = $(this).data('uid'); 1000 var updateUrl = $(this).data('link'); 1001 var btnId = "comment-like-btn"; 1002 var reaction = "1"; 1003 $(".rate_id_"+commentUid).attr('disabled', 'disabled'); 1004 $.ajax({ 1005 type: "GET", 1006 url: updateUrl, 1007 success:function(anscount){ 1008 if(anscount){ 1009 obj = JSON.parse(anscount); 1010 $("#rate_id_"+commentUid).text(obj.voteup); 1011 $("#rate_dislike_id_"+commentUid).text(obj.votedown); 1012 1013 if ($.cookie('rateLikeChange_' + commentUid)) 1014 { 1015 $(".rate_id_"+commentUid).attr('disabled', 'disabled'); 1016 $(".rate_dislike_id_"+commentUid).removeAttr("disabled"); 1017 } 1018 } 1019 }, 1020 error:function (xhr, anscount, thrownError){ 1021 if(xhr.status==404 && xhr.responseText) { 1022 obj = JSON.parse(xhr.responseText); 1023 $("#rate_id_"+commentUid).text(obj.voteup); 1024 $("#rate_dislike_id_"+commentUid).text(obj.votedown); 1025 1026 if ($.cookie('rateLikeChange_' + commentUid)) 1027 { 1028 $(".rate_id_"+commentUid).attr('disabled', 'disabled'); 1029 $(".rate_dislike_id_"+commentUid).removeAttr("disabled"); 1030 } 1031 } 1032 } 1033 }); 1034 }); 1035 1036 $(document).on('click','#comment-dislike-btn', function (e) { 1037 var commentUid = $(this).data('uid'); 1038 var updateUrl = $(this).data('link'); 1039 var btnId = "comment-dislike-btn"; 1040 var reaction = "0"; 1041 $(".rate_dislike_id_"+commentUid).attr('disabled', 'disabled'); 1042 $.ajax({ 1043 url: updateUrl, 1044 success:function (anscount) { 1045 if(anscount){ 1046 obj = JSON.parse(anscount); 1047 $("#rate_dislike_id_"+commentUid).text(obj.votedown); 1048 $("#rate_id_"+commentUid).text(obj.voteup); 1049 1050 if ($.cookie('rateLikeChange_' + commentUid)) 1051 { 1052 $(".rate_dislike_id_"+commentUid).attr('disabled', 'disabled'); 1053 $(".rate_id_"+commentUid).removeAttr("disabled"); 1054 } 1055 } 1056 }, 1057 error:function (xhr, anscount, thrownError){ 1058 if(xhr.status==404 && xhr.responseText) { 1059 obj = JSON.parse(xhr.responseText); 1060 $("#rate_dislike_id_"+commentUid).text(obj.votedown); 1061 $("#rate_id_"+commentUid).text(obj.voteup); 1062 1063 if ($.cookie('rateLikeChange_' + commentUid)) 1064 { 1065 $(".rate_dislike_id_"+commentUid).attr('disabled', 'disabled'); 1066 $(".rate_id_"+commentUid).removeAttr("disabled"); 1067 } 1068 } 1069 } 1070 }); 1071 }); 1072}); 1073 1074// End Comment Like/Dislike Code.....
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.