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