blocks
5 days ago
build
5 days ago
fonts
1 year ago
genericons
5 months ago
lib
5 days ago
accessible-focus.js
6 years ago
blogging-prompts.php
1 month ago
class.jetpack-provision.php
8 months ago
content-guidelines-ai.js
2 weeks ago
content-guidelines-ai.php
1 week ago
crowdsignal-shortcode.js
1 year ago
crowdsignal-survey.js
6 years ago
deprecate.js
8 months ago
facebook-embed.js
4 years ago
gallery-settings.js
6 years ago
genericons.php
1 year ago
jetpack-admin.js
3 years ago
jetpack-deactivate-dialog.js
1 year ago
jetpack-modules.js
5 days ago
jetpack-modules.models.js
5 days ago
jetpack-modules.views.js
5 days ago
polldaddy-shortcode.js
3 weeks ago
site-switcher-endpoint.php
6 months ago
site-switcher.jsx
2 weeks ago
site-switcher.php
6 months ago
social-logos.php
4 months ago
twitter-timeline.js
2 months ago
jetpack-modules.js
100 lines
| 1 | ( function ( window, $, items, models, views, i18n, modalinfo, nonces ) { |
| 2 | 'use strict'; |
| 3 | |
| 4 | var modules, list_table, handle_facet_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. The tag list (".subsubsub") and the |
| 24 | // "Purpose" list (".purpose-filter") are independent single-select facets |
| 25 | // that share this behaviour and combine with one another. |
| 26 | handle_facet_click = function ( event ) { |
| 27 | event.preventDefault(); |
| 28 | |
| 29 | var $link = $( this ); |
| 30 | |
| 31 | // Ignore facets greyed out because they have no matches under the current filters. |
| 32 | if ( $link.closest( 'li' ).hasClass( 'is-empty' ) ) { |
| 33 | return; |
| 34 | } |
| 35 | |
| 36 | // Move the "current" selection within this facet list only. |
| 37 | var $list = $link.closest( '.subsubsub, .purpose-filter' ); |
| 38 | $list.find( 'li.current' ).removeClass( 'current' ); |
| 39 | $link.closest( 'li' ).addClass( 'current' ); |
| 40 | |
| 41 | modules.trigger( 'change' ); |
| 42 | }; |
| 43 | |
| 44 | $( '.subsubsub a, .purpose-filter a' ).on( 'click', handle_facet_click ); |
| 45 | |
| 46 | $the_filters.on( 'click', '.button-group .button', { modules: modules }, function ( event ) { |
| 47 | event.preventDefault(); |
| 48 | |
| 49 | // Each button group is an independent, single-select facet: activating a |
| 50 | // button clears only its siblings. State and Purpose are separate groups, |
| 51 | // so their selections combine rather than replacing one another. |
| 52 | $( this ).addClass( 'active' ).siblings( '.active' ).removeClass( 'active' ); |
| 53 | |
| 54 | modules.trigger( 'change' ); |
| 55 | } ); |
| 56 | |
| 57 | $the_search.on( |
| 58 | 'keyup search', |
| 59 | // Debounce so we re-render (and history.replaceState) once the user |
| 60 | // pauses typing rather than on every keystroke. This keeps the ~50-row |
| 61 | // rebuild off the critical path and avoids Safari's replaceState rate limit. |
| 62 | window._.debounce( function ( e ) { |
| 63 | // Don't trigger change on tab, since it's only used for accessibility |
| 64 | // anyway, and will remove all checked boxes |
| 65 | if ( e.code !== 'Tab' ) { |
| 66 | modules.trigger( 'change' ); |
| 67 | } |
| 68 | }, 200 ) |
| 69 | ); |
| 70 | |
| 71 | $the_search.prop( 'placeholder', i18n.search_placeholder ); |
| 72 | |
| 73 | $bulk_button.on( 'click', function ( event ) { |
| 74 | var selectedModules = $( '.jetpack-modules-list-table-form' ).serialize(), |
| 75 | selectedAction = $( this ).siblings( 'select' ).val(), |
| 76 | url; |
| 77 | |
| 78 | if ( selectedModules.length && '-1' !== selectedAction ) { |
| 79 | url = 'admin.php?page=jetpack&action=' + encodeURIComponent( selectedAction ); |
| 80 | url += '&' + selectedModules; |
| 81 | url += '&_wpnonce=' + encodeURIComponent( nonces.bulk ); |
| 82 | |
| 83 | window.location.href = url; |
| 84 | } else { |
| 85 | // Possibly add in an alert here explaining why nothing's happening? |
| 86 | } |
| 87 | |
| 88 | event.preventDefault(); |
| 89 | } ); |
| 90 | } )( |
| 91 | window, |
| 92 | jQuery, |
| 93 | window.jetpackModulesData.modules, |
| 94 | window.jetpackModules.models, |
| 95 | window.jetpackModules.views, |
| 96 | window.jetpackModulesData.i18n, |
| 97 | window.jetpackModulesData.modalinfo, |
| 98 | window.jetpackModulesData.nonces |
| 99 | ); |
| 100 |