blocks
6 years ago
build
6 years ago
fonts
8 years ago
genericons
6 years ago
lib
6 years ago
social-logos
7 years ago
accessible-focus.js
8 years ago
class.jetpack-provision.php
6 years ago
connect-button.js
6 years ago
crowdsignal-shortcode.js
7 years ago
crowdsignal-survey.js
7 years ago
facebook-embed.js
7 years ago
footer.php
7 years ago
gallery-settings.js
7 years ago
genericons.php
11 years ago
header.php
7 years ago
idc-notice.js
7 years ago
jetpack-admin.js
7 years ago
jetpack-connection-banner.js
6 years ago
jetpack-jitm.js
7 years ago
jetpack-modules.js
7 years ago
jetpack-modules.models.js
6 years ago
jetpack-modules.views.js
7 years ago
jetpack-server-sandbox.php
6 years ago
jetpack-strings.php
6 years ago
jquery.jetpack-resize.js
7 years ago
jquery.spin.js
8 years ago
polldaddy-shortcode.js
6 years ago
postmessage.js
8 years ago
social-logos.php
9 years ago
spin.js
8 years ago
twitter-timeline.js
6 years ago
jetpack-modules.models.js
81 lines
| 1 | this.jetpackModules = this.jetpackModules || {}; |
| 2 | |
| 3 | window.jetpackModules.models = ( function( window, $, _, Backbone ) { |
| 4 | 'use strict'; |
| 5 | |
| 6 | var models = {}; |
| 7 | |
| 8 | models.Modules = Backbone.Model.extend( { |
| 9 | visibles: {}, |
| 10 | |
| 11 | /** |
| 12 | * Updates modules.items dataset to be a reflection of both the current |
| 13 | * modules.raw data, as well as any filters or sorting that may be in effect. |
| 14 | */ |
| 15 | filter_and_sort: function() { |
| 16 | var subsubsub = $( '.subsubsub .current' ), |
| 17 | items = this.get( 'raw' ), |
| 18 | m_filter = $( '.button-group.filter-active .active' ), |
| 19 | m_sort = $( '.button-group.sort .active' ), |
| 20 | m_search = $( '#srch-term-search-input' ) |
| 21 | .val() |
| 22 | .toLowerCase(), |
| 23 | groups; |
| 24 | |
| 25 | // If a module filter has been selected, filter it! |
| 26 | if ( ! subsubsub.closest( 'li' ).hasClass( 'all' ) ) { |
| 27 | items = _.filter( items, function( item ) { |
| 28 | return _.contains( item.module_tags, subsubsub.data( 'title' ) ); |
| 29 | } ); |
| 30 | } |
| 31 | |
| 32 | if ( m_filter.data( 'filter-by' ) ) { |
| 33 | items = _.filter( items, function( item ) { |
| 34 | return item[ m_filter.data( 'filter-by' ) ] === m_filter.data( 'filter-value' ); |
| 35 | } ); |
| 36 | } |
| 37 | |
| 38 | if ( m_search.length ) { |
| 39 | items = _.filter( items, function( item ) { |
| 40 | var search_text = |
| 41 | item.name + |
| 42 | ' ' + |
| 43 | item.description + |
| 44 | ' ' + |
| 45 | item.long_description + |
| 46 | ' ' + |
| 47 | item.search_terms + |
| 48 | ' ' + |
| 49 | item.module_tags; |
| 50 | return -1 !== search_text.toLowerCase().indexOf( m_search ); |
| 51 | } ); |
| 52 | } |
| 53 | |
| 54 | if ( m_sort.data( 'sort-by' ) ) { |
| 55 | items = _.sortBy( items, m_sort.data( 'sort-by' ) ); |
| 56 | if ( 'reverse' === m_sort.data( 'sort-order' ) ) { |
| 57 | items.reverse(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Sort unavailable modules to the end if the user is running in local mode. |
| 62 | groups = _.groupBy( items, 'available' ); |
| 63 | if ( _.has( groups, 'false' ) ) { |
| 64 | items = [].concat( groups[ true ], groups[ false ] ); |
| 65 | } |
| 66 | |
| 67 | // Now shove it back in. |
| 68 | this.set( 'items', items ); |
| 69 | |
| 70 | return this; |
| 71 | }, |
| 72 | |
| 73 | initialize: function() { |
| 74 | var items = this.get( 'items' ); |
| 75 | this.set( 'raw', items ); |
| 76 | }, |
| 77 | } ); |
| 78 | |
| 79 | return models; |
| 80 | } )( this, jQuery, _, Backbone ); |
| 81 |