| 1 |
|
| 2 |
( function( window, $, items, models, views, i18n, modalinfo, nonces ) { |
| 3 |
'use strict'; |
| 4 |
|
| 5 |
var modules, list_table, handle_module_tag_click, $the_table, $the_filters, $the_search, $jp_frame, $bulk_button; |
| 6 |
|
| 7 |
$the_table = $( '.wp-list-table.jetpack-modules' ); |
| 8 |
$the_filters = $( '.navbar-form' ); |
| 9 |
$the_search = $( '#srch-term-search-input' ); |
| 10 |
$jp_frame = $( '.jp-frame' ); |
| 11 |
$bulk_button = $( '#doaction' ); |
| 12 |
|
| 13 |
modules = new models.Modules( { |
| 14 |
items : items |
| 15 |
} ); |
| 16 |
|
| 17 |
list_table = new views.List_Table( { |
| 18 |
el : '#the-list', |
| 19 |
model : modules |
| 20 |
} ); |
| 21 |
|
| 22 |
// Kick off an initial redraw. |
| 23 |
modules.trigger( 'change' ); |
| 24 |
|
| 25 |
// Handle the filtering of modules. |
| 26 |
handle_module_tag_click = function( event ) { |
| 27 |
// Switch the item in the subsubsub list that's flagged as current. |
| 28 |
$( '.subsubsub' ).find( 'a[data-title="' + $(this).data('title') + '"]' ).addClass( 'current' ) |
| 29 |
.closest( 'li' ).siblings().find( 'a.current' ).removeClass( 'current' ); |
| 30 |
|
| 31 |
event.preventDefault(); |
| 32 |
modules.trigger( 'change' ); |
| 33 |
}; |
| 34 |
|
| 35 |
$( '.subsubsub a' ).on( 'click', { modules : modules }, handle_module_tag_click ); |
| 36 |
|
| 37 |
$the_filters.on( 'click', '.button-group .button', { modules : modules }, function( event ) { |
| 38 |
event.preventDefault(); |
| 39 |
$(this).addClass('active').siblings('.active').removeClass('active'); |
| 40 |
modules.trigger( 'change' ); |
| 41 |
} ); |
| 42 |
|
| 43 |
$the_search.on( 'keyup search', function( e ) { |
| 44 |
// Don't trigger change on tab, since it's only used for accessibility |
| 45 |
// anyway, and will remove all checked boxes |
| 46 |
if ( e.keyCode !== 9 ) { |
| 47 |
modules.trigger( 'change' ); |
| 48 |
} |
| 49 |
} ); |
| 50 |
|
| 51 |
$the_search.prop( 'placeholder', i18n.search_placeholder ); |
| 52 |
|
| 53 |
$bulk_button.on( 'click', function( event ) { |
| 54 |
var selectedModules = $('.jetpack-modules-list-table-form').serialize(), |
| 55 |
selectedAction = $(this).siblings('select').val(), |
| 56 |
url; |
| 57 |
|
| 58 |
if ( selectedModules.length && '-1' !== selectedAction ) { |
| 59 |
url = 'admin.php?page=jetpack&action=' + encodeURIComponent( selectedAction ); |
| 60 |
url += '&' + selectedModules; |
| 61 |
url += '&_wpnonce=' + encodeURIComponent( nonces.bulk ); |
| 62 |
|
| 63 |
window.location.href = url; |
| 64 |
} else { |
| 65 |
// Possibly add in an alert here explaining why nothing's happening? |
| 66 |
} |
| 67 |
|
| 68 |
event.preventDefault(); |
| 69 |
} ); |
| 70 |
|
| 71 |
} ) ( this, jQuery, window.jetpackModulesData.modules, this.jetpackModules.models, this.jetpackModules.views, window.jetpackModulesData.i18n, window.jetpackModulesData.modalinfo, window.jetpackModulesData.nonces ); |
| 72 |
|