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
column-modal.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
129 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 | // ask whether to import views |
| 25 | $( document ).on( 'click', 'input[name="post_views_counter_import_views"]', function() { |
| 26 | return confirm( pvcArgsSettings.importViews ); |
| 27 | } ); |
| 28 | |
| 29 | // remove ip box |
| 30 | $( document ).on( 'click', '.remove-exclude-ip', function( e ) { |
| 31 | e.preventDefault(); |
| 32 | |
| 33 | ip_boxes--; |
| 34 | |
| 35 | var parent = $( this ).parent(); |
| 36 | |
| 37 | // remove ip box |
| 38 | parent.slideUp( 'fast', function() { |
| 39 | $( this ).remove(); |
| 40 | } ); |
| 41 | } ); |
| 42 | |
| 43 | // add ip box |
| 44 | $( document ).on( 'click', '.add-exclude-ip', function() { |
| 45 | ip_boxes++; |
| 46 | |
| 47 | var parent = $( this ).parents( '#post_views_counter_general_exclude_ips_setting' ), |
| 48 | new_ip_box = parent.find( '.ip-box:last' ).clone().hide(); |
| 49 | |
| 50 | // clear value |
| 51 | new_ip_box.find( 'input' ).val( '' ); |
| 52 | |
| 53 | if ( ip_boxes > 1 ) |
| 54 | new_ip_box.find( '.remove-exclude-ip' ).show(); |
| 55 | |
| 56 | // add and display new ip box |
| 57 | parent.find( '.ip-box:last' ).after( new_ip_box ).next().slideDown( 'fast' ); |
| 58 | } ); |
| 59 | |
| 60 | // add current ip |
| 61 | $( document ).on( 'click', '.add-current-ip', function() { |
| 62 | // fill input with user's current ip |
| 63 | $( this ).parents( '#post_views_counter_general_exclude_ips_setting' ).find( '.ip-box' ).last().find( 'input' ).val( $( this ).attr( 'data-rel' ) ); |
| 64 | } ); |
| 65 | |
| 66 | // toggle user roles |
| 67 | $( '#pvc_exclude-roles, #pvc_restrict_display-roles' ).on( 'change', function() { |
| 68 | if ( $( this ).is( ':checked' ) ) |
| 69 | $( '.pvc_user_roles' ).slideDown( 'fast' ); |
| 70 | else |
| 71 | $( '.pvc_user_roles' ).slideUp( 'fast' ); |
| 72 | } ); |
| 73 | |
| 74 | // menu position referer update |
| 75 | $( 'input[name="post_views_counter_settings_display[menu_position]"], input[name="post_views_counter_settings_other[menu_position]"]' ).on( 'change', function() { |
| 76 | if ( $( this ).val() === 'top' ) |
| 77 | $( 'input[data-pvc-menu="submenu"]' ).after( $( 'input[data-pvc-menu="topmenu"]' ) ); |
| 78 | else |
| 79 | $( 'input[data-pvc-menu="submenu"]' ).before( $( 'input[data-pvc-menu="topmenu"]' ) ); |
| 80 | } ); |
| 81 | |
| 82 | // import provider switching |
| 83 | $( 'input[name="pvc_import_provider"]' ).on( 'change', function() { |
| 84 | var selectedProvider = $( this ).val(), |
| 85 | $current = $( '.pvc-provider-content:visible' ), |
| 86 | $target = $( '.pvc-provider-' + selectedProvider ); |
| 87 | |
| 88 | if ( ! $target.length || $target.is( ':visible' ) ) |
| 89 | return; |
| 90 | |
| 91 | $current.stop( true, true ).slideUp( 'fast', function() { |
| 92 | $target.stop( true, true ).slideDown( 'fast' ); |
| 93 | } ); |
| 94 | } ); |
| 95 | |
| 96 | // import strategy description switching |
| 97 | ( function() { |
| 98 | var $container = $( '.pvc-import-strategy-details' ), |
| 99 | $strategyRadios = $( 'input[name="pvc_import_strategy"]' ); |
| 100 | |
| 101 | if ( ! $container.length || ! $strategyRadios.length ) |
| 102 | return; |
| 103 | |
| 104 | var showStrategy = function( slug ) { |
| 105 | var $target = $container.find( '.pvc-strategy-' + slug ); |
| 106 | |
| 107 | if ( ! $target.length ) |
| 108 | return; |
| 109 | |
| 110 | var $current = $container.find( '.pvc-strategy-content:visible' ); |
| 111 | |
| 112 | if ( $target.is( ':visible' ) ) |
| 113 | return; |
| 114 | |
| 115 | $current.stop( true, true ).slideUp( 'fast', function() { |
| 116 | $target.stop( true, true ).slideDown( 'fast' ); |
| 117 | } ); |
| 118 | }; |
| 119 | |
| 120 | $strategyRadios.on( 'change', function() { |
| 121 | showStrategy( $( this ).val() ); |
| 122 | } ); |
| 123 | |
| 124 | showStrategy( $strategyRadios.filter( ':checked' ).val() ); |
| 125 | } )(); |
| 126 | } ); |
| 127 | |
| 128 | } )( jQuery ); |
| 129 |