click-to-copy.js
1 day ago
post-type-help-doc-imports.js
1 day ago
post-type-help-docs.js
1 day ago
qs-add.js
1 day ago
qs-remove.js
1 day ago
post-type-help-doc-imports.js
45 lines
| 1 | jQuery( document ).ready( function( $ ) { |
| 2 | |
| 3 | $( document ).on( 'click', '.helpdocs-status-toggle', function() { |
| 4 | const $btn = $( this ); |
| 5 | const post_id = $btn.data( 'id' ); |
| 6 | |
| 7 | if ( $btn.hasClass( 'updating' ) ) { |
| 8 | return; |
| 9 | } |
| 10 | |
| 11 | $btn.addClass( 'updating' ); |
| 12 | |
| 13 | $.post( ajaxurl, { |
| 14 | action: 'helpdocs_toggle_import_status', |
| 15 | nonce: helpdocs_help_doc_imports.nonce, |
| 16 | id: post_id |
| 17 | }, function( response ) { |
| 18 | if ( response.success ) { |
| 19 | if ( response.data.active ) { |
| 20 | $btn.removeClass( 'is-inactive' ) |
| 21 | .addClass( 'is-active' ) |
| 22 | .find( '.helpdocs-post-status' ) |
| 23 | .text( helpdocs_help_doc_imports.active_text ); |
| 24 | |
| 25 | $btn.addClass( 'helpdocs-success-pulse' ); |
| 26 | |
| 27 | setTimeout( function() { |
| 28 | $btn.removeClass( 'helpdocs-success-pulse' ); |
| 29 | }, 500 ); |
| 30 | |
| 31 | } else { |
| 32 | $btn.removeClass( 'is-active' ) |
| 33 | .addClass( 'is-inactive' ) |
| 34 | .find( '.helpdocs-post-status' ) |
| 35 | .text( helpdocs_help_doc_imports.inactive_text ); |
| 36 | } |
| 37 | } else { |
| 38 | alert( response.data ); |
| 39 | } |
| 40 | |
| 41 | $btn.removeClass( 'updating' ); |
| 42 | } ); |
| 43 | } ); |
| 44 | |
| 45 | } ); |