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

Determine select2 version from ACF instead of guessing from ACF version #105

Merged
merged 1 commit into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/scraper/scraper.taxonomy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Scraper.prototype.scrape = function(fields){

if( field.$el.find('.acf-taxonomy-field[data-type="multi_select"]').length > 0 ){

var select2Target = (helper.acf_version >= 5.6)?'select':'input';
var select2Target = (acf.select2.version >= 4)?'select':'input';

terms = _.pluck(
field.$el.find('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target )
Expand Down
2 changes: 1 addition & 1 deletion js/yoast-acf-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ Scraper.prototype.scrape = function(fields){

if( field.$el.find('.acf-taxonomy-field[data-type="multi_select"]').length > 0 ){

var select2Target = (helper.acf_version >= 5.6)?'select':'input';
var select2Target = (acf.select2.version >= 4)?'select':'input';
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, it is nicer to have a global minimalRequiredSelect2Version variable that contains the number 4, that is easier to read than only using a magical 4 value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm...The things is that

  1. This isn't a minimal required version, but rather a switch to work with any select2 version.
  2. The number is compared to acf.select2.version, so isn't it pretty obvious that this is the select2 version?


terms = _.pluck(
field.$el.find('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target )
Expand Down
8 changes: 4 additions & 4 deletions tests/js/system/tests/acf5/relational.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ module.exports = {

browser.execute(
function() {
return parseFloat(YoastACFAnalysisConfig.acfVersion, 10);
return parseFloat(acf.select2.version, 10);
},
[],
function( result ){
var acfVersion = result.value;
var select2Version = result.value;
var inputSelector, optionSelector, choiceSelector;

if( acfVersion >= 5.6 ){
if( select2Version >= 4 ){
inputSelector = '.acf-taxonomy-field[data-type="multi_select"][data-taxonomy="category"] .select2-search__field ';
optionSelector = '.select2-results__option--highlighted';
choiceSelector = '.acf-taxonomy-field .select2-selection__choice';
Expand All @@ -64,7 +64,7 @@ module.exports = {
browser.execute(
function() {

var select2Target = (parseFloat(YoastACFAnalysisConfig.acfVersion, 10) >= 5.6)?'select':'input';
var select2Target = (parseFloat(acf.select2.version, 10) >= 4)?'select':'input';

return jQuery('.acf-taxonomy-field[data-type="multi_select"] ' + select2Target).select2('data')[0].text
},
Expand Down