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