Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from chosen library to select2 and remove deprecated asset enqueuing strategy #1645

Merged
merged 12 commits into from
Dec 13, 2018
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function( grunt ) {
fonts: 'assets/font',
images: 'assets/images',
js: 'assets/js',
select2: 'assets/js/select2',
blocks: 'assets/blocks',
build: 'tmp/build',
svn: 'tmp/release-svn'
Expand Down Expand Up @@ -104,6 +105,15 @@ module.exports = function( grunt ) {
'!mixtape.json'
],
dest: '<%= dirs.build %>/'
},
select2: {
expand: true,
flatten: true,
src: [
'node_modules/select2/dist/js/select2.full.min.js',
'node_modules/select2/dist/css/select2.min.css'
],
dest: '<%= dirs.select2 %>/'
}
},

Expand Down Expand Up @@ -277,6 +287,8 @@ module.exports = function( grunt ) {
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown');
grunt.loadNpmTasks( 'grunt-zip' );

grunt.registerTask( 'update-assets', [ 'copy:select2' ] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this task need to be run manually? Should we document it somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does need to be called manually. It will probably happen when we are prepping the release PR (not packaging/deploying it as it will be committed). I'll add it to our docs when we merge.


grunt.registerTask( 'check-mixtape', 'Checking for WPJM\'s REST library (Mixtape) and building if necessary', function() {
if ( ! grunt.file.exists( 'lib/wpjm_rest/class-wp-job-manager-rest-bootstrap.php' ) ) {
grunt.task.run( [ 'build-mixtape' ] );
Expand Down
18 changes: 11 additions & 7 deletions assets/js/ajax-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ jQuery( document ).ready( function ( $ ) {
var target = $( this ).closest( 'div.job_listings' );
var form = $( this ).closest( 'form' );

form.find( ':input[name="search_keywords"], :input[name="search_location"], .job-manager-filter' ).not(':input[type="hidden"]').val( '' ).trigger( 'chosen:updated' );
form.find( ':input[name^="search_categories"]' ).not(':input[type="hidden"]').val( '' ).trigger( 'chosen:updated' );
form.find( ':input[name="search_keywords"], :input[name="search_location"], .job-manager-filter' ).not(':input[type="hidden"]').val( '' ).trigger( 'change.select2' );
form.find( ':input[name^="search_categories"]' ).not(':input[type="hidden"]').val( '' ).trigger( 'change.select2' );
$( ':input[name="filter_job_type[]"]', form ).not(':input[type="hidden"]').attr( 'checked', 'checked' );

target.triggerHandler( 'reset' );
Expand Down Expand Up @@ -254,11 +254,15 @@ jQuery( document ).ready( function ( $ ) {
return false;
} );

if ( $.isFunction( $.fn.chosen ) ) {
if ( job_manager_ajax_filters.is_rtl === 1 ) {
$( 'select[name^="search_categories"]' ).addClass( 'chosen-rtl' );
if ( $.isFunction( $.fn.select2 ) ) {
var select2_args = {
allowClear: true,
minimumResultsForSearch: 10
};
if ( 1 === parseInt( job_manager_ajax_filters.is_rtl, 10 ) ) {
select2_args.dir = 'rtl';
}
$( 'select[name^="search_categories"]' ).chosen({ search_contains: true });
$( 'select[name^="search_categories"]' ).select2( select2_args );
}

var $supports_html5_history = false;
Expand Down Expand Up @@ -290,7 +294,7 @@ jQuery( document ).ready( function ( $ ) {
if ( state.id && 'job_manager_state' === state.id && index === state.index ) {
inital_page = state.page;
form.deserialize( state.data );
form.find( ':input[name^="search_categories"]' ).not(':input[type="hidden"]').trigger( 'chosen:updated' );
form.find( ':input[name^="search_categories"]' ).not(':input[type="hidden"]').trigger( 'change.select2' );
}
}

Expand Down
2 changes: 1 addition & 1 deletion assets/js/ajax-filters.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions assets/js/job-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jQuery(document).ready(function($) {
return;
}

$details.trigger('visible');

// If max(33% height, 200px) of the application details aren't shown, scroll.
var minimum_details_threshold = Math.max( Math.min( $details.outerHeight(), 200 ), $details.outerHeight() * .33 );
var details_visible_threshold = $details.offset().top + minimum_details_threshold;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/job-application.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/js/multiselect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global job_manager_chosen_multiselect_args */
/* global job_manager_select2_multiselect_args */
jQuery(function(){
jQuery( '.job-manager-multiselect' ).chosen( job_manager_chosen_multiselect_args );
jQuery( '.job-manager-multiselect' ).select2( job_manager_select2_multiselect_args );
});
2 changes: 1 addition & 1 deletion assets/js/multiselect.min.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jQuery(function(){jQuery(".job-manager-multiselect").chosen(job_manager_chosen_multiselect_args)});
jQuery(function(){jQuery(".job-manager-multiselect").select2(job_manager_select2_multiselect_args)});
1 change: 1 addition & 0 deletions assets/js/select2/select2.full.min.js

Large diffs are not rendered by default.

Loading