admin-dashboard.js
5 years ago
admin-post.js
5 years ago
admin-quick-edit.js
5 years ago
admin-settings.js
5 years ago
admin-widgets.js
5 years ago
frontend.js
5 years ago
gutenberg.min.js
6 years ago
admin-settings.js
66 lines
| 1 | ( function( $ ) { |
| 2 | |
| 3 | // ready event |
| 4 | $( function() { |
| 5 | var ip_boxes = $( '#pvc_exclude_ips' ).find( '.ip-box' ).length; |
| 6 | |
| 7 | $( '#pvc_exclude_ips .ip-box:first' ).find( '.remove-exclude-ip' ).hide(); |
| 8 | |
| 9 | // ask whether to reset options to defaults |
| 10 | $( document ).on( 'click', '.reset_pvc_settings', function() { |
| 11 | return confirm( pvcArgsSettings.resetToDefaults ); |
| 12 | } ); |
| 13 | |
| 14 | // ask whether to reset views |
| 15 | $( document ).on( 'click', 'input[name="post_views_counter_reset_views"]', function() { |
| 16 | return confirm( pvcArgsSettings.resetViews ); |
| 17 | } ); |
| 18 | |
| 19 | // remove ip box |
| 20 | $( document ).on( 'click', '.remove-exclude-ip', function( e ) { |
| 21 | e.preventDefault(); |
| 22 | |
| 23 | ip_boxes--; |
| 24 | |
| 25 | var parent = $( this ).parent(); |
| 26 | |
| 27 | // remove ip box |
| 28 | parent.slideUp( 'fast', function() { |
| 29 | $( this ).remove(); |
| 30 | } ); |
| 31 | } ); |
| 32 | |
| 33 | // add ip box |
| 34 | $( document ).on( 'click', '.add-exclude-ip', function() { |
| 35 | ip_boxes++; |
| 36 | |
| 37 | var parent = $( this ).parents( '#pvc_exclude_ips' ), |
| 38 | new_ip_box = parent.find( '.ip-box:last' ).clone().hide(); |
| 39 | |
| 40 | // clear value |
| 41 | new_ip_box.find( 'input' ).val( '' ); |
| 42 | |
| 43 | if ( ip_boxes > 1 ) { |
| 44 | new_ip_box.find( '.remove-exclude-ip' ).show(); |
| 45 | } |
| 46 | |
| 47 | // add and display new ip box |
| 48 | parent.find( '.ip-box:last' ).after( new_ip_box ).next().slideDown( 'fast' ); |
| 49 | } ); |
| 50 | |
| 51 | // add current ip |
| 52 | $( document ).on( 'click', '.add-current-ip', function() { |
| 53 | // fill input with user's current ip |
| 54 | $( this ).parents( '#pvc_exclude_ips' ).find( '.ip-box' ).last().find( 'input' ).val( $( this ).attr( 'data-rel' ) ); |
| 55 | } ); |
| 56 | |
| 57 | // toggle user roles |
| 58 | $( '#pvc_exclude-roles, #pvc_restrict_display-roles' ).on( 'change', function() { |
| 59 | if ( $( this ).is( ':checked' ) ) |
| 60 | $( '.pvc_user_roles' ).slideDown( 'fast' ); |
| 61 | else |
| 62 | $( '.pvc_user_roles' ).slideUp( 'fast' ); |
| 63 | } ); |
| 64 | } ); |
| 65 | |
| 66 | } )( jQuery ); |