Brak opisu

jetpack-modules.js 2.4KB

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