Skip to content

Commit

Permalink
Add logic to set data-abs-locale-* options correctly due to how jQuer…
Browse files Browse the repository at this point in the history
…y handles capitalization.
  • Loading branch information
truckingsim committed May 15, 2015
1 parent 4077502 commit 9d889a8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/js/classes/AjaxBootstrapSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ var AjaxBootstrapSelect = function (element, options) {
this.log(this.LOG_DEBUG, 'Merged in the data attribute options: ', dataOptions, this.options);
}

// The data() call on the attribute returns the first letter capitalized after the dash and ignores all other casing.
// Local relies on accurate casing so handle this:
if(this.options.locale){
var localeKeys = Object.keys(this.options.locale);
var possibleOptions = ['currentlySelected', 'emptyTitle', 'errorText', 'searchPlaceholder', 'statusInitialized', 'statusNoResults', 'statusSearching'];
localeKeys.forEach(function(testLocale){
if(testLocale && !/[A-Z]/.test(testLocale)){
var matchedOption = false;
possibleOptions.forEach(function(item){
if(matchedOption) { return; }
if(/[A-Z]/.test(item)){
matchedOption = item.toLowerCase() === testLocale.toLowerCase() ? item : false;
}
});
if(matchedOption){
plugin.options.locale[matchedOption] = plugin.options.locale[testLocale];
delete plugin.options.locale[testLocale];
}
}
});
}

/**
* Reference to the selectpicker instance.
* @type {Selectpicker}
Expand Down

0 comments on commit 9d889a8

Please sign in to comment.