| 1 |
/* globals jQuery, wp_stream */ |
| 2 |
jQuery( |
| 3 |
function( $ ) { |
| 4 |
var network_affix; |
| 5 |
if ( 'wp_stream_network' === $( 'input[name="option_page"]' ).val() ) { |
| 6 |
network_affix = '_network_affix'; |
| 7 |
} else { |
| 8 |
network_affix = ''; |
| 9 |
} |
| 10 |
var keepRecordsIndefinitely = $( '#wp_stream' + network_affix + '\\[general_keep_records_indefinitely\\]' ), |
| 11 |
keepRecordsFor = $( '#wp_stream' + network_affix + '_general_records_ttl' ), |
| 12 |
keepRecordsForRow = keepRecordsFor.closest( 'tr' ); |
| 13 |
|
| 14 |
function toggleKeepRecordsFor() { |
| 15 |
if ( keepRecordsIndefinitely.is( ':checked' ) ) { |
| 16 |
keepRecordsForRow.addClass( 'hidden' ); |
| 17 |
keepRecordsFor.addClass( 'hidden' ); |
| 18 |
} else { |
| 19 |
keepRecordsForRow.removeClass( 'hidden' ); |
| 20 |
keepRecordsFor.removeClass( 'hidden' ); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
keepRecordsIndefinitely.on( |
| 25 |
'change', function() { |
| 26 |
toggleKeepRecordsFor(); |
| 27 |
} |
| 28 |
); |
| 29 |
|
| 30 |
toggleKeepRecordsFor(); |
| 31 |
|
| 32 |
// Confirmation on some important actions |
| 33 |
$( '#wp_stream_general_reset_site_settings' ).click( |
| 34 |
function( e ) { |
| 35 |
if ( ! confirm( wp_stream.i18n.confirm_defaults ) ) { |
| 36 |
e.preventDefault(); |
| 37 |
} |
| 38 |
} |
| 39 |
); |
| 40 |
|
| 41 |
// Settings page tabs |
| 42 |
var $tabs = $( '.nav-tab-wrapper' ), |
| 43 |
$panels = $( '.nav-tab-content table.form-table' ), |
| 44 |
$activeTab = $tabs.find( '.nav-tab-active' ), |
| 45 |
defaultIndex = $activeTab.length > 0 ? $tabs.find( 'a' ).index( $activeTab ) : 0, |
| 46 |
hashIndexStart = window.location.hash.match( /^#(\d+)$/ ), |
| 47 |
currentHash = ( null !== hashIndexStart ? hashIndexStart[ 1 ] : defaultIndex ), |
| 48 |
syncFormAction = function( index ) { |
| 49 |
var $optionsForm = $( 'input[name="option_page"][value^="wp_stream"]' ).closest( 'form' ); |
| 50 |
if ( $optionsForm.length === 0 ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
var currentAction = $optionsForm.attr( 'action' ); |
| 54 |
|
| 55 |
$optionsForm.prop( 'action', currentAction.replace( /(^[^#]*).*$/, '$1#' + index ) ); |
| 56 |
}; |
| 57 |
|
| 58 |
$tabs.on( |
| 59 |
'click', 'a', function() { |
| 60 |
var index = $tabs.find( 'a' ).index( $( this ) ), |
| 61 |
hashIndex = window.location.hash.match( /^#(\d+)$/ ); |
| 62 |
|
| 63 |
$panels.hide().eq( index ).show(); |
| 64 |
|
| 65 |
$tabs |
| 66 |
.find( 'a' ) |
| 67 |
.removeClass( 'nav-tab-active' ) |
| 68 |
.filter( $( this ) ) |
| 69 |
.addClass( 'nav-tab-active' ); |
| 70 |
|
| 71 |
if ( '' === window.location.hash || null !== hashIndex ) { |
| 72 |
window.location.hash = index; |
| 73 |
} |
| 74 |
|
| 75 |
syncFormAction( index ); |
| 76 |
|
| 77 |
return false; |
| 78 |
} |
| 79 |
); |
| 80 |
|
| 81 |
$tabs.children().eq( currentHash ).trigger( 'click' ); |
| 82 |
} |
| 83 |
); |
| 84 |
|