settings.js
60 lines
| 1 | ( function( $ ) { |
| 2 | /** |
| 3 | * Settings box tabs |
| 4 | * |
| 5 | * We can't use core's tabs script here because it will clear the |
| 6 | * checkboxes upon tab switching |
| 7 | */ |
| 8 | $( '#menu-icons-settings-tabs' ) |
| 9 | .on( 'click', 'a.mi-settings-nav-tab', function( e ) { |
| 10 | var $el = $( this ).blur(), |
| 11 | $target = $( '#' + $el.data( 'type' ) ); |
| 12 | |
| 13 | e.preventDefault(); |
| 14 | e.stopPropagation(); |
| 15 | |
| 16 | $el.parent().addClass( 'tabs' ).siblings().removeClass( 'tabs' ); |
| 17 | $target |
| 18 | .removeClass( 'tabs-panel-inactive' ) |
| 19 | .addClass( 'tabs-panel-active' ) |
| 20 | .show() |
| 21 | .siblings( 'div.tabs-panel' ) |
| 22 | .hide() |
| 23 | .addClass( 'tabs-panel-inactive' ) |
| 24 | .removeClass( 'tabs-panel-active' ); |
| 25 | }) |
| 26 | .find( 'a.mi-settings-nav-tab' ).first().click(); |
| 27 | |
| 28 | // Settings meta box |
| 29 | $( '#menu-icons-settings-save' ).on( 'click', function( e ) { |
| 30 | var $button = $( this ).prop( 'disabled', true ), |
| 31 | $spinner = $button.siblings( 'span.spinner' ); |
| 32 | |
| 33 | e.preventDefault(); |
| 34 | e.stopPropagation(); |
| 35 | |
| 36 | $spinner.css({ |
| 37 | display: 'inline-block', |
| 38 | visibility: 'visible' |
| 39 | }); |
| 40 | |
| 41 | $.ajax({ |
| 42 | type: 'POST', |
| 43 | url: window.menuIcons.ajaxUrls.update, |
| 44 | data: $( '#menu-icons-settings :input' ).serialize(), |
| 45 | |
| 46 | success: function( response ) { |
| 47 | if ( response.success && response.data.redirectUrl === true ) { |
| 48 | window.location = response.data.redirectUrl; |
| 49 | } else { |
| 50 | $button.prop( 'disabled', false ); |
| 51 | } |
| 52 | }, |
| 53 | |
| 54 | always: function() { |
| 55 | $spinner.hide(); |
| 56 | } |
| 57 | }); |
| 58 | }); |
| 59 | })( jQuery ); |
| 60 |