jetpack-modules.js 2.4 KB

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