1function um_sanitize_value( value, el ) { 2 var element = document.createElement( 'div' ); 3 element.innerText = value; 4 var sanitized_value = element.innerHTML; 5 if ( el ) { 6 jQuery( el ).val( sanitized_value ); 7 } 8 9 return sanitized_value; 10} 11 12function um_unsanitize_value( input ) { 13 var e = document.createElement( 'textarea' ); 14 e.innerHTML = input; 15 // handle case of empty input 16 return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue; 17} 18 19jQuery(document).ready(function() { 20 21 jQuery( document.body ).on('click', '.um-dropdown a.real_url', function() { 22 window.location = jQuery(this).attr('href'); 23 }); 24 25 jQuery( document.body ).on( 'click', '.um-trigger-menu-on-click', function() { 26 var menu = jQuery(this).find('.um-dropdown'); 27 UM.dropdown.show( menu ); 28 return false; 29 }); 30 31 jQuery( document.body ).on('click', '.um-dropdown-hide', function() { 32 UM.dropdown.hideAll(); 33 return false; 34 }); 35 36 jQuery( document.body ).on('click', 'a.um-manual-trigger', function() { 37 var child = jQuery(this).attr('data-child'); 38 var parent = jQuery(this).attr('data-parent'); 39 jQuery(this).parents( parent ).find( child ).trigger('click'); 40 UM.dropdown.hideAll(); 41 return false; 42 }); 43 44 jQuery('.um-s1,.um-s2').css({'display':'block'}); 45 46 /** 47 * Unselect empty option if something is selected 48 * 49 * @since 2.1.16 50 * @param {object} e 51 * @returns {undefined} 52 */ 53 function unselectEmptyOption( e ) { 54 var $element = jQuery( e.currentTarget ); 55 var $selected = $element.find(':selected'); 56 57 if ( $selected.length > 1 ) { 58 $selected.each( function ( i, option ) { 59 if ( option.value === '' ) { 60 option.selected = false; 61 $element.trigger( 'change' ); 62 } 63 }); 64 } 65 } 66 67 if ( typeof( jQuery.fn.select2 ) === 'function' ) { 68 jQuery(".um-s1").each( function( e ) { 69 var obj = jQuery(this); 70 71 obj.select2({ 72 allowClear: true, 73 dropdownParent: obj.parent() 74 }).on( 'change', unselectEmptyOption ); 75 } ); 76 77 jQuery(".um-s2").each( function( e ) { 78 var obj = jQuery(this); 79 80 // fix https://github.com/ultimatemember/ultimatemember/issues/941 81 // using .um-custom-shortcode-tab class as temporarily solution 82 var atts = {}; 83 if ( obj.parents('.um-custom-shortcode-tab').length ) { 84 atts = { 85 allowClear: false 86 }; 87 } else { 88 atts = { 89 allowClear: false, 90 minimumResultsForSearch: 10, 91 dropdownParent: obj.parent() 92 }; 93 } 94 obj.select2( atts ).on( 'change', unselectEmptyOption ); 95 } ); 96 97 jQuery(".um-s3").each( function( e ) { 98 var obj = jQuery(this); 99 100 obj.select2({ 101 allowClear: false, 102 minimumResultsForSearch: -1, 103 dropdownParent: obj.parent() 104 }).on( 'change', unselectEmptyOption ); 105 } ); 106 } 107 108 if ( typeof( jQuery.fn.um_raty ) === 'function' ) { 109 jQuery('.um-rating').um_raty({ 110 half: false, 111 starType: 'i', 112 number: function() { 113 return jQuery(this).attr('data-number'); 114 }, 115 score: function() { 116 return jQuery(this).attr('data-score'); 117 }, 118 scoreName: function() { 119 return jQuery(this).attr('data-key'); 120 }, 121 hints: false, 122 click: function( score, evt ) { 123 um_live_field = this.id; 124 um_live_value = score; 125 um_apply_conditions( jQuery(this), false ); 126 } 127 }); 128 129 jQuery('.um-rating-readonly').um_raty({ 130 half: false, 131 starType: 'i', 132 number: function() { 133 return jQuery(this).attr('data-number'); 134 }, 135 score: function() { 136 return jQuery(this).attr('data-score'); 137 }, 138 scoreName: function() { 139 return jQuery(this).attr('data-key'); 140 }, 141 hints: false, 142 readOnly: true 143 }); 144 } 145 146 jQuery(document).on('change', '.um-field-area input[type="radio"]', function() { 147 var field = jQuery(this).parents('.um-field-area'); 148 var this_field = jQuery(this).parents('label'); 149 field.find('.um-field-radio').removeClass('active'); 150 field.find('.um-field-radio').find('i').removeAttr('class').addClass('um-icon-android-radio-button-off'); 151 this_field.addClass('active'); 152 this_field.find('i').removeAttr('class').addClass('um-icon-android-radio-button-on'); 153 }); 154 155 jQuery(document).on('change', '.um-field-area input[type="checkbox"]', function() { 156 var this_field = jQuery(this).parents('label'); 157 if ( this_field.hasClass('active') ) { 158 this_field.removeClass('active'); 159 this_field.find('i').removeAttr('class').addClass('um-icon-android-checkbox-outline-blank'); 160 } else { 161 this_field.addClass('active'); 162 this_field.find('i').removeAttr('class').addClass('um-icon-android-checkbox-outline'); 163 } 164 }); 165 166 jQuery(document.body).on('click', '.um-single-image-preview a.cancel', function(e) { 167 e.preventDefault(); 168 169 let isModal = false;
170 if ( jQuery(this).parents('.um-modal-body').length > 0 ) { 171 isModal = true; 172 } 173 174 let parent, mode, src, args; 175 176 if ( ! isModal ) { 177 parent = jQuery(this).parents('.um-field'); 178 mode = parent.data('mode'); 179 src = parent.find('.um-single-image-preview img').attr('src'); 180 181 let filename = parent.find( 'input[type="hidden"]#' + parent.data('key') + '-' + jQuery(this).parents('form').find('input[type="hidden"][name="form_id"]').val() ).val(); 182 183 args = { 184 data: { 185 mode: mode, 186 filename: filename, 187 src: src, 188 nonce: um_scripts.nonce 189 }, 190 success: function() { 191 parent.find('.um-single-image-preview img').replaceWith('<img src="" alt="" />'); 192 parent.find('.um-single-image-preview').removeAttr('style').hide(); 193 parent.find('.um-btn-auto-width').html( parent.data('upload-label') ); 194 parent.find('input[type="hidden"]').val( 'empty_file' ); 195 } 196 }; 197 198 if ( mode !== 'register' ) { 199 args.data.user_id = jQuery(this).parents('form').find('#user_id').val(); 200 } 201 } else { 202 parent = jQuery(this).parents('.um-modal-body'); 203 mode = parent.find('.um-single-image-upload').data('set_mode'); 204 src = parent.find('.um-single-image-preview img').attr('src'); 205 206 args = { 207 data: { 208 src: src, 209 mode: mode, 210 nonce: um_scripts.nonce 211 }, 212 success: function() { 213 wp.hooks.doAction( 'um_after_removing_preview' ); 214 215 parent.find('.um-single-image-preview img').replaceWith('<img src="" alt="" />'); // required replaceWith for flushing DOM before re-init Cropper. 216 parent.find('.um-single-image-preview').removeAttr('style').hide(); 217 parent.find('.ajax-upload-dragdrop').show(); 218 parent.find('.um-modal-btn.um-finish-upload').addClass( 'disabled' ); 219 220 um_modal_responsive(); 221 } 222 }; 223 } 224 225 wp.ajax.send( 'um_remove_file', args ); 226 }); 227 228 jQuery(document.body).on('click', '.um-single-file-preview a.cancel', function(e) { 229 e.preventDefault(); 230 231 let isModal = false; 232 if ( jQuery(this).parents('.um-modal-body').length > 0 ) { 233 isModal = true; 234 } 235 236 let parent, mode, src, args; 237 238 if ( ! isModal ) { 239 parent = jQuery(this).parents('.um-field'); 240 src = parent.find('.um-single-fileinfo a').attr('href'); 241 mode = parent.data('mode'); 242 243 let filename = parent.find( 'input[type="hidden"]#' + parent.data('key') + '-' + jQuery(this).parents('form').find('input[type="hidden"][name="form_id"]').val() ).val(); 244 245 args = { 246 data: { 247 mode: mode, 248 filename: filename, 249 src: src, 250 nonce: um_scripts.nonce 251 }, 252 success: function() { 253 parent.find('.um-single-file-preview').hide(); 254 parent.find('.um-btn-auto-width').html( parent.data('upload-label') ); 255 parent.find('input[type=hidden]').val( 'empty_file' ); 256 } 257 }; 258 259 if ( mode !== 'register' ) { 260 args.data.user_id = jQuery(this).parents('form' ).find( '#user_id' ).val(); 261 } 262 } else { 263 parent = jQuery(this).parents('.um-modal-body'); 264 src = parent.find('.um-single-fileinfo a').attr('href'); 265 mode = parent.find('.um-single-file-upload').data('set_mode'); 266 267 args = { 268 data: { 269 src: src, 270 mode: mode, 271 nonce: um_scripts.nonce 272 }, 273 success: function() { 274 parent.find('.um-single-file-preview').hide(); 275 parent.find('.ajax-upload-dragdrop').show(); 276 parent.find('.um-modal-btn.um-finish-upload').addClass('disabled'); 277 um_modal_responsive(); 278 } 279 }; 280 } 281 wp.ajax.send( 'um_remove_file', args ); 282 }); 283 284 // @todo deprecate 285 jQuery(document).on('click', '.um-field-group-head:not(.disabled)', function() { 286 var field = jQuery(this).parents('.um-field-group'); 287 var limit = field.data('max_entries'); 288 289 if ( field.find('.um-field-group-body').is(':hidden')){ 290 field.find('.um-field-group-body').show(); 291 } else { 292 field.find('.um-field-group-body:first').clone().appendTo( field ); 293 } 294 295 var increase_id = 0; 296 field.find('.um-field-group-body').each(function(){ 297 increase_id++; 298 jQuery(this).find('input').each(function(){ 299 var input = jQuery(this); 300 input.attr('id', input.data('key') + '-' + increase_id ); 301 input.attr('name', input.data('key') + '-' + increase_id ); 302 input.parent().parent().find('label').attr('for', input.data('key') + '-' + increase_id ); 303 }); 304 }); 305 306 if ( limit > 0 && field.find('.um-field-group-body').length == limit ) { 307 308 jQuery(this).addClass('disabled'); 309 310 } 311 }); 312 // @todo deprecate 313 jQuery(document).on('click', '.um-field-group-cancel', function( e ) { 314 e.preventDefault(); 315 var field = jQuery(this).parents('.um-field-group'); 316 317 var limit = field.data('max_entries'); 318 319 if ( field.find('.um-field-group-body').length > 1 ) { 320 jQuery(this).parents('.um-field-group-body').remove(); 321 } else { 322 jQuery(this).parents('.um-field-group-body').hide(); 323 } 324 325 if ( limit > 0 && field.find('.um-field-group-body').length < limit ) { 326 field.find('.um-field-group-head').removeClass('disabled'); 327 } 328 329 return false;
330 }); 331 332 333 jQuery( document.body ).on( 'click', '.um-ajax-paginate', function( e ) { 334 e.preventDefault(); 335 336 var obj = jQuery(this); 337 var parent = obj.parent(); 338 parent.addClass( 'loading' ); 339 340 var pages = obj.data('pages')*1; 341 var next_page = obj.data('page')*1 + 1; 342 343 var hook = obj.data('hook'); 344 345 if ( 'um_load_posts' === hook ) { 346 347 jQuery.ajax({ 348 url: wp.ajax.settings.url, 349 type: 'post', 350 data: { 351 action: 'um_ajax_paginate_posts', 352 author: jQuery(this).data('author'), 353 page: next_page, 354 nonce: um_scripts.nonce 355 }, 356 complete: function() { 357 parent.removeClass( 'loading' ); 358 }, 359 success: function( data ) { 360 parent.before( data ); 361 if ( next_page === pages ) { 362 parent.remove(); 363 } else { 364 obj.data( 'page', next_page ); 365 } 366 } 367 }); 368 } else if ( 'um_load_comments' === hook ) { 369 370 jQuery.ajax({ 371 url: wp.ajax.settings.url, 372 type: 'post', 373 data: { 374 action: 'um_ajax_paginate_comments', 375 user_id: jQuery(this).data('user_id'), 376 page: next_page, 377 nonce: um_scripts.nonce 378 }, 379 complete: function() { 380 parent.removeClass( 'loading' ); 381 }, 382 success: function( data ) { 383 parent.before( data ); 384 if ( next_page === pages ) { 385 parent.remove(); 386 } else { 387 obj.data( 'page', next_page ); 388 } 389 } 390 }); 391 } else { 392 var args = jQuery(this).data('args'); 393 var container = jQuery(this).parents('.um.um-profile.um-viewing').find('.um-ajax-items'); 394 395 jQuery.ajax({ 396 url: wp.ajax.settings.url, 397 type: 'post', 398 data: { 399 action: 'um_ajax_paginate', 400 hook: hook, 401 args: args, 402 nonce: um_scripts.nonce 403 }, 404 complete: function() { 405 parent.removeClass( 'loading' ); 406 }, 407 success: function(data){ 408 parent.remove(); 409 container.append( data ); 410 } 411 }); 412 } 413 }); 414 415 416 jQuery(document).on('click', '.um-ajax-action', function( e ) { 417 e.preventDefault(); 418 var hook = jQuery(this).data('hook'); 419 var user_id = jQuery(this).data('user_id'); 420 var args = jQuery(this).data('args'); 421 422 if ( jQuery(this).data('js-remove') ){ 423 jQuery(this).parents('.'+jQuery(this).data('js-remove')).fadeOut('fast'); 424 } 425 426 jQuery.ajax({ 427 url: wp.ajax.settings.url, 428 type: 'post', 429 data: { 430 action: 'um_muted_action', 431 hook: hook, 432 user_id: user_id, 433 arguments: args, 434 nonce: um_scripts.nonce 435 }, 436 success: function(data){ 437 438 } 439 }); 440 return false; 441 }); 442 443 jQuery( document.body ).on('click', '#um-search-button', function(e) { 444 e.preventDefault(); 445 446 let $btn = jQuery(this); 447 if ( $btn.hasClass( 'um-disabled' ) ) { 448 return; 449 } 450 451 let $form = $btn.parents('.um-search-form'); 452 let search = $form.find('.um-search-field').val(); 453 let nonce = $form.data('nonce'); 454 455 $btn.addClass('um-disabled'); 456 wp.ajax.send( 'um_search_widget_request', { 457 data: { 458 search: search, 459 _wpnonce: nonce 460 }, 461 success: function(response) { 462 $btn.removeClass('um-disabled'); 463 window.location = response.url; 464 }, 465 error: function(e) { 466 console.log(e); 467 $btn.removeClass('um-disabled'); 468 } 469 }); 470 }); 471 472 //make search on Enter click 473 jQuery( document.body ).on( 'keypress', '.um-search-field', function(e) { 474 if ( e.which === 13 ) { 475 let $field = jQuery(this); 476 let $form = $field.parents('.um-search-form'); 477 478 let $btn = $form.find('#um-search-button'); 479 if ( $btn.hasClass( 'um-disabled' ) ) { 480 return; 481 } 482 let search = $field.val(); 483 let nonce = $form.data('nonce'); 484 485 $btn.addClass('um-disabled'); 486 wp.ajax.send( 'um_search_widget_request', { 487 data: { 488 search: search, 489 _wpnonce: nonce 490 }, 491 success: function(response) { 492 $btn.removeClass('um-disabled'); 493 window.location = response.url; 494 }, 495 error: function(e) { 496 console.log(e); 497 $btn.removeClass('um-disabled'); 498 } 499 }); 500 } 501 }); 502 503 jQuery('.um-form input[class="um-button"][type="submit"]').prop('disabled', false); 504 505 jQuery(document).one('click', '.um:not(.um-account) .um-form input[class="um-button"][type="submit"]:not(.um-has-recaptcha)', function() { 506 jQuery(this).attr('disabled','disabled'); 507 jQuery(this).parents('form').trigger('submit'); 508 }); 509 510 511 var um_select_options_cache = {}; 512 513 /** 514 * Find all select fields with parent select fields 515 */ 516 jQuery('select[data-um-parent]').each( function() { 517 518 var me = jQuery(this); 519 var parent_option = me.data('um-parent'); 520 var um_ajax_source = me.data('um-ajax-source'); 521 522 me.attr('data-um-init-field', true ); 523 524 jQuery(document).on('change','select[name="' + parent_option + '"]',function() { 525 var parent = jQuery(this); 526 var form_id = parent.closest( 'form' ).find( 'input[type="hidden"][name="form_id"]' ).val(); 527 528 var arr_key; 529 if ( me.attr( 'data-member-directory' ) === 'yes' ) { 530 var directory = parent.parents('.um-directory'); 531 arr_key = um_get_data_for_directory( directory, 'filter_' + parent_option ); 532 if ( typeof arr_key != 'undefined' ) { 533 arr_key = arr_key.split('||'); 534 } else { 535 arr_key = ''; 536 } 537 } else { 538 arr_key = parent.val(); 539 } 540 541 if ( typeof arr_key != 'undefined' && arr_key !== '' && typeof um_select_options_cache[ arr_key ] !== 'object' ) { 542 543 if ( typeof( me.um_wait ) === 'undefined' || me.um_wait === false ) { 544 me.um_wait = true; 545 } else { 546 return; 547 } 548 549 jQuery.ajax({ 550 url: wp.ajax.settings.url, 551 type: 'post', 552 data: { 553 action: 'um_select_options', 554 parent_option_name: parent_option, 555 parent_option: arr_key, 556 child_callback: um_ajax_source, 557 child_name: me.attr('name'), 558 members_directory: me.attr('data-member-directory'), 559 form_id: form_id, 560 nonce: um_scripts.nonce 561 }, 562 success: function( data ) { 563 if ( data.status === 'success' && arr_key !== '' ) { 564 um_select_options_cache[ arr_key ] = data; 565 um_field_populate_child_options( me, data, arr_key ); 566 } 567 568 if ( typeof data.debug !== 'undefined' ) { 569 console.log( data ); 570 } 571 572 me.um_wait = false;
573 }, 574 error: function( e ) { 575 console.log( e ); 576 me.um_wait = false; 577 } 578 }); 579 580 } 581 582 if ( typeof arr_key != 'undefined' && arr_key !== '' && typeof um_select_options_cache[ arr_key ] == 'object' ) { 583 setTimeout( um_field_populate_child_options, 10, me, um_select_options_cache[ arr_key ], arr_key ); 584 } 585 586 if ( typeof arr_key != 'undefined' || arr_key === '' ) { 587 me.find('option[value!=""]').remove(); 588 me.val('').trigger('change'); 589 } 590 591 }); 592 593 jQuery('select[name="' + parent_option + '"]').trigger('change'); 594 595 }); 596 597 598 /** 599 * Populates child options and cache ajax response 600 * 601 * @param me 602 * @param data 603 * @param arr_key 604 */ 605 function um_field_populate_child_options( me, data, arr_key ) { 606 var directory = me.parents('.um-directory'); 607 var child_name = me.attr('name'); 608 me.find('option[value!=""]').remove(); 609 610 if ( ! me.hasClass('um-child-option-disabled') ) { 611 me.prop('disabled', false); 612 } 613 614 var arr_items = [], 615 search_get = ''; 616 617 if ( data.post.members_directory === 'yes' ) { 618 arr_items.push({id: '', text: '', selected: 1}); 619 } 620 jQuery.each( data.items, function(k,v){ 621 arr_items.push({id: k, text: v, selected: (v === search_get)}); 622 }); 623 624 me.select2('destroy'); 625 if ( me.hasClass( 'um-s1' ) ) { 626 me.select2({ 627 data: arr_items, 628 allowClear: true, 629 dropdownParent: me.parent() 630 }); 631 } else if ( me.hasClass( 'um-s2' ) ) { 632 me.select2({ 633 data: arr_items, 634 allowClear: true, 635 minimumResultsForSearch: 10, 636 dropdownParent: me.parent() 637 }); 638 } 639 640 641 642 if ( data.post.members_directory === 'yes' ) { 643 me.find('option').each( function() { 644 if ( jQuery(this).html() !== '' ) { 645 jQuery(this).data( 'value_label', jQuery(this).html() ).attr( 'data-value_label', jQuery(this).html() ); 646 } 647 }); 648 649 var current_filter_val = um_get_data_for_directory( directory, 'filter_' + child_name ); 650 if ( typeof current_filter_val !== 'undefined' ) { 651 current_filter_val = current_filter_val.split('||'); 652 653 var temp_filter_val = []; 654 jQuery.each( current_filter_val, function(i) { 655 if ( me.find('option[value="' + current_filter_val[ i ] + '"]').length ) { 656 temp_filter_val.push( current_filter_val[ i ] ); 657 } 658 me.find('option[value="' + current_filter_val[ i ] + '"]').prop('disabled', true).hide(); 659 if ( me.find('option:not(:disabled)').length === 1 ) { 660 me.prop('disabled', true); 661 } 662 663 me.select2('destroy').select2(); 664 me.val('').trigger( 'change' ); 665 }); 666 667 temp_filter_val = temp_filter_val.join('||'); 668 if ( current_filter_val !== temp_filter_val ) { 669 um_set_url_from_data( directory, 'filter_' + child_name, temp_filter_val ); 670 um_ajax_get_members( directory ); 671 } 672 } 673 674 um_change_tag( directory ); 675 } 676 677 if ( data.post.members_directory !== 'yes' ) { 678 if ( typeof data.field.default !== 'undefined' && ! me.data('um-original-value') ) { 679 me.val( data.field.default ).trigger('change'); 680 } else if ( me.data('um-original-value') !== '' ) { 681 me.val( me.data('um-original-value') ).trigger('change'); 682 } 683 684 if ( data.field.editable == 0 ) { 685 me.addClass('um-child-option-disabled'); 686 me.attr('disabled','disabled'); 687 } 688 } 689 } 690 691 jQuery( document.body ).on('click', '.um-toggle-password', function (){ 692 let parent = jQuery(this).closest('.um-field-area-password'); 693 let passwordField = parent.find('input'); 694 let type = passwordField.attr('type'); 695 if ( 'text' === type ) { 696 passwordField.attr('type', 'password'); 697 parent.find('i').toggleClass('um-icon-eye um-icon-eye-disabled'); 698 } else { 699 passwordField.attr('type', 'text'); 700 parent.find('i').toggleClass('um-icon-eye um-icon-eye-disabled'); 701 } 702 }); 703}); 704 705// Makes the honeypot. 706jQuery( window ).on( 'load', function() { 707 let $honeypotField = jQuery('input[name="um_request"]'); 708 if ( $honeypotField.length ) { 709 $honeypotField.val(''); 710 } 711}); 712
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.