mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 02:01:18 +03:00
Add 5ftf plugin from https://github.com/coreymckrill/5ftf
This commit is contained in:
parent
1db9ec9203
commit
697a4b2329
12 changed files with 943 additions and 0 deletions
65
plugins/wporg-5ftf/assets/js/front-end.js
Executable file
65
plugins/wporg-5ftf/assets/js/front-end.js
Executable file
|
@ -0,0 +1,65 @@
|
|||
window.wp = window.wp || {};
|
||||
|
||||
jQuery( function( $ ) {
|
||||
'use strict';
|
||||
|
||||
var allCompanies = window.fiveFutureCompanies || {},
|
||||
sortOrder = 'ascending';
|
||||
|
||||
var app = window.wp.FiveForTheFuture = {
|
||||
// jsdoc
|
||||
init: function() {
|
||||
app.renderTemplate( allCompanies );
|
||||
|
||||
$( '#5ftf-search' ).keyup( app.searchCompanies );
|
||||
// works on keyup but not change. isn't change better?
|
||||
$( '.fftf-sorting-indicator' ).click( app.orderCompanies );
|
||||
},
|
||||
|
||||
//
|
||||
renderTemplate: function( companies ) {
|
||||
var $container = $( '#5ftf-companies-body' ),
|
||||
template = wp.template( '5ftf-companies' );
|
||||
|
||||
$container.html( template( companies ) );
|
||||
},
|
||||
|
||||
//
|
||||
searchCompanies: function( event ) {
|
||||
var matches = $.extend( true, [], allCompanies ),
|
||||
query = $( event.target ).val().toLowerCase();
|
||||
|
||||
matches = _.filter( matches, function( company ) {
|
||||
return -1 !== company.name.toLowerCase().indexOf( query );
|
||||
} );
|
||||
|
||||
app.renderTemplate( matches );
|
||||
},
|
||||
|
||||
//
|
||||
orderCompanies: function( event ) {
|
||||
var $activeSortButton = $( event.target ),
|
||||
$activeSortColumn = $activeSortButton.parent( 'th' ),
|
||||
$sortColumns = $( '.fftf-sorting-indicator' );
|
||||
|
||||
allCompanies = _.sortBy( allCompanies, $activeSortButton.data( 'field' ) );
|
||||
|
||||
$sortColumns.removeClass( 'fftf-sorted-ascending' );
|
||||
$sortColumns.removeClass( 'fftf-sorted-descending' );
|
||||
|
||||
if ( 'ascending' === sortOrder ) {
|
||||
sortOrder = 'descending';
|
||||
allCompanies = allCompanies.reverse();
|
||||
|
||||
$activeSortColumn.addClass( 'fftf-sorted-descending' );
|
||||
} else {
|
||||
sortOrder = 'ascending';
|
||||
$activeSortColumn.addClass( 'fftf-sorted-ascending' );
|
||||
}
|
||||
|
||||
app.renderTemplate( allCompanies );
|
||||
}
|
||||
};
|
||||
|
||||
app.init();
|
||||
} );
|
Loading…
Add table
Add a link
Reference in a new issue