1/** 2 * Kevon Adonis 3 * Copyright 2018 4 * http://www.wpabstracts.com 5 */ 6 7String.prototype.stripSlashes = function () { 8 return this.replace(/\\(.)/gm, '$1'); 9}; 10 11jQuery(function () { 12 alertify.defaults.overflow = false; 13 alertify.defaults.notifier.delay = 0; 14 alertify.defaults.glossary.title = 'Confirmation'; 15 alertify.defaults.transition = 'fade'; 16 17 alertify.customError = function (msg) { 18 alertify.dismissAll(); 19 return alertify.error(msg); 20 }; 21}); 22 23function wp_field_validate(itemId, error) { 24 var currentError = false; 25 if (itemId !== undefined) { 26 itemId = itemId.replace('[]', '\\[\\]'); 27 var inputItem = jQuery('#' + itemId); 28 if (inputItem.val() === '') { 29 console.log('Empty @ ', inputItem.attr('id')); 30 inputItem.addClass('required-field'); 31 inputItem.parent().addClass('has-error'); 32 currentError = true; 33 } else { 34 inputItem.parent().removeClass('has-error'); 35 inputItem.removeClass('required-field'); 36 } 37 } 38 return currentError + error; 39} 40 41function wp_radio_validate(itemName, error) { 42 var currentError = false; 43 if (itemName !== undefined) { 44 var inputItem = jQuery('input[name="' + itemName + '"]'); 45 var isValid = jQuery('input[name="' + itemName + '"]:checked').length; 46 if (!isValid) { 47 console.log('Empty @ ', itemName); 48 inputItem.parent().parent().addClass('has-error'); 49 currentError = true; 50 } else { 51 inputItem.parent().parent().removeClass('has-error'); 52 } 53 } 54 return currentError + error; 55} 56 57function wp_email_validate(email) { 58 var regex = 59 /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; 60 return regex.test(email); 61} 62 63// checks to see if a particular editor (editor_id) or an activeEditor is present or active 64function wpabstracts_is_editor_active(editor_id) { 65 if (typeof tinyMCE == 'undefined') { 66 return false; 67 } 68 69 if (typeof editor_id == 'undefined') { 70 editor = tinyMCE.activeEditor; 71 } else { 72 editor = tinyMCE.EditorManager.get(editor_id); 73 } 74 75 if (editor == null) { 76 return false; 77 } 78 79 return !editor.isHidden(); 80} 81 82function wpabstracts_add_attachment(parentId, maxAllowed) { 83 jQuery('#' + parentId).append( 84 '<div><input type="file" name="attachments[]"/></div>' 85 ); 86 var count = jQuery('input[name="attachments[]"]').length; 87 if (count >= maxAllowed) { 88 jQuery('.add_attachments').remove(); 89 } 90} 91 92function wpabstracts_remove_attachment(id) { 93 var attachment_id = id; 94 jQuery('#attachment_' + attachment_id).remove(); 95 jQuery('#manage_attachments').append( 96 '<input type="hidden" name="abs_remove_attachments[]" value ="' + 97 attachment_id + 98 '">' 99 ); 100 101 //refresh upload box 102 var max_uploads = jQuery('#wpabstracts_upload_limit').val(); 103 var current_attactments = jQuery('.wpabstracts_attachments_counter').length; 104 var atts_input = jQuery('input[name=attachments\\[\\]]').length; 105 var atts_remaining = max_uploads - (current_attactments + atts_input); 106 107 for (var i = 0; i < atts_remaining; i++) { 108 var new_input = jQuery( 109 '<dd><input type="file" id="abs_attachmment_' + 110 i + 111 '" name="attachments[]"><span class="wpabstracts glyphicon glyphicon-refresh remove_file" onclick="wpabstracts_refresh_file(this);"></span></dd>' 112 ); 113 jQuery('.wpabstracts_upload_disallowed').addClass('hidden'); 114 jQuery('.wpabstracts_attachments').append(new_input); 115 } 116 if (!current_attactments) { 117 jQuery('.manage_attachments').append( 118 '<p>' + wpabstracts.no_attachments + '</p>' 119 ); 120 } 121} 122 123function wpabstracts_remove_review_attachment(att_id) { 124 jQuery('#review_attachment_' + att_id).remove(); 125 jQuery('#review_attactments').append( 126 '<input type="hidden" name="remove_review_attachment" value ="' + 127 att_id + 128 '">' 129 ); 130 jQuery('#review_attactments').append( 131 '<input type="file" name="review_attachment">' 132 ); 133} 134 135function wpabstracts_getFileExt(filename) { 136 var arr = filename.split('.'); 137 if (arr.length === 1 || (arr[0] === '' && arr.length === 2)) { 138 return ''; 139 } 140 return arr.pop().toLowerCase(); 141} 142 143function wpabstracts_validateAttachments() { 144 var error = false; 145 var attachments = jQuery('input[name=attachments\\[\\]]'); 146 for (var ii = 0; ii < attachments.length; ii++) { 147 var file = attachments[ii].files[0]; 148 if (file) { 149 var file_ext = wpabstracts_getFileExt(file.name); 150 var file_size = file.size; 151 152 // checks file type is approved 153 if (wpabstracts.approved_exts.indexOf(file_ext) == -1) { 154 alertify.customError(wpabstracts.file_ext_err); 155 error = true; 156 } 157 // check is file is within size limits 158 if (file_size > wpabstracts.max_atts_size) { 159 alertify.customError(wpabstracts.file_size_err); 160 error = true; 161 } 162 } 163 } 164 return error; 165} 166 167function wpabstracts_validateAbstract() { 168 var errors = false;
169 var maxCount = jQuery('.max-word-count').text(); 170 var content = null; 171 var count = 0; 172 var allEmailsValid = true; 173 174 if (jQuery('#abstext').length) { 175 // see if description is enabled 176 if (wpabstracts_is_editor_active()) { 177 content = jQuery.trim(tinyMCE.activeEditor.getContent()); 178 } else { 179 content = jQuery.trim(jQuery('#abstext').val()); 180 } 181 if (content.length > 0) { 182 count = content.replace(/\s+/gi, ' ').split(' ').length; 183 184 if (count > maxCount) { 185 alertify.customError(wpabstracts.word_count_err); 186 return; 187 } 188 } else { 189 errors = false; 190 alertify.customError(wpabstracts.desc_required); 191 return; 192 } 193 } 194 195 jQuery('#abs_form .wpa_event_input') 196 .not('.optional') 197 .each(function () { 198 errors = wp_field_validate(jQuery(this).attr('id'), errors); 199 }); 200 201 jQuery("#abs_form :input[type='email']").each(function () { 202 if (!wp_email_validate(jQuery(this).val())) { 203 jQuery(this).addClass('required-field'); 204 allEmailsValid = false; 205 } else { 206 jQuery(this).removeClass('required-field'); 207 } 208 }); 209 210 var abs_terms = jQuery("#abs_form input[name='abs_terms']"); 211 212 if (jQuery(abs_terms).length > 0 && !jQuery(abs_terms).prop('checked')) { 213 jQuery(abs_terms).parent().addClass('wpabstracts text-danger'); 214 errors = true; 215 } else { 216 jQuery(abs_terms).parent().removeClass('text-danger'); 217 } 218 219 var att_error = wpabstracts_validateAttachments(); 220 221 if (errors) { 222 alertify.customError(wpabstracts.required_fields); 223 } 224 225 if (!allEmailsValid) { 226 alertify.customError(wpabstracts.invalid_email); 227 } 228 229 if (!errors && !att_error && allEmailsValid) { 230 alertify.dismissAll(); 231 alertify.success('Saving...'); 232 jQuery('#abs_form').submit(); 233 } 234} 235 236function wpabstracts_validateUser() { 237 var errors = false; 238 jQuery('#wpa_profile_form input, #wpa_profile_form select') 239 .not('.optional') 240 .each(function () { 241 if (jQuery(this).parent().hasClass('required')) { 242 errors = wp_field_validate(jQuery(this).attr('id'), errors); 243 } 244 }); 245 246 var terms = jQuery('#terms_conditions'); 247 if (terms.prop('checked') === false) { 248 terms.parent().addClass('has-error'); 249 errors = true; 250 } else { 251 terms.parent().removeClass('has-error'); 252 } 253 254 if (errors) { 255 alertify.customError(wpabstracts.required_fields); 256 } else { 257 jQuery('#wpa_profile_form').submit(); 258 } 259} 260 261function wpabstracts_validateLogin() { 262 var errors = false; 263 jQuery( 264 "#wpa_login_form input[type='text'], #wpa_login_form input[type='password']" 265 ).each(function () { 266 if (jQuery(this).parent().hasClass('required')) { 267 errors = wp_field_validate(jQuery(this).attr('id'), errors); 268 } 269 }); 270 if (errors) { 271 alertify.customError(wpabstracts.required_fields); 272 } else { 273 jQuery('#wpa_login_form').submit(); 274 } 275} 276 277function wpabstracts_validateReview() { 278 var errors = false; 279 jQuery('#wpabs_review_form input[type=text], #wpabs_review_form select') 280 .not('.optional') 281 .each(function () { 282 errors = wp_field_validate(jQuery(this).attr('id'), errors); 283 }); 284 285 jQuery('#wpabs_review_form input[type=radio]') 286 .not('.optional') 287 .each(function () { 288 errors = wp_radio_validate(jQuery(this).attr('name'), errors); 289 }); 290 291 var content = null; 292 if (wpabstracts_is_editor_active()) { 293 content = jQuery.trim(tinyMCE.activeEditor.getContent()); 294 } else { 295 content = jQuery.trim(jQuery('#abs_comments').val()); 296 } 297 if (jQuery('#abs_comments').length && content.length < 1) { 298 errors = true; 299 jQuery('#abs_review_comments_error').addClass('bg-danger'); 300 } else { 301 jQuery('#abs_review_comments_error').removeClass('bg-danger'); 302 } 303 if (errors) { 304 alertify.customError(wpabstracts.required_fields); 305 } else { 306 alertify.dismissAll(); 307 alertify.success('Saving...'); 308 jQuery('#wpabs_review_form').submit(); 309 } 310} 311 312function wpabstracts_add_coauthor() { 313 var author_box = jQuery('.author_box:first').clone(); 314 jQuery(author_box).find('input').val(''); 315 jQuery('#coauthors_table').append(author_box); 316} 317 318function wpabstracts_delete_coauthor() { 319 if (jQuery('#coauthors_table .author_box').length > 1) { 320 jQuery('#coauthors_table').find('.author_box:last').remove(); 321 } 322} 323 324function wpabstracts_add_presenter() { 325 var presenter_box = jQuery('.presenter_box:first').clone(); 326 jQuery(presenter_box).find('input').val(''); 327 jQuery('#presenter_table').append(presenter_box); 328} 329 330function wpabstracts_delete_presenter() { 331 if (jQuery('#presenter_table .presenter_box').length > 1) { 332 jQuery('#presenter_table').find('.presenter_box:last').remove(); 333 } 334} 335 336function wpabstracts_add_status() { 337 var timeStamp = -new Date().valueOf(); 338 var status_box = jQuery('.wpa_status_default:first').clone(); 339 jQuery(status_box) 340 .removeClass('hidden') 341 .removeClass('wpa_status_default') 342 .addClass('wpa_status') 343 .attr('id', timeStamp); 344 jQuery(status_box) 345 .find('input') 346 .attr('name', 'wpabstracts_status[' + timeStamp + ']'); 347 jQuery('#wpa_status_container').append(status_box); 348} 349 350function wpabstracts_delete_status(elem, id) { 351 if (jQuery('.wpa_status').length > 1) { 352 alertify.confirm(wpabstracts.confirm_status_delete, function (e) { 353 if (e) { 354 jQuery(elem).parent('.wpa_status').remove(); 355 jQuery('#wpa_status_container').append( 356 '<input type="hidden" name="wpabstracts_delete_status[]" value ="' + 357 id + 358 '">' 359 ); 360 } 361 }); 362 } else { 363 alertify.customError(wpabstracts.status_required); 364 } 365} 366 367function wpabstracts_add_topic() { 368 var html = 369 '<p><input class="wpabstracts form-control" type="text" name="topics[]" id="topics[]" /></p>'; 370 jQuery('#topics_table').append(html); 371} 372 373function wpabstracts_delete_topic() { 374 if (jQuery('#topics_table input').length > 1) { 375 jQuery('#topics_table').find('p input:last').remove(); 376 } else { 377 alertify.customError(wpabstracts.topic_required); 378 } 379} 380 381function wpabstracts_delete_abstracts(ids, page, isBulk) { 382 var warning = isBulk 383 ? wpabstracts.confirm_abstracts_delete 384 : wpabstracts.confirm_abstract_delete; 385 var formAction = ''; 386 var abs_ids = jQuery(ids).toArray(); 387 alertify.confirm(warning, function (e) { 388 if (e) { 389 if (location.pathname.indexOf('admin') >= 0) { 390 formAction = '?page=wpabstracts&tab=abstracts&task=delete'; 391 var delete_form = jQuery('<form method="post" id="delete_form">').attr( 392 'action', 393 formAction 394 ); 395 jQuery(delete_form).append( 396 '<input name="isBulk" type="hidden" value="' + isBulk + '">' 397 ); 398 jQuery(delete_form).append( 399 '<input name="page" type="hidden" value="' + page + '">' 400 ); 401 abs_ids.forEach(function (id) { 402 jQuery(delete_form).append( 403 '<input name="abs_ids[]" type="hidden" value="' + id + '">' 404 ); 405 }); 406 jQuery('body').append(delete_form); 407 jQuery('#delete_form').submit(); 408 } else { 409 location.href = '?task=delete_abstract&id=' + abs_ids[0]; 410 } 411 } 412 }); 413} 414 415function wpabstracts_delete_review(id, page) { 416 alertify.confirm(wpabstracts.confirm_review_delete, function (e) { 417 if (e) { 418 if (location.pathname.indexOf('admin') >= 0) { 419 location.href = 420 '?page=wpabstracts&tab=reviews&task=delete&id=' + 421 id + 422 '&paged=' + 423 page; 424 } else { 425 location.href = '?task=delete_review&id=' + id + ''; 426 } 427 } 428 }); 429} 430 431function wpabstracts_delete_attachment(id, page) { 432 alertify.confirm(wpabstracts.confirm_atts_delete, function (e) { 433 if (e) { 434 location.href = 435 '?page=wpabstracts&tab=attachments&task=delete&id=' + 436 id + 437 '&paged=' + 438 page; 439 } 440 }); 441} 442 443function wpabstracts_delete_user(id, page) { 444 alertify.confirm(wpabstracts.confirm_user_delete, function (e) { 445 if (e) { 446 location.href = 447 '?page=wpabstracts&tab=users&task=delete&id=' + id + '&paged=' + page; 448 } 449 }); 450} 451 452function wpabstracts_delete_event(id, nonce) { 453 alertify.prompt(wpabstracts.confirm_event_delete).setting({ 454 onok: function (closeEvent) {
455 var entry = jQuery('.ajs-input').val(); 456 if (entry && 'DELETE' == entry.toUpperCase()) { 457 location.href = 458 '?page=wpabstracts&tab=events&task=delete&id=' + 459 id + 460 '&_wpnonce=' + 461 nonce; 462 } else { 463 return false; 464 } 465 }, 466 labels: { 467 ok: 'DELETE', 468 cancel: 'Cancel', 469 }, 470 }); 471} 472 473function wpabstracts_delete_template(id, tab) { 474 alertify.confirm(wpabstracts.confirm_template_delete, function (e) { 475 if (e) { 476 location.href = 477 '?page=wpabstracts&tab=' + tab + '&subtab=emails&task=delete&id=' + id; 478 } 479 }); 480} 481 482function wpabstracts_restore_user_formbuilder() { 483 alertify.confirm(wpabstracts.confirm_form_restore, function (e) { 484 if (e) { 485 location.href = 486 '?page=wpabstracts&tab=users&subtab=formbuilder&task=restore'; 487 } 488 }); 489} 490 491function wpabstracts_load_reviewers(ids, paged, isBulk) { 492 var data = { 493 action: 'loadreviewers', 494 abs_ids: jQuery(ids).toArray(), 495 isBulk: isBulk, 496 page: paged, 497 }; 498 499 jQuery.post(wpabstracts.ajaxurl, data).done(function (modal) { 500 jQuery('body').append('<div id="assign_reviewer"></div>'); 501 jQuery('#assign_reviewer').html('').html(modal); 502 jQuery('#assign_reviewer') 503 .dialog({ 504 width: 550, 505 modal: true, 506 closeOnEscape: true, 507 dialogClass: 'assign-reviewer', 508 closeText: '', 509 title: '', 510 buttons: [ 511 { 512 text: 'Close', 513 click: function () { 514 jQuery('#assign_reviewer').dialog('close'); 515 }, 516 class: 'wpa_button cancel', 517 }, 518 ], 519 }) 520 .dialog('open'); 521 }); 522} 523 524function wpabstracts_load_status(ids, paged, isBulk) { 525 var data = { 526 action: 'loadstatus', 527 abs_ids: jQuery(ids).toArray(), 528 isBulk: isBulk, 529 page: paged, 530 }; 531 532 jQuery.post(wpabstracts.ajaxurl, data).done(function (modal) { 533 jQuery('body').append('<div id="change_status"></div>'); 534 jQuery('#change_status').html('').html(modal); 535 jQuery('#change_status') 536 .dialog({ 537 width: 400, 538 modal: true, 539 closeOnEscape: true, 540 dialogClass: 'assign-reviewer', 541 closeText: '', 542 title: wpabstracts.change_status, 543 buttons: [ 544 { 545 text: 'Cancel', 546 click: function () { 547 jQuery('#change_status').dialog('close'); 548 }, 549 class: 'wpa_button cancel', 550 }, 551 { 552 text: 'Change Status', 553 click: function () { 554 jQuery('#change_status_form').submit(); 555 }, 556 class: 'wpa_button success', 557 }, 558 ], 559 }) 560 .dialog('open'); 561 }); 562} 563 564function wpabstracts_load_topics(id) { 565 var data = { 566 action: 'loadtopics', 567 event_id: id, 568 }; 569 jQuery.post(wpabstracts.ajaxurl, data).done(function (data) { 570 jQuery('#abs_topic').html(data); 571 }); 572} 573 574function wpabstracts_updateWordCount() { 575 var content = null; 576 var notified = false; 577 var count = 0; 578 var counterCont = jQuery('.abs-word-count'); 579 var remainingCont = jQuery('.abs-word-remaining'); 580 var maxCount = jQuery('.max-word-count').text(); 581 582 if (wpabstracts_is_editor_active()) { 583 content = jQuery.trim(tinyMCE.activeEditor.getContent()); 584 } else { 585 content = jQuery.trim(jQuery('#abstext').val()); 586 } 587 if (jQuery('#abstext').length > 0 && content.length > 0) { 588 count = content.replace(/\s+/gi, ' ').split(' ').length; 589 } 590 counterCont.text(count); 591 remainingCont.text(maxCount - count); 592 if (count > maxCount && !notified) { 593 remainingCont.css('color', 'red'); 594 counterCont.css('color', 'red'); 595 } else { 596 counterCont.css('color', 'green'); 597 remainingCont.css('color', 'green'); 598 } 599 if (count > maxCount) { 600 alertify.customError(wpabstracts.word_count_err); 601 return; 602 } 603} 604 605function wpabstracts_validateEvent() { 606 var errors = false; 607 jQuery('form#abs_event_form .wpa_event_input').each(function () { 608 errors = wp_field_validate(jQuery(this).attr('id'), errors); 609 }); 610 if (errors) { 611 alertify.customError(wpabstracts.required_fields); 612 } else { 613 alertify.dismissAll(); 614 alertify.success('Saving...'); 615 jQuery('#abs_event_form').submit(); 616 } 617} 618 619function wpabstracts_validateTemplate() { 620 var errors = false; 621 jQuery('form#emailtemplate .wpa_event_input').each(function () { 622 errors = wp_field_validate(jQuery(this).attr('id'), errors); 623 }); 624 if (!jQuery('#email_body').val()) { 625 jQuery('#email_body').addClass('has-error'); 626 errors = true; 627 } else { 628 jQuery('#email_body').removeClass('has-error'); 629 } 630 if (errors) { 631 alertify.customError(wpabstracts.required_fields); 632 } else { 633 alertify.dismissAll(); 634 alertify.success('Saving...'); 635 jQuery('#emailtemplate').submit(); 636 } 637} 638 639function wpabstracts_copy_to_clipboard(textToCopy) { 640 if (!navigator.clipboard) { 641 var textArea = document.createElement('textarea'); 642 textArea.value = textToCopy; 643 document.body.appendChild(textArea); 644 textArea.focus(); 645 textArea.select(); 646 try { 647 var success = document.execCommand('copy'); 648 if (success) { 649 alertify.success(wpabstracts.copy_success); 650 } else { 651 alertify.customError(wpabstracts.copy_failure); 652 } 653 } catch (err) { 654 alertify.customError(wpabstracts.copy_failure); 655 } 656 document.body.removeChild(textArea); 657 } else { 658 navigator.clipboard.writeText(textToCopy).then( 659 function () { 660 alertify.success(wpabstracts.copy_success); 661 }, 662 function (err) { 663 alertify.customError(wpabstracts.copy_failure); 664 } 665 ); 666 } 667} 668 669function wpabstracts_refresh_file(elem) { 670 var $el = jQuery(elem).parent().find('input'); 671 $el.wrap('<form>').closest('form').get(0).reset(); 672 $el.unwrap(); 673} 674 675function wpabstracts_restore_titles(nonce) { 676 alertify.confirm(wpabstracts.confirm_title_restore, function (e) { 677 if (e) { 678 location.href = 679 '?page=wpabstracts&tab=settings&subtab=titles&task=reset&_wpnonce=' + 680 nonce; 681 } 682 }); 683} 684 685function wpabstracts_sync_user_meta(nonce) { 686 alertify.prompt(wpabstracts.confirm_usermeta_sync).setting({ 687 onok: function (closeEvent) {
688 var entry = jQuery('.ajs-input').val(); 689 if (entry && 'SYNC' == entry.toUpperCase()) { 690 location.href = 691 '?page=wpabstracts&tab=users&subtab=settings&task=sync&_wpnonce=' + 692 nonce; 693 } else { 694 return false; 695 } 696 }, 697 labels: { 698 ok: 'SYNC', 699 cancel: 'Cancel', 700 }, 701 }); 702} 703 704function wpabstracts_load_maillog(log_id) { 705 var data = { 706 action: 'wpamaillog', 707 log_id, 708 }; 709 jQuery.post(wpabstracts.ajaxurl, data).done(function (_log) { 710 var log = JSON.parse(_log); 711 jQuery('body').append('<div id="wpa_mail_log"></div>'); 712 jQuery('#wpa_mail_log').html('').html(log.body); 713 jQuery('#wpa_mail_log') 714 .dialog({ 715 width: 650, 716 maxHeight: 750, 717 modal: true, 718 closeOnEscape: true, 719 closeText: '', 720 title: 'Email Log', 721 buttons: [ 722 { 723 text: 'Close', 724 click: function () { 725 jQuery('#wpa_mail_log').dialog('close'); 726 }, 727 class: 'wpa_button cancel', 728 }, 729 ], 730 }) 731 .dialog('open'); 732 }); 733}
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.