um-profile.js
4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
jQuery(document).ready(function() {
jQuery('.um-profile.um-viewing .um-profile-body .um-row').each(function(){
var this_row = jQuery(this);
if ( this_row.find('.um-field').length == 0 ) {
this_row.prev('.um-row-heading').remove();
this_row.remove();
}
});
if ( jQuery('.um-profile.um-viewing .um-profile-body').length && jQuery('.um-profile.um-viewing .um-profile-body').find('.um-field').length == 0 ) {
jQuery('.um-profile.um-viewing .um-profile-body').find('.um-row-heading,.um-row').remove();
jQuery('.um-profile-note').show();
}
jQuery( document.body ).on( 'click', '.um-profile-save', function(e){
e.preventDefault();
jQuery(this).parents('.um').find('form').trigger('submit');
return false;
});
jQuery( document.body ).on( 'click', '.um-profile-edit-a', function(e){
jQuery(this).addClass('active');
});
jQuery( document.body ).on( 'click', '.um-cover a.um-cover-add, .um-photo a', function(e){
e.preventDefault();
});
jQuery( document.body ).on('click', '.um-photo-modal', function(e){
e.preventDefault();
var photo_src = jQuery(this).attr('data-src');
um_new_modal('um_view_photo', 'fit', true, photo_src );
return false;
});
jQuery(document.body).on('click', '.um-reset-profile-photo', function(e) {
jQuery('.um-profile-photo-img img').attr( 'src', jQuery(this).attr( 'data-default_src' ) );
user_id = jQuery(this).attr('data-user_id');
metakey = 'profile_photo';
UM.dropdown.hideAll();
jQuery.ajax({
url: wp.ajax.settings.url,
type: 'post',
data: {
action:'um_delete_profile_photo',
metakey: metakey,
user_id: user_id,
nonce: um_scripts.nonce
}
});
jQuery(this).parents('li').hide();
return false;
});
jQuery(document.body).on('click', '.um-reset-cover-photo', function(e){
var obj = jQuery(this);
jQuery('.um-cover-overlay').hide();
jQuery('.um-cover-e').html('<a href="javascript:void(0);" class="um-cover-add" style="height: 370px;"><span class="um-cover-add-i"><i class="um-icon-plus um-tip-n" original-title="Upload a cover photo"></i></span></a>');
um_responsive();
user_id = jQuery(this).attr('data-user_id');
metakey = 'cover_photo';
jQuery.ajax({
url: wp.ajax.settings.url,
type: 'post',
data: {
action: 'um_delete_cover_photo',
metakey: metakey,
user_id: user_id,
nonce: um_scripts.nonce
},
success: function( response ) {
obj.hide();
}
});
UM.dropdown.hideAll();
return false;
});
// Bio characters limit
jQuery( document.body ).on( 'change keyup', '#um-meta-bio', function() {
if ( typeof jQuery(this).val() !== 'undefined' ) {
let um_bio_limit = jQuery(this).data( 'character-limit' );
let bio_html = jQuery(this).data( 'html' );
let remaining = um_bio_limit - jQuery(this).val().length;
if ( parseInt( bio_html ) === 1 ) {
remaining = um_bio_limit - jQuery(this).val().replace(/(<([^>]+)>)/ig,'').length;
}
remaining = remaining < 0 ? 0 : remaining;
jQuery( 'span.um-meta-bio-character span.um-bio-limit' ).text( remaining );
let color = remaining < 5 ? 'red' : '';
jQuery('span.um-meta-bio-character').css( 'color', color );
}
});
jQuery( '#um-meta-bio' ).trigger('change');
// Biography (description) fields syncing.
jQuery( '.um-profile form' ).each( function () {
let descKey = jQuery(this).data('description_key');
if ( jQuery(this).find( 'textarea[name="' + descKey + '"]' ).length ) {
jQuery( document.body ).on( 'change input', 'textarea[name="' + descKey + '"]', function ( e ) {
jQuery(this).parents( 'form' ).find( 'textarea[name="' + descKey + '"]' ).each( function() {
jQuery(this).val( e.currentTarget.value );
if ( jQuery('#um-meta-bio')[0] !== e.currentTarget && jQuery('#um-meta-bio')[0] === jQuery(this)[0] ) {
jQuery(this).trigger('change');
}
});
});
}
});
jQuery( '.um-profile-edit a.um_delete-item' ).on( 'click', function(e) {
e.preventDefault();
if ( ! confirm( wp.i18n.__( 'Are you sure that you want to delete this user?', 'ultimate-member' ) ) ) {
return false;
}
});
/**
* Fix profile nav links for iPhone
* @see https://www.html5rocks.com/en/mobile/touchandmouse/
*/
jQuery( '.um-profile-nav a' ).on( 'touchend', function(e) {
jQuery( e.currentTarget).trigger( "click" );
});
});