From e1d6d16d47e88f1206dd1a228cbd10fc972b6d34 Mon Sep 17 00:00:00 2001 From: Mike Hins Date: Fri, 13 Nov 2015 11:21:50 -0500 Subject: [PATCH 1/3] Add diacritic support to filter and update the documentation page --- dist/js/bootstrap-multiselect.js | 458 +- index.html | 7399 ++++++++++++++++-------------- 2 files changed, 4115 insertions(+), 3742 deletions(-) diff --git a/dist/js/bootstrap-multiselect.js b/dist/js/bootstrap-multiselect.js index a7c71eab..6b67251f 100644 --- a/dist/js/bootstrap-multiselect.js +++ b/dist/js/bootstrap-multiselect.js @@ -1,23 +1,23 @@ /** * Bootstrap Multiselect (https://github.com/davidstutz/bootstrap-multiselect) - * + * * Apache License, Version 2.0: * Copyright (c) 2012 - 2015 David Stutz - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. - * + * * BSD 3-Clause License: * Copyright (c) 2012 - 2015 David Stutz * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright notice, @@ -28,7 +28,7 @@ * - Neither the name of David Stutz nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -48,7 +48,7 @@ ko.bindingHandlers.multiselect = { after: ['options', 'value', 'selectedOptions', 'enable', 'disable'], - init: function(element, valueAccessor, allBindings, viewModel, bindingContext) { + init: function (element, valueAccessor, allBindings, viewModel, bindingContext) { var $element = $(element); var config = ko.toJS(valueAccessor()); @@ -58,9 +58,9 @@ var options = allBindings.get('options'); if (ko.isObservable(options)) { ko.computed({ - read: function() { + read: function () { options(); - setTimeout(function() { + setTimeout(function () { var ms = $element.data('multiselect'); if (ms) ms.updateOriginalOptions();//Not sure how beneficial this is. @@ -79,14 +79,14 @@ var value = allBindings.get('value'); if (ko.isObservable(value)) { ko.computed({ - read: function() { + read: function () { value(); - setTimeout(function() { + setTimeout(function () { $element.multiselect('refresh'); }, 1); }, disposeWhenNodeIsRemoved: element - }).extend({ rateLimit: 100, notifyWhenChangesStop: true }); + }).extend({rateLimit: 100, notifyWhenChangesStop: true}); } } @@ -96,14 +96,14 @@ var selectedOptions = allBindings.get('selectedOptions'); if (ko.isObservable(selectedOptions)) { ko.computed({ - read: function() { + read: function () { selectedOptions(); - setTimeout(function() { + setTimeout(function () { $element.multiselect('refresh'); }, 1); }, disposeWhenNodeIsRemoved: element - }).extend({ rateLimit: 100, notifyWhenChangesStop: true }); + }).extend({rateLimit: 100, notifyWhenChangesStop: true}); } } @@ -124,7 +124,7 @@ setEnabled(enable()); }, disposeWhenNodeIsRemoved: element - }).extend({ rateLimit: 100, notifyWhenChangesStop: true }); + }).extend({rateLimit: 100, notifyWhenChangesStop: true}); } else { setEnabled(enable); } @@ -138,18 +138,18 @@ setEnabled(!disable()); }, disposeWhenNodeIsRemoved: element - }).extend({ rateLimit: 100, notifyWhenChangesStop: true }); + }).extend({rateLimit: 100, notifyWhenChangesStop: true}); } else { setEnabled(!disable); } } - ko.utils.domNodeDisposal.addDisposeCallback(element, function() { + ko.utils.domNodeDisposal.addDisposeCallback(element, function () { $element.multiselect('destroy'); }); }, - update: function(element, valueAccessor, allBindings, viewModel, bindingContext) { + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { var $element = $(element); var config = ko.toJS(valueAccessor()); @@ -175,12 +175,12 @@ function Multiselect(select, options) { this.$select = $(select); - + // Placeholder via data attributes if (this.$select.attr("data-placeholder")) { options.nonSelectedText = this.$select.data("placeholder"); } - + this.options = this.mergeOptions($.extend({}, options, this.$select.data())); // Initialization. @@ -197,7 +197,7 @@ this.options.onDropdownShown = $.proxy(this.options.onDropdownShown, this); this.options.onDropdownHidden = $.proxy(this.options.onDropdownHidden, this); this.options.onInitialized = $.proxy(this.options.onInitialized, this); - + // Build select all if enabled. this.buildContainer(); this.buildButton(); @@ -212,7 +212,7 @@ if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) { this.disable(); } - + this.$select.hide().after(this.$container); this.options.onInitialized(this.$select, this.$container); } @@ -224,25 +224,25 @@ * Default text function will either print 'None selected' in case no * option is selected or a list of the selected options up to a length * of 3 selected options. - * + * * @param {jQuery} options * @param {jQuery} select * @returns {String} */ - buttonText: function(options, select) { - if (this.disabledText.length > 0 - && (this.disableIfEmpty || select.prop('disabled')) - && options.length == 0) { - + buttonText: function (options, select) { + if (this.disabledText.length > 0 + && (this.disableIfEmpty || select.prop('disabled')) + && options.length == 0) { + return this.disabledText; } else if (options.length === 0) { return this.nonSelectedText; } - else if (this.allSelectedText - && options.length === $('option', $(select)).length - && $('option', $(select)).length !== 1 - && this.multiple) { + else if (this.allSelectedText + && options.length === $('option', $(select)).length + && $('option', $(select)).length !== 1 + && this.multiple) { if (this.selectAllNumber) { return this.allSelectedText + ' (' + options.length + ')'; @@ -257,30 +257,30 @@ else { var selected = ''; var delimiter = this.delimiterText; - - options.each(function() { + + options.each(function () { var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text(); selected += label + delimiter; }); - + return selected.substr(0, selected.length - 2); } }, /** * Updates the title of the button similar to the buttonText function. - * + * * @param {jQuery} options * @param {jQuery} select * @returns {@exp;selected@call;substr} */ - buttonTitle: function(options, select) { + buttonTitle: function (options, select) { if (options.length === 0) { return this.nonSelectedText; } else { var selected = ''; var delimiter = this.delimiterText; - + options.each(function () { var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).text(); selected += label + delimiter; @@ -294,7 +294,7 @@ * @param {jQuery} element * @returns {String} */ - optionLabel: function(element){ + optionLabel: function (element) { return $(element).attr('label') || $(element).text(); }, /** @@ -303,18 +303,18 @@ * @param {jQuery} element * @returns {String} */ - optionClass: function(element) { + optionClass: function (element) { return $(element).attr('class') || ''; }, /** * Triggered on change of the multiselect. - * + * * Not triggered when selecting/deselecting options manually. - * + * * @param {jQuery} option * @param {Boolean} checked */ - onChange : function(option, checked) { + onChange: function (option, checked) { }, /** @@ -322,7 +322,7 @@ * * @param {jQuery} event */ - onDropdownShow: function(event) { + onDropdownShow: function (event) { }, /** @@ -330,30 +330,30 @@ * * @param {jQuery} event */ - onDropdownHide: function(event) { + onDropdownHide: function (event) { }, /** * Triggered after the dropdown is shown. - * + * * @param {jQuery} event */ - onDropdownShown: function(event) { - + onDropdownShown: function (event) { + }, /** * Triggered after the dropdown is hidden. - * + * * @param {jQuery} event */ - onDropdownHidden: function(event) { - + onDropdownHidden: function (event) { + }, /** * Triggered on select all. */ - onSelectAll: function(checked) { - + onSelectAll: function (checked) { + }, /** * Triggered after initializing. @@ -361,7 +361,7 @@ * @param {jQuery} $select * @param {jQuery} $container */ - onInitialized: function($select, $container) { + onInitialized: function ($select, $container) { }, enableHTML: false, @@ -385,6 +385,7 @@ selectAllJustVisible: true, enableFiltering: false, enableCaseInsensitiveFiltering: false, + enableReplaceDiacritics: true, enableFullValueFiltering: false, enableClickableOptGroups: false, enableCollapsibelOptGroups: false, @@ -416,7 +417,7 @@ /** * Builds the container of the multiselect. */ - buildContainer: function() { + buildContainer: function () { this.$container = $(this.options.buttonContainer); this.$container.on('show.bs.dropdown', this.options.onDropdownShow); this.$container.on('hide.bs.dropdown', this.options.onDropdownHide); @@ -427,7 +428,7 @@ /** * Builds the button of the multiselect. */ - buildButton: function() { + buildButton: function () { this.$button = $(this.options.templates.button).addClass(this.options.buttonClass); if (this.$select.attr('class') && this.options.inheritClass) { this.$button.addClass(this.$select.attr('class')); @@ -443,9 +444,9 @@ // Manually add button width if set. if (this.options.buttonWidth && this.options.buttonWidth !== 'auto') { this.$button.css({ - 'width' : this.options.buttonWidth, - 'overflow' : 'hidden', - 'text-overflow' : 'ellipsis' + 'width': this.options.buttonWidth, + 'overflow': 'hidden', + 'text-overflow': 'ellipsis' }); this.$container.css({ 'width': this.options.buttonWidth @@ -464,7 +465,7 @@ /** * Builds the ul representing the dropdown menu. */ - buildDropdown: function() { + buildDropdown: function () { // Build ul. this.$ul = $(this.options.templates.ul); @@ -482,12 +483,12 @@ 'overflow-x': 'hidden' }); } - + if (this.options.dropUp) { - - var height = Math.min(this.options.maxHeight, $('option[data-role!="divider"]', this.$select).length*26 + $('option[data-role="divider"]', this.$select).length*19 + (this.options.includeSelectAllOption ? 26 : 0) + (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering ? 44 : 0)); + + var height = Math.min(this.options.maxHeight, $('option[data-role!="divider"]', this.$select).length * 26 + $('option[data-role="divider"]', this.$select).length * 19 + (this.options.includeSelectAllOption ? 26 : 0) + (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering ? 44 : 0)); var moveCalc = height + 34; - + this.$ul.css({ 'max-height': height + 'px', 'overflow-y': 'auto', @@ -495,24 +496,24 @@ 'margin-top': "-" + moveCalc + 'px' }); } - + this.$container.append(this.$ul); }, /** * Build the dropdown options and binds all nessecary events. - * + * * Uses createDivider and createOptionValue to create the necessary options. */ - buildDropdownOptions: function() { + buildDropdownOptions: function () { - this.$select.children().each($.proxy(function(index, element) { + this.$select.children().each($.proxy(function (index, element) { var $element = $(element); // Support optgroups and options without a group simultaneously. var tag = $element.prop('tagName') .toLowerCase(); - + if ($element.prop('value') === this.options.selectAllValue) { return; } @@ -535,7 +536,7 @@ }, this)); // Bind the change event on the dropdown elements. - $('li input', this.$ul).on('change', $.proxy(function(event) { + $('li input', this.$ul).on('change', $.proxy(function (event) { var $target = $(event.target); var checked = $target.prop('checked') || false; @@ -597,7 +598,7 @@ // Unselect option. $option.prop('selected', false); } - + // To prevent select all from firing onChange: #575 this.options.onChange($option, checked); } @@ -607,25 +608,25 @@ this.updateButtonText(); this.updateSelectAll(); - if(this.options.preventInputChangeEvent) { + if (this.options.preventInputChangeEvent) { return false; } }, this)); - $('li a', this.$ul).on('mousedown', function(e) { + $('li a', this.$ul).on('mousedown', function (e) { if (e.shiftKey) { // Prevent selecting text by Shift+click return false; } }); - - $('li a', this.$ul).on('touchstart click', $.proxy(function(event) { + + $('li a', this.$ul).on('touchstart click', $.proxy(function (event) { event.stopPropagation(); var $target = $(event.target); - + if (event.shiftKey && this.options.multiple) { - if($target.is("label")){ // Handles checkbox selection manually (see https://github.com/davidstutz/bootstrap-multiselect/issues/431) + if ($target.is("label")) { // Handles checkbox selection manually (see https://github.com/davidstutz/bootstrap-multiselect/issues/431) event.preventDefault(); $target = $target.find("input"); $target.prop("checked", !$target.prop("checked")); @@ -635,41 +636,41 @@ if (this.lastToggledInput !== null && this.lastToggledInput !== $target) { // Make sure we actually have a range var from = $target.closest("li").index(); var to = this.lastToggledInput.closest("li").index(); - + if (from > to) { // Swap the indices var tmp = to; to = from; from = tmp; } - + // Make sure we grab all elements since slice excludes the last index ++to; - + // Change the checkboxes and underlying options var range = this.$ul.find("li").slice(from, to).find("input"); - + range.prop('checked', checked); - + if (this.options.selectedClass) { range.closest('li') .toggleClass(this.options.selectedClass, checked); } - + for (var i = 0, j = range.length; i < j; i++) { var $checkbox = $(range[i]); var $option = this.getOptionByValue($checkbox.val()); $option.prop('selected', checked); - } + } } - + // Trigger the select "change" event $target.trigger("change"); } - + // Remembers last clicked option - if($target.is("input") && !$target.closest("li").is(".multiselect-item")){ + if ($target.is("input") && !$target.closest("li").is(".multiselect-item")) { this.lastToggledInput = $target; } @@ -677,7 +678,7 @@ }, this)); // Keyboard support. - this.$container.off('keydown.multiselect').on('keydown.multiselect', $.proxy(function(event) { + this.$container.off('keydown.multiselect').on('keydown.multiselect', $.proxy(function (event) { if ($('input[type="text"]', this.$container).is(':focus')) { return; } @@ -721,8 +722,8 @@ } }, this)); - if(this.options.enableClickableOptGroups && this.options.multiple) { - $('li.multiselect-group', this.$ul).on('click', $.proxy(function(event) { + if (this.options.enableClickableOptGroups && this.options.multiple) { + $('li.multiselect-group', this.$ul).on('click', $.proxy(function (event) { event.stopPropagation(); console.log('test'); var group = $(event.target).parent(); @@ -735,8 +736,8 @@ var allChecked = true; var optionInputs = $visibleOptions.find('input'); var values = []; - - optionInputs.each(function() { + + optionInputs.each(function () { allChecked = allChecked && $(this).prop('checked'); values.push($(this).val()); }); @@ -747,83 +748,83 @@ else { this.deselect(values, false); } - + this.options.onChange(optionInputs, !allChecked); - }, this)); + }, this)); } if (this.options.enableCollapsibleOptGroups && this.options.multiple) { $("li.multiselect-group input", this.$ul).off(); - $("li.multiselect-group", this.$ul).siblings().not("li.multiselect-group, li.multiselect-all", this.$ul).each( function () { + $("li.multiselect-group", this.$ul).siblings().not("li.multiselect-group, li.multiselect-all", this.$ul).each(function () { $(this).toggleClass('hidden', true); }); - - $("li.multiselect-group", this.$ul).on("click", $.proxy(function(group) { + + $("li.multiselect-group", this.$ul).on("click", $.proxy(function (group) { group.stopPropagation(); }, this)); - - $("li.multiselect-group > a > b", this.$ul).on("click", $.proxy(function(t) { + + $("li.multiselect-group > a > b", this.$ul).on("click", $.proxy(function (t) { t.stopPropagation(); var n = $(t.target).closest('li'); var r = n.nextUntil("li.multiselect-group"); var i = true; - - r.each(function() { + + r.each(function () { i = i && $(this).hasClass('hidden'); }); - + r.toggleClass('hidden', !i); }, this)); - - $("li.multiselect-group > a > input", this.$ul).on("change", $.proxy(function(t) { + + $("li.multiselect-group > a > input", this.$ul).on("change", $.proxy(function (t) { t.stopPropagation(); var n = $(t.target).closest('li'); var r = n.nextUntil("li.multiselect-group", ':not(.disabled)'); var s = r.find("input"); - + var i = true; - s.each(function() { + s.each(function () { i = i && $(this).prop("checked"); }); - + s.prop("checked", !i).trigger("change"); }, this)); - + // Set the initial selection state of the groups. - $('li.multiselect-group', this.$ul).each(function() { + $('li.multiselect-group', this.$ul).each(function () { var r = $(this).nextUntil("li.multiselect-group", ':not(.disabled)'); var s = r.find("input"); - + var i = true; - s.each(function() { + s.each(function () { i = i && $(this).prop("checked"); }); - + $(this).find('input').prop("checked", i); }); - + // Update the group checkbox based on new selections among the // corresponding children. - $("li input", this.$ul).on("change", $.proxy(function(t) { + $("li input", this.$ul).on("change", $.proxy(function (t) { t.stopPropagation(); var n = $(t.target).closest('li'); var r1 = n.prevUntil("li.multiselect-group", ':not(.disabled)'); var r2 = n.nextUntil("li.multiselect-group", ':not(.disabled)'); var s1 = r1.find("input"); var s2 = r2.find("input"); - + var i = $(t.target).prop('checked'); - s1.each(function() { + s1.each(function () { i = i && $(this).prop("checked"); }); - - s2.each(function() { + + s2.each(function () { i = i && $(this).prop("checked"); }); - + n.prevAll('.multiselect-group').find('input').prop('checked', i); }, this)); - + $("li.multiselect-all", this.$ul).css('background', '#f3f3f3').css('border-bottom', '1px solid #eaeaea'); $("li.multiselect-group > a, li.multiselect-all > a > label.checkbox", this.$ul).css('padding', '3px 20px 3px 35px'); $("li.multiselect-group > a > input", this.$ul).css('margin', '4px 0px 5px -20px'); @@ -835,7 +836,7 @@ * * @param {jQuery} element */ - createOptionValue: function(element) { + createOptionValue: function (element) { var $element = $(element); if ($element.is(':selected')) { $element.prop('selected', true); @@ -858,7 +859,7 @@ else { $label.text(" " + label); } - + var $checkbox = $('').attr('type', inputType); if (this.options.checkboxName) { @@ -901,7 +902,7 @@ * * @param {jQuery} element */ - createDivider: function(element) { + createDivider: function (element) { var $divider = $(this.options.templates.divider); this.$ul.append($divider); }, @@ -911,7 +912,7 @@ * * @param {jQuery} group */ - createOptgroup: function(group) { + createOptgroup: function (group) { if (this.options.enableCollapsibleOptGroups && this.options.multiple) { var label = $(group).attr("label"); var value = $(group).attr("value"); @@ -924,7 +925,7 @@ if ($(group).is(":disabled")) { r.addClass("disabled") } - $("option", group).each($.proxy(function($, group) { + $("option", group).each($.proxy(function ($, group) { this.createOptionValue(group) }, this)) } @@ -952,7 +953,7 @@ } // Add the options of the group. - $('option', group).each($.proxy(function(index, element) { + $('option', group).each($.proxy(function (index, element) { this.createOptionValue(element); }, this)); } @@ -960,18 +961,18 @@ /** * Build the select all. - * + * * Checks if a select all has already been created. */ - buildSelectAll: function() { + buildSelectAll: function () { if (typeof this.options.selectAllValue === 'number') { this.options.selectAllValue = this.options.selectAllValue.toString(); } - + var alreadyHasSelectAll = this.hasSelectAll(); if (!alreadyHasSelectAll && this.options.includeSelectAllOption && this.options.multiple - && $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) { + && $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) { // Check whether to add a divider after the select all. if (this.options.includeSelectAllDivider) { @@ -980,21 +981,21 @@ var $li = $(this.options.templates.li); $('label', $li).addClass("checkbox"); - + if (this.options.enableHTML) { $('label', $li).html(" " + this.options.selectAllText); } else { $('label', $li).text(" " + this.options.selectAllText); } - + if (this.options.selectAllName) { $('label', $li).prepend(''); } else { $('label', $li).prepend(''); } - + var $checkbox = $('input', $li); $checkbox.val(this.options.selectAllValue); @@ -1011,7 +1012,7 @@ /** * Builds the filter. */ - buildFilter: function() { + buildFilter: function () { // Build filter if filtering OR case insensitive filtering is enabled and the number of options exceeds (or equals) enableFilterLength. if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) { @@ -1021,11 +1022,11 @@ this.$filter = $(this.options.templates.filter); $('input', this.$filter).attr('placeholder', this.options.filterPlaceholder); - + // Adds optional filter clear button - if(this.options.includeFilterClearBtn){ + if (this.options.includeFilterClearBtn) { var clearBtn = $(this.options.templates.filterClearBtn); - clearBtn.on('click', $.proxy(function(event){ + clearBtn.on('click', $.proxy(function (event) { clearTimeout(this.searchTimeout); this.$filter.find('.multiselect-search').val(''); $('li', this.$ul).show().removeClass("filter-hidden"); @@ -1033,27 +1034,27 @@ }, this)); this.$filter.find('.input-group').append(clearBtn); } - + this.$ul.prepend(this.$filter); - this.$filter.val(this.query).on('click', function(event) { + this.$filter.val(this.query).on('click', function (event) { event.stopPropagation(); - }).on('input keydown', $.proxy(function(event) { + }).on('input keydown', $.proxy(function (event) { // Cancel enter key default behaviour if (event.which === 13) { - event.preventDefault(); + event.preventDefault(); } - + // This is useful to catch "keydown" events after the browser has updated the control. clearTimeout(this.searchTimeout); - this.searchTimeout = this.asyncFunction($.proxy(function() { + this.searchTimeout = this.asyncFunction($.proxy(function () { if (this.query !== event.target.value) { this.query = event.target.value; var currentGroup, currentGroupVisible; - $.each($('li', this.$ul), $.proxy(function(index, element) { + $.each($('li', this.$ul), $.proxy(function (index, element) { var value = $('input', element).length > 0 ? $('input', element).val() : ""; var text = $('label', element).text(); @@ -1079,6 +1080,11 @@ this.query = this.query.toLowerCase(); } + if (this.options.enableReplaceDiacritics) { + filterCandidate = this.replaceDiacritics(filterCandidate); + this.query = this.replaceDiacritics(this.query); + } + if (this.options.enableFullValueFiltering && this.options.filterBehavior !== 'both') { var valueToMatch = filterCandidate.trim().substring(0, this.query.length); if (this.query.indexOf(valueToMatch) > -1) { @@ -1091,7 +1097,7 @@ // Toggle current element (group or group item) according to showElement boolean. $(element).toggle(showElement).toggleClass('filter-hidden', !showElement); - + // Differentiate groups and group items. if ($(element).hasClass('multiselect-group')) { // Remember group status. @@ -1103,7 +1109,7 @@ if (showElement) { $(currentGroup).show().removeClass('filter-hidden'); } - + // Show all group items when group name satisfies filter. if (!showElement && currentGroupVisible) { $(element).show().removeClass('filter-hidden'); @@ -1120,10 +1126,32 @@ } }, + /** + * Replace diacritics (ă,ş,ţ etc) with their "normal" form + * + * @param s + * @returns string + */ + replaceDiacritics: function (s) { + var in_chrs = '¹²³áàâãäåaaaÀÁÂÃÄÅAAAÆccç©CCÇÐÐèéê?əëeeeeeÈÊË?EEEEE€gGiìíîïìiiiÌÍÎÏ?ÌIIIlLnnñNNÑòóôõöoooøÒÓÔÕÖOOOØŒr®Ršs?ߊS?ùúûüuuuuÙÚÛÜUUUUýÿÝŸžzzŽZZ', + out_chrs = '123aaaaaaaaaaaaaaaaaaacccccccddeeeeeeeeeeeeeeeeeeeeeggiiiiiiiiiiiiiiiiiillnnnnnnoooooooooooooooorrrsssssssuuuuuuuuuuuuuuuuyyyyzzzzzz', + chars_rgx = new RegExp('[' + in_chrs + ']', 'g'), + transl = {}, i, + lookup = function (m) { + return transl[m] || m; + }; + + for (i = 0; i < in_chrs.length; i++) { + transl[in_chrs[i]] = out_chrs[i]; + } + + return s.replace(chars_rgx, lookup); + }, + /** * Unbinds the whole plugin. */ - destroy: function() { + destroy: function () { this.$container.remove(); this.$select.show(); this.$select.data('multiselect', null); @@ -1134,7 +1162,7 @@ */ refresh: function () { var inputs = $.map($('li input', this.$ul), $); - + $('option', this.$select).each($.proxy(function (index, element) { var $elem = $(element); var value = $elem.val(); @@ -1181,15 +1209,15 @@ /** * Select all options of the given values. - * + * * If triggerOnChange is set to true, the on change event is triggered if * and only if one value is passed. - * + * * @param {Array} selectValues * @param {Boolean} triggerOnChange */ - select: function(selectValues, triggerOnChange) { - if(!$.isArray(selectValues)) { + select: function (selectValues, triggerOnChange) { + if (!$.isArray(selectValues)) { selectValues = [selectValues]; } @@ -1203,14 +1231,14 @@ var $option = this.getOptionByValue(value); var $checkbox = this.getInputByValue(value); - if($option === undefined || $checkbox === undefined) { + if ($option === undefined || $checkbox === undefined) { continue; } - + if (!this.options.multiple) { this.deselectAll(false); } - + if (this.options.selectedClass) { $checkbox.closest('li') .addClass(this.options.selectedClass); @@ -1218,7 +1246,7 @@ $checkbox.prop('checked', true); $option.prop('selected', true); - + if (triggerOnChange) { this.options.onChange($option, true); } @@ -1239,15 +1267,15 @@ /** * Deselects all options of the given values. - * + * * If triggerOnChange is set to true, the on change event is triggered, if * and only if one value is passed. - * + * * @param {Array} deselectValues * @param {Boolean} triggerOnChange */ - deselect: function(deselectValues, triggerOnChange) { - if(!$.isArray(deselectValues)) { + deselect: function (deselectValues, triggerOnChange) { + if (!$.isArray(deselectValues)) { deselectValues = [deselectValues]; } @@ -1261,7 +1289,7 @@ var $option = this.getOptionByValue(value); var $checkbox = this.getInputByValue(value); - if($option === undefined || $checkbox === undefined) { + if ($option === undefined || $checkbox === undefined) { continue; } @@ -1272,7 +1300,7 @@ $checkbox.prop('checked', false); $option.prop('selected', false); - + if (triggerOnChange) { this.options.onChange($option, false); } @@ -1281,7 +1309,7 @@ this.updateButtonText(); this.updateSelectAll(); }, - + /** * Selects all enabled & visible options. * @@ -1292,14 +1320,14 @@ */ selectAll: function (justVisible, triggerOnSelectAll) { justVisible = (this.options.enableCollapsibleOptGroups && this.options.multiple) ? false : justVisible; - + var justVisible = typeof justVisible === 'undefined' ? true : justVisible; var allCheckboxes = $("li input[type='checkbox']:enabled", this.$ul); var visibleCheckboxes = allCheckboxes.filter(":visible"); var allCheckboxesCount = allCheckboxes.length; var visibleCheckboxesCount = visibleCheckboxes.length; - - if(justVisible) { + + if (justVisible) { visibleCheckboxes.prop('checked', true); $("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").addClass(this.options.selectedClass); } @@ -1307,20 +1335,20 @@ allCheckboxes.prop('checked', true); $("li:not(.divider):not(.disabled)", this.$ul).addClass(this.options.selectedClass); } - + if (allCheckboxesCount === visibleCheckboxesCount || justVisible === false) { $("option:not([data-role='divider']):enabled", this.$select).prop('selected', true); } else { - var values = visibleCheckboxes.map(function() { + var values = visibleCheckboxes.map(function () { return $(this).val(); }).get(); - - $("option:enabled", this.$select).filter(function(index) { + + $("option:enabled", this.$select).filter(function (index) { return $.inArray($(this).val(), values) !== -1; }).prop('selected', true); } - + if (triggerOnSelectAll) { this.options.onSelectAll(); } @@ -1328,27 +1356,27 @@ /** * Deselects all options. - * + * * If justVisible is true or not specified, only visible options are deselected. - * + * * @param {Boolean} justVisible */ deselectAll: function (justVisible) { justVisible = (this.options.enableCollapsibleOptGroups && this.options.multiple) ? false : justVisible; justVisible = typeof justVisible === 'undefined' ? true : justVisible; - - if(justVisible) { + + if (justVisible) { var visibleCheckboxes = $("li input[type='checkbox']:not(:disabled)", this.$ul).filter(":visible"); visibleCheckboxes.prop('checked', false); - - var values = visibleCheckboxes.map(function() { + + var values = visibleCheckboxes.map(function () { return $(this).val(); }).get(); - - $("option:enabled", this.$select).filter(function(index) { + + $("option:enabled", this.$select).filter(function (index) { return $.inArray($(this).val(), values) !== -1; }).prop('selected', false); - + if (this.options.selectedClass) { $("li:not(.divider):not(.disabled)", this.$ul).filter(":visible").removeClass(this.options.selectedClass); } @@ -1356,7 +1384,7 @@ else { $("li input[type='checkbox']:enabled", this.$ul).prop('checked', false); $("option:enabled", this.$select).prop('selected', false); - + if (this.options.selectedClass) { $("li:not(.divider):not(.disabled)", this.$ul).removeClass(this.options.selectedClass); } @@ -1365,10 +1393,10 @@ /** * Rebuild the plugin. - * + * * Rebuilds the dropdown, the filter and the select all option. */ - rebuild: function() { + rebuild: function () { this.$ul.html(''); // Important to distinguish between radios and checkboxes. @@ -1380,14 +1408,14 @@ this.updateButtonText(); this.updateSelectAll(true); - + if (this.options.disableIfEmpty && $('option', this.$select).length <= 0) { this.disable(); } else { this.enable(); } - + if (this.options.dropRight) { this.$ul.addClass('pull-right'); } @@ -1396,23 +1424,23 @@ /** * The provided data will be used to build the dropdown. */ - dataprovider: function(dataprovider) { - + dataprovider: function (dataprovider) { + var groupCounter = 0; var $select = this.$select.empty(); - + $.each(dataprovider, function (index, option) { var $tag; - + if ($.isArray(option.children)) { // create optiongroup tag groupCounter++; - + $tag = $('').attr({ label: option.label || 'Group ' + groupCounter, disabled: !!option.disabled }); - - forEach(option.children, function(subOption) { // add children option tags + + forEach(option.children, function (subOption) { // add children option tags $tag.append($('