PluginProbe
Profile Extra Fields by BestWebSoft / trunk
Profile Extra Fields by BestWebSoft vtrunk
1.3.7 1.3.6 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 38 releases
profile-extra-fields / js / script.js

script.js in Profile Extra Fields by BestWebSoft trunk, at js/script.js

311 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( $ ) {
2 $( document ).ready(
3 function() {
4 /* Show trash icon */
5 $( '.prflxtrflds-value-delete input' ).addClass( 'prflxtrflds-value-delete-check' );
6 $( '.prflxtrflds-value-delete label' ).click(
7 function() {
8 /* clear value */
9 $( this ).parent().parent().children( 'input.prflxtrflds-add-options-input' ).val( '' );
10 /* hide field */
11 $( this ).parent().parent().hide();
12
13 if ( 'function' == typeof bws_show_settings_notice ) {
14 bws_show_settings_notice();
15 }
16 }
17 );
18 /* Add additional fields for checkbox, radio, select */
19 $( '#prflxtrflds-add-field' ).click(
20 function() {
21 /* Clone previous input */
22 var lastfield = $( '.prflxtrflds-drag-values' ).last().clone( true );
23 /* remove hidden input */
24 lastfield.children( 'input.hidden' ).remove();
25 /* clear textfield */
26 lastfield.children( 'input.prflxtrflds-add-options-input' ).val( '' );
27 /* Insert field before button */
28 lastfield.clone( true ).removeClass( 'hide-if-js' ).show().insertAfter( $( '.prflxtrflds-drag-values' ).last() );
29 }
30 );
31 /* Show fields for diffrent field type */
32 $( '#prflxtrflds-select-type' ).on(
33 'change',
34 function() {
35 type_value = $( this ).val();
36 $( '.prflxtrflds-fields-container, .prflxtrflds-pattern, .prflxtrflds-time-format, .prflxtrflds-date-format, .prflxtrflds-maxlength, .prflxtrflds-rows, .prflxtrflds-cols, .prflxtrflds-selected-extensions' ).hide();
37 $( '.prflxtrflds-fields-edit-table' ).show();
38
39 if ( '3' == type_value || '4' == type_value || '5' == type_value ) {
40 $( '.prflxtrflds-fields-container' ).show();
41 } else if ( '10' == type_value ) {
42 $( '.prflxtrflds-pattern' ).show();
43 } else if ( '12' == type_value ) {
44 $( '.prflxtrflds-selected-extensions' ).show();
45 } else {
46 if ( '6' == type_value || '8' == type_value ) {
47 $( '.prflxtrflds-date-format' ).show();
48 }
49 if ( '7' == type_value || '8' == type_value ) {
50 $( '.prflxtrflds-time-format' ).show();
51 }
52 if ( '1' == type_value || '9' == type_value || '11' == type_value ) {
53 $( '.prflxtrflds-maxlength' ).show();
54 }
55 if ( '2' == type_value ) {
56 $( '.prflxtrflds-rows, .prflxtrflds-cols, .prflxtrflds-maxlength' ).show();
57 }
58 }
59 }
60 ).trigger( 'change' );
61
62 $( "input[name='prflxtrflds_date_format']" ).click(
63 function(){
64 if ( "prflxtrflds_date_format_custom_radio" != $( this ).attr( "id" ) ) {
65 $( "input[name='prflxtrflds_date_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
66 }
67 }
68 );
69 $( "input[name='prflxtrflds_date_format_custom']" ).focus(
70 function(){
71 $( '#prflxtrflds_date_format_custom_radio' ).prop( 'checked', true );
72 }
73 );
74
75 $( "input[name='prflxtrflds_time_format']" ).click(
76 function(){
77 if ( "prflxtrflds_time_format_custom_radio" != $( this ).attr( "id" ) ) {
78 $( "input[name='prflxtrflds_time_format_custom']" ).val( $( this ).val() ).siblings( '.example' ).text( $( this ).parent( 'label' ).text() );
79 }
80 }
81 );
82 $( "input[name='prflxtrflds_time_format_custom']" ).focus(
83 function(){
84 $( '#prflxtrflds_time_format_custom_radio' ).prop( 'checked', true );
85 }
86 );
87 $( "input[name='prflxtrflds_date_format_custom'], input[name='prflxtrflds_time_format_custom']" ).change(
88 function() {
89 var format = $( this );
90 format.siblings( '.spinner' ).addClass( 'is-active' );
91 $.post(
92 ajaxurl,
93 {
94 action: 'prflxtrflds_date_format_custom' == format.attr( 'name' ) ? 'date_format' : 'time_format',
95 date : format.val()
96 },
97 function( d ) { format.siblings( '.spinner' ).removeClass( 'is-active' ); format.siblings( '.example' ).text( d ); }
98 );
99 }
100 );
101
102 /* Sortable table settings */
103 if ( $.fn.sortable ) {
104 if ( $( '.prflxtrflds-wplisttable-fullwidth-sort-container .wp-list-table tbody tr' ).size() > 1 ) {
105 $( '.prflxtrflds-wplisttable-fullwidth-sort-container .wp-list-table tr' ).addClass( 'prflxtrflds-cursor-move' );
106 $( '.prflxtrflds-wplisttable-fullwidth-sort-container #the-list' ).sortable(
107 {
108 cursor: 'move',
109 placeholder: 'prflxtrflds-placeholder',
110 stop: function( event, ui ) {
111 var order = [];
112 $( '.prflxtrflds-wplisttable-fullwidth-sort-container #the-list tr th input' ).each(
113 function( i, row ) {
114 row = $( row );
115 order[ i ] = row.attr( 'value' );
116 }
117 );
118 var fieldId = $( '#prflxtrflds-role-id option:selected' ).val();
119 /* Save order with ajax */
120 $.ajax(
121 {
122 url: prflxtrflds_ajax.prflxtrflds_ajax_url,
123 type: "POST",
124 data: 'action=prflxtrflds_table_order&table_order=' + order.join( ', ' ) + '&prflxtrflds_ajax_nonce_field=' + prflxtrflds_ajax.prflxtrflds_nonce + '&field_id=' + fieldId,
125 success: function( result ) {
126 },
127 error: function( request, status, error ) {
128 console.log( error + request.status );
129 }
130 }
131 );
132 }
133 }
134 );
135 }
136
137 /* Drag n drop values list */
138 $( '.prflxtrflds-drag-values-container' ).sortable(
139 {
140 itemSelector: 'div',
141 /* Without container selector script return error */
142 containerSelector: '.prflxtrflds-drag-values-container',
143 handle: '.prflxtrflds-drag-field',
144 placeholder: 'prflxtrflds-placeholder',
145 stop: function( event, ui ) {
146 if ( 'function' == typeof bws_show_settings_notice ) {
147 bws_show_settings_notice();
148 }
149 }
150 }
151 );
152 }
153
154 /* Disable select if field unchecked after render page */
155 $( '.prflxtrflds-available-fields' ).each(
156 function() {
157 if ( ! this.checked ) {
158 $( this ).parent().next().children( 'select' ).prop( 'disabled', 'disabled' );
159 }
160 }
161 );
162 /* Dynamic enable or disable select */
163 $( '.prflxtrflds-available-fields' ).change(
164 function() {
165 if ( this.checked ) {
166 $( this ).parent().next().children( 'select' ).prop( 'disabled', false );
167 } else {
168 $( this ).parent().next().children( 'select' ).prop( 'disabled', 'disabled' );
169 }
170 }
171 );
172
173 $( '[id*=prflxtrflds-show-in-]' ).on(
174 'click',
175 function() {
176 if ( $( this ).is( ':checked' ) ) {
177 $( '.' + this.id ).show();
178 } else {
179 $( '.' + this.id ).hide().find( '[type="checkbox"]' ).prop( 'checked', false );
180 }
181 }
182 );
183
184 $( '[id*=prflxtrflds-show-in-]' ).each(
185 function() {
186 if ( $( this ).is( ':checked' ) ) {
187 $( '.' + this.id ).show();
188 } else {
189 $( '.' + this.id ).hide();
190 }
191 }
192 );
193
194 /* Make inputs always send value */
195 $( '.prflxtrflds-hidden-checkbox' ).each(
196 function( i, e ) {
197 e.disabled = $( '[type="checkbox"][name="' + e.name + '"]' ).prop( 'checked' );
198
199 $( '[name="' + e.name + '"]' ).change(
200 function( e ) {
201 $( '[type="hidden"][name="' + e.target.name + '"]' ).prop( 'disabled', e.target.checked );
202 }
203 );
204 }
205 );
206
207 /* Show 'select all' checkbox if js enabled */
208 $( '#prflxtrflds-div-select-all' ).show();
209
210 $( '.prflxtrflds-checkboxes-select-all-in-roles' ).on(
211 'click',
212 function() {
213 var $parent = $( this ).closest( 'td' ),
214 $child_cb = $parent.find( '.prflxtrflds-checkboxes-in-roles' ),
215 $child_cb_disabled = $parent.find( '.prflxtrflds-checkboxes-in-roles' ).filter( ':disabled' );
216 if ( $( this ).is( ':checked' ) ) {
217 $child_cb.prop( 'checked', true ).trigger( 'change' );
218 $child_cb_disabled.removeAttr( 'checked' ).trigger( 'change' );
219 } else {
220 $child_cb.removeAttr( 'checked' ).trigger( 'change' );
221 }
222 }
223 );
224
225 $( '.prflxtrflds-checkboxes-in-roles' ).on(
226 'change',
227 function() {
228 var $parent = $( this ).closest( 'td' ),
229 $cb_all = $parent.find( '.prflxtrflds-checkboxes-select-all-in-roles' ),
230
231 $checkboxes = $parent.find( '.prflxtrflds-checkboxes-in-roles' ).filter( ':enabled' ),
232 $enabled_checkboxes = $checkboxes.filter( ':checked' );
233
234 if ( $checkboxes.length > 0 && $checkboxes.length == $enabled_checkboxes.length ) {
235 $cb_all.prop( 'checked', true );
236 $cb_all.removeAttr( 'disabled' );
237 } else {
238 $cb_all.removeAttr( 'checked' );
239 $cb_all.removeAttr( 'disabled' );
240 }
241 }
242 ).trigger( 'change' );
243
244 $( '.prflxtrflds-checkboxes-available' ).on(
245 'change',
246 function() {
247 var $parent = $( this ).closest( 'td' ),
248 role_id = $( this ).data( 'prflxtrflds-role-id' ),
249 checkboxes = $( '.prflxtrflds-checkboxes-editable[data-prflxtrflds-role-id="' + role_id + '"], .prflxtrflds-checkboxes-visible[data-prflxtrflds-role-id="' + role_id + '"]' );
250 if ( $( this ).is( ':checked' ) ) {
251 checkboxes.removeAttr( 'checked' ).trigger( 'change' );
252 checkboxes.removeAttr( 'disabled' ).trigger( 'change' );
253 } else {
254 checkboxes.prop( 'disabled', true ).trigger( 'change' );
255 checkboxes.removeAttr( 'checked' ).trigger( 'change' );
256 }
257 }
258 );
259
260 var table = $( 'table.toplevel_page_profile-extra-fields' );
261 if ( table.length > 1 ) {
262 table.wrap( '<div class="postbox prflxtrflds-table-wrap"><div class="inside"></div></div>' );
263 table.parents( 'form' ).addClass( 'meta-box-sortables' );
264
265 var table_wrap = $( '.prflxtrflds-table-wrap' );
266
267 table_wrap.prepend( '<h2 class="hndle"></h2>' );
268
269 table_wrap.each(
270 function( i, e ) {
271 var $this = $( e ),
272 name = $this.next( '.prflxtrflds-tables-name' ).val(),
273 button = '<button type="button" class="handlediv" aria-expanded="true"><span class="screen-reader-text">Toggle panel: <label><input class="hide-if-no-js" id="plugins_checkbox" type="checkbox" value="prflxtrflds_tab_button">' + name + '</label></span><span class="toggle-indicator" aria-hidden="true"></span></button>';
274
275 $this.prepend( button );
276 $this.find( '.hndle' ).text( name );
277 }
278 );
279
280 $( '.prflxtrflds-table-wrap .hndle, .prflxtrflds-table-wrap .handlediv' ).click(
281 function( e ) {
282 $( e.target ).parents( '.prflxtrflds-table-wrap' ).toggleClass( 'closed' );
283 }
284 );
285 }
286
287 $( '#prflxtrflds_notify_admin_register' ).on(
288 'change',
289 function() {
290 if ( this.checked ) {
291 $( '.prflxtrflds_notify_admin_register' ).show();
292 } else {
293 $( '.prflxtrflds_notify_admin_register' ).hide();
294 }
295 }
296 ).trigger( 'change' );
297
298 $( '#prflxtrflds_notify_user_register' ).on(
299 'change',
300 function() {
301 if ( this.checked ) {
302 $( '.prflxtrflds_notify_user_register' ).show();
303 } else {
304 $( '.prflxtrflds_notify_user_register' ).hide();
305 }
306 }
307 ).trigger( 'change' );
308 }
309 );
310 } )( jQuery );
311