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