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