admin-dashboard.js
2 years ago
admin-post.js
5 years ago
admin-quick-edit.js
5 years ago
admin-settings.js
2 years ago
admin-widgets.js
5 years ago
block-editor.min.js
2 years ago
counter.js
2 years ago
counter.min.js
2 years ago
frontend.js
2 years ago
frontend.min.js
2 years ago
admin-settings.js
80 lines
| 1 | ( function( $ ) { |
| 2 | |
| 3 | // ready event |
| 4 | $( function() { |
| 5 | var ip_boxes = $( '#post_views_counter_general_exclude_ips_setting' ).find( '.ip-box' ).length; |
| 6 | |
| 7 | $( '#post_views_counter_general_exclude_ips_setting .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 | var result = confirm( pvcArgsSettings.resetToDefaults ); |
| 12 | |
| 13 | if ( result && $( this ).hasClass( 'reset_post_views_counter_settings_general' ) ) { |
| 14 | $( 'input[data-pvc-menu="submenu"]' ).before( $( 'input[data-pvc-menu="topmenu"]' ) ); |
| 15 | } |
| 16 | |
| 17 | return result; |
| 18 | } ); |
| 19 | |
| 20 | // ask whether to reset views |
| 21 | $( document ).on( 'click', 'input[name="post_views_counter_reset_views"]', function() { |
| 22 | return confirm( pvcArgsSettings.resetViews ); |
| 23 | } ); |
| 24 | |
| 25 | // remove ip box |
| 26 | $( document ).on( 'click', '.remove-exclude-ip', function( e ) { |
| 27 | e.preventDefault(); |
| 28 | |
| 29 | ip_boxes--; |
| 30 | |
| 31 | var parent = $( this ).parent(); |
| 32 | |
| 33 | // remove ip box |
| 34 | parent.slideUp( 'fast', function() { |
| 35 | $( this ).remove(); |
| 36 | } ); |
| 37 | } ); |
| 38 | |
| 39 | // add ip box |
| 40 | $( document ).on( 'click', '.add-exclude-ip', function() { |
| 41 | ip_boxes++; |
| 42 | |
| 43 | var parent = $( this ).parents( '#post_views_counter_general_exclude_ips_setting' ), |
| 44 | new_ip_box = parent.find( '.ip-box:last' ).clone().hide(); |
| 45 | |
| 46 | // clear value |
| 47 | new_ip_box.find( 'input' ).val( '' ); |
| 48 | |
| 49 | if ( ip_boxes > 1 ) |
| 50 | new_ip_box.find( '.remove-exclude-ip' ).show(); |
| 51 | |
| 52 | // add and display new ip box |
| 53 | parent.find( '.ip-box:last' ).after( new_ip_box ).next().slideDown( 'fast' ); |
| 54 | } ); |
| 55 | |
| 56 | // add current ip |
| 57 | $( document ).on( 'click', '.add-current-ip', function() { |
| 58 | // fill input with user's current ip |
| 59 | $( this ).parents( '#post_views_counter_general_exclude_ips_setting' ).find( '.ip-box' ).last().find( 'input' ).val( $( this ).attr( 'data-rel' ) ); |
| 60 | } ); |
| 61 | |
| 62 | // toggle user roles |
| 63 | $( '#pvc_exclude-roles, #pvc_restrict_display-roles' ).on( 'change', function() { |
| 64 | if ( $( this ).is( ':checked' ) ) |
| 65 | $( '.pvc_user_roles' ).slideDown( 'fast' ); |
| 66 | else |
| 67 | $( '.pvc_user_roles' ).slideUp( 'fast' ); |
| 68 | } ); |
| 69 | |
| 70 | // menu position referer update |
| 71 | $( 'input[name="post_views_counter_settings_other[menu_position]"]' ).on( 'change', function() { |
| 72 | if ( $( this ).val() === 'top' ) { |
| 73 | $( 'input[data-pvc-menu="submenu"]' ).after( $( 'input[data-pvc-menu="topmenu"]' ) ); |
| 74 | } else { |
| 75 | $( 'input[data-pvc-menu="submenu"]' ).before( $( 'input[data-pvc-menu="topmenu"]' ) ); |
| 76 | } |
| 77 | } ); |
| 78 | } ); |
| 79 | |
| 80 | } )( jQuery ); |