Nessuna descrizione

jetpack-modules.views.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. this.jetpackModules = this.jetpackModules || {};
  2. window.jetpackModules.views = ( function ( window, $, _, Backbone, wp ) {
  3. 'use strict';
  4. var views = {};
  5. views.List_Table = Backbone.View.extend( {
  6. template: wp.template( 'Jetpack_Modules_List_Table_Template' ),
  7. /**
  8. * If we can, use replaceState to change the URL and indicate the new filtering.
  9. * This will be handy with redirecting back to the same state after activating/deactivating.
  10. */
  11. updateUrl: function () {
  12. if ( ! window.history.replaceState ) {
  13. return;
  14. }
  15. var url = window.location.href.split( '?' )[ 0 ] + '?page=jetpack_modules',
  16. m_tag = $( '.subsubsub .current' ),
  17. m_filter = $( '.button-group.filter-active .active' ),
  18. m_sort = $( '.button-group.sort .active' ),
  19. m_search = $( '#srch-term-search-input' ).val();
  20. if ( m_search.length ) {
  21. url += '&s=' + encodeURIComponent( m_search );
  22. }
  23. if ( ! m_tag.hasClass( 'all' ) ) {
  24. url += '&module_tag=' + encodeURIComponent( m_tag.data( 'title' ) );
  25. }
  26. if ( m_filter.data( 'filter-by' ) ) {
  27. url +=
  28. '&' +
  29. encodeURIComponent( m_filter.data( 'filter-by' ) ) +
  30. '=' +
  31. encodeURIComponent( m_filter.data( 'filter-value' ) );
  32. }
  33. if ( 'name' !== m_sort.data( 'sort-by' ) ) {
  34. url += '&sort_by=' + encodeURIComponent( m_sort.data( 'sort-by' ) );
  35. }
  36. window.history.replaceState( {}, '', url );
  37. },
  38. render: function () {
  39. this.model.filter_and_sort();
  40. this.$el.html( this.template( this.model.attributes ) );
  41. this.updateUrl();
  42. return this;
  43. },
  44. initialize: function () {
  45. this.listenTo( this.model, 'change', this.render );
  46. },
  47. } );
  48. return views;
  49. } )( this, jQuery, _, Backbone, wp );