From 9d889a8cc496c49da92312d59df92820adac0b51 Mon Sep 17 00:00:00 2001 From: Adam Heim Date: Fri, 15 May 2015 17:49:57 -0400 Subject: [PATCH] Add logic to set data-abs-locale-* options correctly due to how jQuery handles capitalization. --- src/js/classes/AjaxBootstrapSelect.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/js/classes/AjaxBootstrapSelect.js b/src/js/classes/AjaxBootstrapSelect.js index 34a104c..73c8993 100644 --- a/src/js/classes/AjaxBootstrapSelect.js +++ b/src/js/classes/AjaxBootstrapSelect.js @@ -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}