GPQAPP
893 строки · 32.5 Кб
1/*
2* Bootstrap Duallistbox - v4.0.2
3* A responsive dual listbox widget optimized for Twitter Bootstrap. It works on all modern browsers and on touch devices.
4* http://www.virtuosoft.eu/code/bootstrap-duallistbox/
5*
6* Made by István Ujj-Mészáros
7* Under Apache License v2.0 License
8*/
9(function(factory) {10if (typeof define === 'function' && define.amd) {11define(['jquery'], factory);12} else if (typeof module === 'object' && module.exports) {13module.exports = function(root, jQuery) {14if (jQuery === undefined) {15if (typeof window !== 'undefined') {16jQuery = require('jquery');17}18else {19jQuery = require('jquery')(root);20}21}22factory(jQuery);23return jQuery;24};25} else {26factory(jQuery);27}28}(function($) {29// Create the defaults once30var pluginName = 'bootstrapDualListbox',31defaults = {32filterTextClear: 'show all',33filterPlaceHolder: 'Filter',34moveSelectedLabel: 'Move selected',35moveAllLabel: 'Move all',36removeSelectedLabel: 'Remove selected',37removeAllLabel: 'Remove all',38moveOnSelect: true, // true/false (forced true on androids, see the comment later)39moveOnDoubleClick: true, // true/false (forced false on androids, cause moveOnSelect is forced to true)40preserveSelectionOnMove: false, // 'all' / 'moved' / false41selectedListLabel: false, // 'string', false42nonSelectedListLabel: false, // 'string', false43helperSelectNamePostfix: '_helper', // 'string_of_postfix' / false44selectorMinimalHeight: 100,45showFilterInputs: true, // whether to show filter inputs46nonSelectedFilter: '', // string, filter the non selected options47selectedFilter: '', // string, filter the selected options48infoText: 'Showing all {0}', // text when all options are visible / false for no info text49infoTextFiltered: '<span class="badge badge-warning">Filtered</span> {0} from {1}', // when not all of the options are visible due to the filter50infoTextEmpty: 'Empty list', // when there are no options present in the list51filterOnValues: false, // filter by selector's values, boolean52sortByInputOrder: false,53eventMoveOverride: false, // boolean, allows user to unbind default event behaviour and run their own instead54eventMoveAllOverride: false, // boolean, allows user to unbind default event behaviour and run their own instead55eventRemoveOverride: false, // boolean, allows user to unbind default event behaviour and run their own instead56eventRemoveAllOverride: false, // boolean, allows user to unbind default event behaviour and run their own instead57btnClass: 'btn-outline-secondary', // sets the button style class for all the buttons58btnMoveText: '>', // string, sets the text for the "Move" button59btnRemoveText: '<', // string, sets the text for the "Remove" button60btnMoveAllText: '>>', // string, sets the text for the "Move All" button61btnRemoveAllText: '<<' // string, sets the text for the "Remove All" button62},63// Selections are invisible on android if the containing select is styled with CSS64// http://code.google.com/p/android/issues/detail?id=1692265isBuggyAndroid = /android/i.test(navigator.userAgent.toLowerCase());66
67// The actual plugin constructor68function BootstrapDualListbox(element, options) {69this.element = $(element);70// jQuery has an extend method which merges the contents of two or71// more objects, storing the result in the first object. The first object72// is generally empty as we don't want to alter the default options for73// future instances of the plugin74this.settings = $.extend({}, defaults, options);75this._defaults = defaults;76this._name = pluginName;77this.init();78}79
80function triggerChangeEvent(dualListbox) {81dualListbox.element.trigger('change');82}83
84function updateSelectionStates(dualListbox) {85dualListbox.element.find('option').each(function(index, item) {86var $item = $(item);87if (typeof($item.data('original-index')) === 'undefined') {88$item.data('original-index', dualListbox.elementCount++);89}90if (typeof($item.data('_selected')) === 'undefined') {91$item.data('_selected', false);92}93});94}95
96function changeSelectionState(dualListbox, original_index, selected) {97dualListbox.element.find('option').each(function(index, item) {98var $item = $(item);99if ($item.data('original-index') === original_index) {100$item.prop('selected', selected);101if(selected){102$item.attr('data-sortindex', dualListbox.sortIndex);103dualListbox.sortIndex++;104} else {105$item.removeAttr('data-sortindex');106}107}108});109}110
111function formatString(s, args) {112console.log(s, args);113return s.replace(/{(\d+)}/g, function(match, number) {114return typeof args[number] !== 'undefined' ? args[number] : match;115});116}117
118function refreshInfo(dualListbox) {119if (!dualListbox.settings.infoText) {120return;121}122
123var visible1 = dualListbox.elements.select1.find('option').length,124visible2 = dualListbox.elements.select2.find('option').length,125all1 = dualListbox.element.find('option').length - dualListbox.selectedElements,126all2 = dualListbox.selectedElements,127content = '';128
129if (all1 === 0) {130content = dualListbox.settings.infoTextEmpty;131} else if (visible1 === all1) {132content = formatString(dualListbox.settings.infoText, [visible1, all1]);133} else {134content = formatString(dualListbox.settings.infoTextFiltered, [visible1, all1]);135}136
137dualListbox.elements.info1.html(content);138dualListbox.elements.box1.toggleClass('filtered', !(visible1 === all1 || all1 === 0));139
140if (all2 === 0) {141content = dualListbox.settings.infoTextEmpty;142} else if (visible2 === all2) {143content = formatString(dualListbox.settings.infoText, [visible2, all2]);144} else {145content = formatString(dualListbox.settings.infoTextFiltered, [visible2, all2]);146}147
148dualListbox.elements.info2.html(content);149dualListbox.elements.box2.toggleClass('filtered', !(visible2 === all2 || all2 === 0));150}151
152function refreshSelects(dualListbox) {153dualListbox.selectedElements = 0;154
155dualListbox.elements.select1.empty();156dualListbox.elements.select2.empty();157
158dualListbox.element.find('option').each(function(index, item) {159var $item = $(item);160if ($item.prop('selected')) {161dualListbox.selectedElements++;162dualListbox.elements.select2.append($item.clone(true).prop('selected', $item.data('_selected')));163} else {164dualListbox.elements.select1.append($item.clone(true).prop('selected', $item.data('_selected')));165}166});167
168if (dualListbox.settings.showFilterInputs) {169filter(dualListbox, 1);170filter(dualListbox, 2);171}172refreshInfo(dualListbox);173}174
175function filter(dualListbox, selectIndex) {176if (!dualListbox.settings.showFilterInputs) {177return;178}179
180saveSelections(dualListbox, selectIndex);181
182dualListbox.elements['select'+selectIndex].empty().scrollTop(0);183var regex,184allOptions = dualListbox.element.find('option'),185options = dualListbox.element;186
187if (selectIndex === 1) {188options = allOptions.not(':selected');189} else {190options = options.find('option:selected');191}192
193try {194regex = new RegExp($.trim(dualListbox.elements['filterInput'+selectIndex].val()), 'gi');195}196catch(e) {197// a regex to match nothing198regex = new RegExp('/a^/', 'gi');199}200
201options.each(function(index, item) {202var $item = $(item),203isFiltered = true;204if (item.text.match(regex) || (dualListbox.settings.filterOnValues && $item.attr('value').match(regex) ) ) {205isFiltered = false;206dualListbox.elements['select'+selectIndex].append($item.clone(true).prop('selected', $item.data('_selected')));207}208allOptions.eq($item.data('original-index')).data('filtered'+selectIndex, isFiltered);209});210
211refreshInfo(dualListbox);212}213
214function saveSelections(dualListbox, selectIndex) {215var options = dualListbox.element.find('option');216dualListbox.elements['select'+selectIndex].find('option').each(function(index, item) {217var $item = $(item);218options.eq($item.data('original-index')).data('_selected', $item.prop('selected'));219});220}221
222function sortOptionsByInputOrder(select){223var selectopt = select.children('option');224
225selectopt.sort(function(a,b){226var an = parseInt(a.getAttribute('data-sortindex')),227bn = parseInt(b.getAttribute('data-sortindex'));228
229if(an > bn) {230return 1;231}232if(an < bn) {233return -1;234}235return 0;236});237
238selectopt.detach().appendTo(select);239}240
241function sortOptions(select, dualListbox) {242select.find('option').sort(function(a, b) {243return ($(a).data('original-index') > $(b).data('original-index')) ? 1 : -1;244}).appendTo(select);245
246// workaround for chromium bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1072475247refreshSelects(dualListbox);248}249
250function clearSelections(dualListbox) {251dualListbox.elements.select1.find('option').each(function() {252dualListbox.element.find('option').data('_selected', false);253});254}255
256function move(dualListbox) {257if (dualListbox.settings.preserveSelectionOnMove === 'all' && !dualListbox.settings.moveOnSelect) {258saveSelections(dualListbox, 1);259saveSelections(dualListbox, 2);260} else if (dualListbox.settings.preserveSelectionOnMove === 'moved' && !dualListbox.settings.moveOnSelect) {261saveSelections(dualListbox, 1);262}263
264dualListbox.elements.select1.find('option:selected').each(function(index, item) {265var $item = $(item);266if (!$item.data('filtered1')) {267changeSelectionState(dualListbox, $item.data('original-index'), true);268}269});270
271refreshSelects(dualListbox);272triggerChangeEvent(dualListbox);273if(dualListbox.settings.sortByInputOrder){274sortOptionsByInputOrder(dualListbox.elements.select2);275} else {276sortOptions(dualListbox.elements.select2, dualListbox);277}278}279
280function remove(dualListbox) {281if (dualListbox.settings.preserveSelectionOnMove === 'all' && !dualListbox.settings.moveOnSelect) {282saveSelections(dualListbox, 1);283saveSelections(dualListbox, 2);284} else if (dualListbox.settings.preserveSelectionOnMove === 'moved' && !dualListbox.settings.moveOnSelect) {285saveSelections(dualListbox, 2);286}287
288dualListbox.elements.select2.find('option:selected').each(function(index, item) {289var $item = $(item);290if (!$item.data('filtered2')) {291changeSelectionState(dualListbox, $item.data('original-index'), false);292}293});294
295refreshSelects(dualListbox);296triggerChangeEvent(dualListbox);297sortOptions(dualListbox.elements.select1, dualListbox);298if(dualListbox.settings.sortByInputOrder){299sortOptionsByInputOrder(dualListbox.elements.select2);300}301}302
303function moveAll(dualListbox) {304if (dualListbox.settings.preserveSelectionOnMove === 'all' && !dualListbox.settings.moveOnSelect) {305saveSelections(dualListbox, 1);306saveSelections(dualListbox, 2);307} else if (dualListbox.settings.preserveSelectionOnMove === 'moved' && !dualListbox.settings.moveOnSelect) {308saveSelections(dualListbox, 1);309}310
311dualListbox.element.find('option').each(function(index, item) {312var $item = $(item);313if (!$item.data('filtered1')) {314$item.prop('selected', true);315$item.attr('data-sortindex', dualListbox.sortIndex);316dualListbox.sortIndex++;317}318});319
320refreshSelects(dualListbox);321triggerChangeEvent(dualListbox);322}323
324function removeAll(dualListbox) {325if (dualListbox.settings.preserveSelectionOnMove === 'all' && !dualListbox.settings.moveOnSelect) {326saveSelections(dualListbox, 1);327saveSelections(dualListbox, 2);328} else if (dualListbox.settings.preserveSelectionOnMove === 'moved' && !dualListbox.settings.moveOnSelect) {329saveSelections(dualListbox, 2);330}331
332dualListbox.element.find('option').each(function(index, item) {333var $item = $(item);334if (!$item.data('filtered2')) {335$item.prop('selected', false);336$item.removeAttr('data-sortindex');337}338});339
340refreshSelects(dualListbox);341triggerChangeEvent(dualListbox);342}343
344function bindEvents(dualListbox) {345dualListbox.elements.form.submit(function(e) {346if (dualListbox.elements.filterInput1.is(':focus')) {347e.preventDefault();348dualListbox.elements.filterInput1.focusout();349} else if (dualListbox.elements.filterInput2.is(':focus')) {350e.preventDefault();351dualListbox.elements.filterInput2.focusout();352}353});354
355dualListbox.element.on('bootstrapDualListbox.refresh', function(e, mustClearSelections){356dualListbox.refresh(mustClearSelections);357});358
359dualListbox.elements.filterClear1.on('click', function() {360dualListbox.setNonSelectedFilter('', true);361});362
363dualListbox.elements.filterClear2.on('click', function() {364dualListbox.setSelectedFilter('', true);365});366
367if (dualListbox.settings.eventMoveOverride === false) {368dualListbox.elements.moveButton.on('click', function() {369move(dualListbox);370});371}372
373if (dualListbox.settings.eventMoveAllOverride === false) {374dualListbox.elements.moveAllButton.on('click', function() {375moveAll(dualListbox);376});377}378
379if (dualListbox.settings.eventRemoveOverride === false) {380dualListbox.elements.removeButton.on('click', function() {381remove(dualListbox);382});383}384
385if (dualListbox.settings.eventRemoveAllOverride === false) {386dualListbox.elements.removeAllButton.on('click', function() {387removeAll(dualListbox);388});389}390
391dualListbox.elements.filterInput1.on('change keyup', function() {392filter(dualListbox, 1);393});394
395dualListbox.elements.filterInput2.on('change keyup', function() {396filter(dualListbox, 2);397});398}399
400BootstrapDualListbox.prototype = {401init: function () {402// Add the custom HTML template403this.container = $('' +404'<div class="bootstrap-duallistbox-container row">' +405' <div class="box1 col-md-6">' +406' <label></label>' +407' <span class="info-container">' +408' <span class="info"></span>' +409' <button type="button" class="btn btn-sm clear1" style="float:right!important;"></button>' +410' </span>' +411' <input class="form-control filter" type="text">' +412' <div class="btn-group buttons">' +413' <button type="button" class="btn moveall"></button>' +414' <button type="button" class="btn move"></button>' +415' </div>' +416' <select multiple="multiple"></select>' +417' </div>' +418' <div class="box2 col-md-6">' +419' <label></label>' +420' <span class="info-container">' +421' <span class="info"></span>' +422' <button type="button" class="btn btn-sm clear2" style="float:right!important;"></button>' +423' </span>' +424' <input class="form-control filter" type="text">' +425' <div class="btn-group buttons">' +426' <button type="button" class="btn remove"></button>' +427' <button type="button" class="btn removeall"></button>' +428' </div>' +429' <select multiple="multiple"></select>' +430' </div>' +431'</div>')432.insertBefore(this.element);433
434// Cache the inner elements435this.elements = {436originalSelect: this.element,437box1: $('.box1', this.container),438box2: $('.box2', this.container),439filterInput1: $('.box1 .filter', this.container),440filterInput2: $('.box2 .filter', this.container),441filterClear1: $('.box1 .clear1', this.container),442filterClear2: $('.box2 .clear2', this.container),443label1: $('.box1 > label', this.container),444label2: $('.box2 > label', this.container),445info1: $('.box1 .info', this.container),446info2: $('.box2 .info', this.container),447select1: $('.box1 select', this.container),448select2: $('.box2 select', this.container),449moveButton: $('.box1 .move', this.container),450removeButton: $('.box2 .remove', this.container),451moveAllButton: $('.box1 .moveall', this.container),452removeAllButton: $('.box2 .removeall', this.container),453form: $($('.box1 .filter', this.container)[0].form)454};455
456// Set select IDs457this.originalSelectName = this.element.attr('name') || '';458var select1Id = 'bootstrap-duallistbox-nonselected-list_' + this.originalSelectName,459select2Id = 'bootstrap-duallistbox-selected-list_' + this.originalSelectName;460this.elements.select1.attr('id', select1Id);461this.elements.select2.attr('id', select2Id);462this.elements.label1.attr('for', select1Id);463this.elements.label2.attr('for', select2Id);464
465// Apply all settings466this.selectedElements = 0;467this.sortIndex = 0;468this.elementCount = 0;469this.setFilterTextClear(this.settings.filterTextClear);470this.setFilterPlaceHolder(this.settings.filterPlaceHolder);471this.setMoveSelectedLabel(this.settings.moveSelectedLabel);472this.setMoveAllLabel(this.settings.moveAllLabel);473this.setRemoveSelectedLabel(this.settings.removeSelectedLabel);474this.setRemoveAllLabel(this.settings.removeAllLabel);475this.setMoveOnSelect(this.settings.moveOnSelect);476this.setMoveOnDoubleClick(this.settings.moveOnDoubleClick);477this.setPreserveSelectionOnMove(this.settings.preserveSelectionOnMove);478this.setSelectedListLabel(this.settings.selectedListLabel);479this.setNonSelectedListLabel(this.settings.nonSelectedListLabel);480this.setHelperSelectNamePostfix(this.settings.helperSelectNamePostfix);481this.setSelectOrMinimalHeight(this.settings.selectorMinimalHeight);482
483updateSelectionStates(this);484
485this.setShowFilterInputs(this.settings.showFilterInputs);486this.setNonSelectedFilter(this.settings.nonSelectedFilter);487this.setSelectedFilter(this.settings.selectedFilter);488this.setInfoText(this.settings.infoText);489this.setInfoTextFiltered(this.settings.infoTextFiltered);490this.setInfoTextEmpty(this.settings.infoTextEmpty);491this.setFilterOnValues(this.settings.filterOnValues);492this.setSortByInputOrder(this.settings.sortByInputOrder);493this.setEventMoveOverride(this.settings.eventMoveOverride);494this.setEventMoveAllOverride(this.settings.eventMoveAllOverride);495this.setEventRemoveOverride(this.settings.eventRemoveOverride);496this.setEventRemoveAllOverride(this.settings.eventRemoveAllOverride);497this.setBtnClass(this.settings.btnClass);498this.setBtnMoveText(this.settings.btnMoveText);499this.setBtnRemoveText(this.settings.btnRemoveText);500this.setBtnMoveAllText(this.settings.btnMoveAllText);501this.setBtnRemoveAllText(this.settings.btnRemoveAllText);502
503// Hide the original select504this.element.hide();505
506bindEvents(this);507refreshSelects(this);508
509return this.element;510},511setFilterTextClear: function(value, refresh) {512this.settings.filterTextClear = value;513this.elements.filterClear1.html(value);514this.elements.filterClear2.html(value);515if (refresh) {516refreshSelects(this);517}518return this.element;519},520setFilterPlaceHolder: function(value, refresh) {521this.settings.filterPlaceHolder = value;522this.elements.filterInput1.attr('placeholder', value);523this.elements.filterInput2.attr('placeholder', value);524if (refresh) {525refreshSelects(this);526}527return this.element;528},529setMoveSelectedLabel: function(value, refresh) {530this.settings.moveSelectedLabel = value;531this.elements.moveButton.attr('title', value);532if (refresh) {533refreshSelects(this);534}535return this.element;536},537setMoveAllLabel: function(value, refresh) {538this.settings.moveAllLabel = value;539this.elements.moveAllButton.attr('title', value);540if (refresh) {541refreshSelects(this);542}543return this.element;544},545setRemoveSelectedLabel: function(value, refresh) {546this.settings.removeSelectedLabel = value;547this.elements.removeButton.attr('title', value);548if (refresh) {549refreshSelects(this);550}551return this.element;552},553setRemoveAllLabel: function(value, refresh) {554this.settings.removeAllLabel = value;555this.elements.removeAllButton.attr('title', value);556if (refresh) {557refreshSelects(this);558}559return this.element;560},561setMoveOnSelect: function(value, refresh) {562if (isBuggyAndroid) {563value = true;564}565this.settings.moveOnSelect = value;566if (this.settings.moveOnSelect) {567this.container.addClass('moveonselect');568var self = this;569this.elements.select1.on('change', function() {570move(self);571});572this.elements.select2.on('change', function() {573remove(self);574});575this.elements.moveButton.detach();576this.elements.removeButton.detach();577} else {578this.container.removeClass('moveonselect');579this.elements.select1.off('change');580this.elements.select2.off('change');581this.elements.moveButton.insertAfter(this.elements.moveAllButton);582this.elements.removeButton.insertBefore(this.elements.removeAllButton);583}584if (refresh) {585refreshSelects(this);586}587return this.element;588},589setMoveOnDoubleClick: function(value, refresh) {590if (isBuggyAndroid) {591value = false;592}593this.settings.moveOnDoubleClick = value;594if (this.settings.moveOnDoubleClick) {595this.container.addClass('moveondoubleclick');596var self = this;597this.elements.select1.on('dblclick', function() {598move(self);599});600this.elements.select2.on('dblclick', function() {601remove(self);602});603} else {604this.container.removeClass('moveondoubleclick');605this.elements.select1.off('dblclick');606this.elements.select2.off('dblclick');607}608if (refresh) {609refreshSelects(this);610}611return this.element;612},613setPreserveSelectionOnMove: function(value, refresh) {614// We are forcing to move on select and disabling preserveSelectionOnMove on Android615if (isBuggyAndroid) {616value = false;617}618this.settings.preserveSelectionOnMove = value;619if (refresh) {620refreshSelects(this);621}622return this.element;623},624setSelectedListLabel: function(value, refresh) {625this.settings.selectedListLabel = value;626if (value) {627this.elements.label2.show().html(value);628} else {629this.elements.label2.hide().html(value);630}631if (refresh) {632refreshSelects(this);633}634return this.element;635},636setNonSelectedListLabel: function(value, refresh) {637this.settings.nonSelectedListLabel = value;638if (value) {639this.elements.label1.show().html(value);640} else {641this.elements.label1.hide().html(value);642}643if (refresh) {644refreshSelects(this);645}646return this.element;647},648setHelperSelectNamePostfix: function(value, refresh) {649this.settings.helperSelectNamePostfix = value;650if (value) {651this.elements.select1.attr('name', this.originalSelectName + value + '1');652this.elements.select2.attr('name', this.originalSelectName + value + '2');653} else {654this.elements.select1.removeAttr('name');655this.elements.select2.removeAttr('name');656}657if (refresh) {658refreshSelects(this);659}660return this.element;661},662setSelectOrMinimalHeight: function(value, refresh) {663this.settings.selectorMinimalHeight = value;664var height = this.element.height();665if (this.element.height() < value) {666height = value;667}668this.elements.select1.height(height);669this.elements.select2.height(height);670if (refresh) {671refreshSelects(this);672}673return this.element;674},675setShowFilterInputs: function(value, refresh) {676if (!value) {677this.setNonSelectedFilter('');678this.setSelectedFilter('');679refreshSelects(this);680this.elements.filterInput1.hide();681this.elements.filterInput2.hide();682} else {683this.elements.filterInput1.show();684this.elements.filterInput2.show();685}686this.settings.showFilterInputs = value;687if (refresh) {688refreshSelects(this);689}690return this.element;691},692setNonSelectedFilter: function(value, refresh) {693if (this.settings.showFilterInputs) {694this.settings.nonSelectedFilter = value;695this.elements.filterInput1.val(value);696if (refresh) {697refreshSelects(this);698}699return this.element;700}701},702setSelectedFilter: function(value, refresh) {703if (this.settings.showFilterInputs) {704this.settings.selectedFilter = value;705this.elements.filterInput2.val(value);706if (refresh) {707refreshSelects(this);708}709return this.element;710}711},712setInfoText: function(value, refresh) {713this.settings.infoText = value;714if (value) {715this.elements.info1.show();716this.elements.info2.show();717} else {718this.elements.info1.hide();719this.elements.info2.hide();720}721if (refresh) {722refreshSelects(this);723}724return this.element;725},726setInfoTextFiltered: function(value, refresh) {727this.settings.infoTextFiltered = value;728if (refresh) {729refreshSelects(this);730}731return this.element;732},733setInfoTextEmpty: function(value, refresh) {734this.settings.infoTextEmpty = value;735if (refresh) {736refreshSelects(this);737}738return this.element;739},740setFilterOnValues: function(value, refresh) {741this.settings.filterOnValues = value;742if (refresh) {743refreshSelects(this);744}745return this.element;746},747setSortByInputOrder: function(value, refresh){748this.settings.sortByInputOrder = value;749if (refresh) {750refreshSelects(this);751}752return this.element;753},754setEventMoveOverride: function(value, refresh) {755this.settings.eventMoveOverride = value;756if (refresh) {757refreshSelects(this);758}759return this.element;760},761setEventMoveAllOverride: function(value, refresh) {762this.settings.eventMoveAllOverride = value;763if (refresh) {764refreshSelects(this);765}766return this.element;767},768setEventRemoveOverride: function(value, refresh) {769this.settings.eventRemoveOverride = value;770if (refresh) {771refreshSelects(this);772}773return this.element;774},775setEventRemoveAllOverride: function(value, refresh) {776this.settings.eventRemoveAllOverride = value;777if (refresh) {778refreshSelects(this);779}780return this.element;781},782setBtnClass: function(value, refresh) {783this.settings.btnClass = value;784this.elements.moveButton.attr('class', 'btn move').addClass(value);785this.elements.removeButton.attr('class', 'btn remove').addClass(value);786this.elements.moveAllButton.attr('class', 'btn moveall').addClass(value);787this.elements.removeAllButton.attr('class', 'btn removeall').addClass(value);788if (refresh) {789refreshSelects(this);790}791return this.element;792},793setBtnMoveText: function(value, refresh) {794this.settings.btnMoveText = value;795this.elements.moveButton.html(value);796if (refresh) {797refreshSelects(this);798}799return this.element;800},801setBtnRemoveText: function(value, refresh) {802this.settings.btnMoveText = value;803this.elements.removeButton.html(value);804if (refresh) {805refreshSelects(this);806}807return this.element;808},809setBtnMoveAllText: function(value, refresh) {810this.settings.btnMoveText = value;811this.elements.moveAllButton.html(value);812if (refresh) {813refreshSelects(this);814}815return this.element;816},817setBtnRemoveAllText: function(value, refresh) {818this.settings.btnMoveText = value;819this.elements.removeAllButton.html(value);820if (refresh) {821refreshSelects(this);822}823return this.element;824},825getContainer: function() {826return this.container;827},828refresh: function(mustClearSelections) {829updateSelectionStates(this);830
831if (!mustClearSelections) {832saveSelections(this, 1);833saveSelections(this, 2);834} else {835clearSelections(this);836}837
838refreshSelects(this);839},840destroy: function() {841this.container.remove();842this.element.show();843$.data(this, 'plugin_' + pluginName, null);844return this.element;845}846};847
848// A really lightweight plugin wrapper around the constructor,849// preventing against multiple instantiations850$.fn[ pluginName ] = function (options) {851var args = arguments;852
853// Is the first parameter an object (options), or was omitted, instantiate a new instance of the plugin.854if (options === undefined || typeof options === 'object') {855return this.each(function () {856// If this is not a select857if (!$(this).is('select')) {858$(this).find('select').each(function(index, item) {859// For each nested select, instantiate the Dual List Box860$(item).bootstrapDualListbox(options);861});862} else if (!$.data(this, 'plugin_' + pluginName)) {863// Only allow the plugin to be instantiated once so we check that the element has no plugin instantiation yet864
865// if it has no instance, create a new one, pass options to our plugin constructor,866// and store the plugin instance in the elements jQuery data object.867$.data(this, 'plugin_' + pluginName, new BootstrapDualListbox(this, options));868}869});870// If the first parameter is a string and it doesn't start with an underscore or "contains" the `init`-function,871// treat this as a call to a public method.872} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {873
874// Cache the method call to make it possible to return a value875var returns;876
877this.each(function () {878var instance = $.data(this, 'plugin_' + pluginName);879// Tests that there's already a plugin-instance and checks that the requested public method exists880if (instance instanceof BootstrapDualListbox && typeof instance[options] === 'function') {881// Call the method of our plugin instance, and pass it the supplied arguments.882returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));883}884});885
886// If the earlier cached method gives a value back return the value,887// otherwise return this to preserve chainability.888return returns !== undefined ? returns : this;889}890
891};892
893}));894