12345678910 |
- /*
- * Bootstrap Duallistbox - v3.0.7
- * A responsive dual listbox widget optimized for Twitter Bootstrap. It works on all modern browsers and on touch devices.
- * https://www.virtuosoft.eu/code/bootstrap-duallistbox/
- *
- * Made by István Ujj-Mészáros
- * Under Apache License v2.0 License
- */
- !function(a,e,t,s){var l="bootstrapDualListbox",n={bootstrap2Compatible:!1,filterTextClear:"show all",filterPlaceHolder:"Filter",moveSelectedLabel:"Move selected",moveAllLabel:"Move all",removeSelectedLabel:"Remove selected",removeAllLabel:"Remove all",moveOnSelect:!0,moveOnDoubleClick:!0,preserveSelectionOnMove:!1,selectedListLabel:!1,nonSelectedListLabel:!1,helperSelectNamePostfix:"_helper",selectorMinimalHeight:100,showFilterInputs:!0,nonSelectedFilter:"",selectedFilter:"",infoText:"Showing all {0}",infoTextFiltered:'<span class="label label-warning">Filtered</span> {0} from {1}',infoTextEmpty:"Empty list",filterOnValues:!1,sortByInputOrder:!1,eventMoveOverride:!1,eventMoveAllOverride:!1,eventRemoveOverride:!1,eventRemoveAllOverride:!1},i=/android/i.test(navigator.userAgent.toLowerCase());function o(e,t){this.element=a(e),this.settings=a.extend({},n,t),this._defaults=n,this._name=l,this.init()}function r(e){e.element.trigger("change")}function c(i){i.element.find("option").each(function(e,t){var n=a(t);void 0===n.data("original-index")&&n.data("original-index",i.elementCount++),void 0===n.data("_selected")&&n.data("_selected",!1)})}function h(i,s,l){i.element.find("option").each(function(e,t){var n=a(t);n.data("original-index")===s&&(n.prop("selected",l),l?(n.attr("data-sortindex",i.sortIndex),i.sortIndex++):n.removeAttr("data-sortindex"))})}function m(e,n){return e.replace(/\{(\d+)\}/g,function(e,t){return void 0!==n[t]?n[t]:e})}function d(e){if(e.settings.infoText){var t=e.elements.select1.find("option").length,n=e.elements.select2.find("option").length,i=e.element.find("option").length-e.selectedElements,s=e.selectedElements,l="";l=0===i?e.settings.infoTextEmpty:m(t===i?e.settings.infoText:e.settings.infoTextFiltered,[t,i]),e.elements.info1.html(l),e.elements.box1.toggleClass("filtered",!(t===i||0===i)),l=0===s?e.settings.infoTextEmpty:m(n===s?e.settings.infoText:e.settings.infoTextFiltered,[n,s]),e.elements.info2.html(l),e.elements.box2.toggleClass("filtered",!(n===s||0===s))}}function v(i){i.selectedElements=0,i.elements.select1.empty(),i.elements.select2.empty(),i.element.find("option").each(function(e,t){var n=a(t);n.prop("selected")?(i.selectedElements++,i.elements.select2.append(n.clone(!0).prop("selected",n.data("_selected")))):i.elements.select1.append(n.clone(!0).prop("selected",n.data("_selected")))}),i.settings.showFilterInputs&&(f(i,1),f(i,2)),d(i)}function f(s,l){if(s.settings.showFilterInputs){u(s,l),s.elements["select"+l].empty().scrollTop(0);var o=new RegExp(a.trim(s.elements["filterInput"+l].val()),"gi"),r=s.element.find("option"),e=s.element;(e=1===l?r.not(":selected"):e.find("option:selected")).each(function(e,t){var n=a(t),i=!0;(t.text.match(o)||s.settings.filterOnValues&&n.attr("value").match(o))&&(i=!1,s.elements["select"+l].append(n.clone(!0).prop("selected",n.data("_selected")))),r.eq(n.data("original-index")).data("filtered"+l,i)}),d(s)}}function u(e,t){var i=e.element.find("option");e.elements["select"+t].find("option").each(function(e,t){var n=a(t);i.eq(n.data("original-index")).data("_selected",n.prop("selected"))})}function p(e){var t=e.children("option");t.sort(function(e,t){var n=parseInt(e.getAttribute("data-sortindex")),i=parseInt(t.getAttribute("data-sortindex"));return i<n?1:n<i?-1:0}),t.detach().appendTo(e)}function g(e){e.find("option").sort(function(e,t){return a(e).data("original-index")>a(t).data("original-index")?1:-1}).appendTo(e)}function b(i){"all"!==i.settings.preserveSelectionOnMove||i.settings.moveOnSelect?"moved"!==i.settings.preserveSelectionOnMove||i.settings.moveOnSelect||u(i,1):(u(i,1),u(i,2)),i.elements.select1.find("option:selected").each(function(e,t){var n=a(t);n.data("filtered1")||h(i,n.data("original-index"),!0)}),v(i),r(i),i.settings.sortByInputOrder?p(i.elements.select2):g(i.elements.select2)}function x(i){"all"!==i.settings.preserveSelectionOnMove||i.settings.moveOnSelect?"moved"!==i.settings.preserveSelectionOnMove||i.settings.moveOnSelect||u(i,2):(u(i,1),u(i,2)),i.elements.select2.find("option:selected").each(function(e,t){var n=a(t);n.data("filtered2")||h(i,n.data("original-index"),!1)}),v(i),r(i),g(i.elements.select1),i.settings.sortByInputOrder&&p(i.elements.select2)}function S(n){n.elements.form.submit(function(e){n.elements.filterInput1.is(":focus")?(e.preventDefault(),n.elements.filterInput1.focusout()):n.elements.filterInput2.is(":focus")&&(e.preventDefault(),n.elements.filterInput2.focusout())}),n.element.on("bootstrapDualListbox.refresh",function(e,t){n.refresh(t)}),n.elements.filterClear1.on("click",function(){n.setNonSelectedFilter("",!0)}),n.elements.filterClear2.on("click",function(){n.setSelectedFilter("",!0)}),!1===n.settings.eventMoveOverride&&n.elements.moveButton.on("click",function(){b(n)}),!1===n.settings.eventMoveAllOverride&&n.elements.moveAllButton.on("click",function(){var i;"all"!==(i=n).settings.preserveSelectionOnMove||i.settings.moveOnSelect?"moved"!==i.settings.preserveSelectionOnMove||i.settings.moveOnSelect||u(i,1):(u(i,1),u(i,2)),i.element.find("option").each(function(e,t){var n=a(t);n.data("filtered1")||(n.prop("selected",!0),n.attr("data-sortindex",i.sortIndex),i.sortIndex++)}),v(i),r(i)}),!1===n.settings.eventRemoveOverride&&n.elements.removeButton.on("click",function(){x(n)}),!1===n.settings.eventRemoveAllOverride&&n.elements.removeAllButton.on("click",function(){var e;"all"!==(e=n).settings.preserveSelectionOnMove||e.settings.moveOnSelect?"moved"!==e.settings.preserveSelectionOnMove||e.settings.moveOnSelect||u(e,2):(u(e,1),u(e,2)),e.element.find("option").each(function(e,t){var n=a(t);n.data("filtered2")||(n.prop("selected",!1),n.removeAttr("data-sortindex"))}),v(e),r(e)}),n.elements.filterInput1.on("change keyup",function(){f(n,1)}),n.elements.filterInput2.on("change keyup",function(){f(n,2)})}o.prototype={init:function(){this.container=a('<div class="bootstrap-duallistbox-container"> <div class="box1"> <label></label> <span class="info-container"> <span class="info"></span> <button type="button" class="btn clear1 pull-right"></button> </span> <input class="filter" type="text"> <div class="btn-group buttons"> <button type="button" class="btn moveall"> <i></i> <i></i> </button> <button type="button" class="btn move"> <i></i> </button> </div> <select multiple="multiple"></select> </div> <div class="box2"> <label></label> <span class="info-container"> <span class="info"></span> <button type="button" class="btn clear2 pull-right"></button> </span> <input class="filter" type="text"> <div class="btn-group buttons"> <button type="button" class="btn remove"> <i></i> </button> <button type="button" class="btn removeall"> <i></i> <i></i> </button> </div> <select multiple="multiple"></select> </div></div>').insertBefore(this.element),this.elements={originalSelect:this.element,box1:a(".box1",this.container),box2:a(".box2",this.container),filterInput1:a(".box1 .filter",this.container),filterInput2:a(".box2 .filter",this.container),filterClear1:a(".box1 .clear1",this.container),filterClear2:a(".box2 .clear2",this.container),label1:a(".box1 > label",this.container),label2:a(".box2 > label",this.container),info1:a(".box1 .info",this.container),info2:a(".box2 .info",this.container),select1:a(".box1 select",this.container),select2:a(".box2 select",this.container),moveButton:a(".box1 .move",this.container),removeButton:a(".box2 .remove",this.container),moveAllButton:a(".box1 .moveall",this.container),removeAllButton:a(".box2 .removeall",this.container),form:a(a(".box1 .filter",this.container)[0].form)},this.originalSelectName=this.element.attr("name")||"";var e="bootstrap-duallistbox-nonselected-list_"+this.originalSelectName,t="bootstrap-duallistbox-selected-list_"+this.originalSelectName;return this.elements.select1.attr("id",e),this.elements.select2.attr("id",t),this.elements.label1.attr("for",e),this.elements.label2.attr("for",t),this.selectedElements=0,this.sortIndex=0,this.elementCount=0,this.setBootstrap2Compatible(this.settings.bootstrap2Compatible),this.setFilterTextClear(this.settings.filterTextClear),this.setFilterPlaceHolder(this.settings.filterPlaceHolder),this.setMoveSelectedLabel(this.settings.moveSelectedLabel),this.setMoveAllLabel(this.settings.moveAllLabel),this.setRemoveSelectedLabel(this.settings.removeSelectedLabel),this.setRemoveAllLabel(this.settings.removeAllLabel),this.setMoveOnSelect(this.settings.moveOnSelect),this.setMoveOnDoubleClick(this.settings.moveOnDoubleClick),this.setPreserveSelectionOnMove(this.settings.preserveSelectionOnMove),this.setSelectedListLabel(this.settings.selectedListLabel),this.setNonSelectedListLabel(this.settings.nonSelectedListLabel),this.setHelperSelectNamePostfix(this.settings.helperSelectNamePostfix),this.setSelectOrMinimalHeight(this.settings.selectorMinimalHeight),c(this),this.setShowFilterInputs(this.settings.showFilterInputs),this.setNonSelectedFilter(this.settings.nonSelectedFilter),this.setSelectedFilter(this.settings.selectedFilter),this.setInfoText(this.settings.infoText),this.setInfoTextFiltered(this.settings.infoTextFiltered),this.setInfoTextEmpty(this.settings.infoTextEmpty),this.setFilterOnValues(this.settings.filterOnValues),this.setSortByInputOrder(this.settings.sortByInputOrder),this.setEventMoveOverride(this.settings.eventMoveOverride),this.setEventMoveAllOverride(this.settings.eventMoveAllOverride),this.setEventRemoveOverride(this.settings.eventRemoveOverride),this.setEventRemoveAllOverride(this.settings.eventRemoveAllOverride),this.element.hide(),S(this),v(this),this.element},setBootstrap2Compatible:function(e,t){return(this.settings.bootstrap2Compatible=e)?(this.container.removeClass("row").addClass("row-fluid bs2compatible"),this.container.find(".box1, .box2").removeClass("col-md-6").addClass("span6"),this.container.find(".clear1, .clear2").removeClass("btn-white btn-xs").addClass("btn-mini"),this.container.find("input, select").removeClass("form-control"),this.container.find(".btn").removeClass("btn-white"),this.container.find(".moveall > i, .move > i").removeClass("glyphicon glyphicon-arrow-right").addClass("icon-arrow-right"),this.container.find(".removeall > i, .remove > i").removeClass("glyphicon glyphicon-arrow-left").addClass("icon-arrow-left")):(this.container.removeClass("row-fluid bs2compatible").addClass("row"),this.container.find(".box1, .box2").removeClass("span6").addClass("col-md-6"),this.container.find(".clear1, .clear2").removeClass("btn-mini").addClass("btn-white btn-xs"),this.container.find("input, select").addClass("form-control"),this.container.find(".btn").addClass("btn-white"),this.container.find(".moveall > i, .move > i").removeClass("icon-arrow-right").addClass("glyphicon glyphicon-arrow-right"),this.container.find(".removeall > i, .remove > i").removeClass("icon-arrow-left").addClass("glyphicon glyphicon-arrow-left")),t&&v(this),this.element},setFilterTextClear:function(e,t){return this.settings.filterTextClear=e,this.elements.filterClear1.html(e),this.elements.filterClear2.html(e),t&&v(this),this.element},setFilterPlaceHolder:function(e,t){return this.settings.filterPlaceHolder=e,this.elements.filterInput1.attr("placeholder",e),this.elements.filterInput2.attr("placeholder",e),t&&v(this),this.element},setMoveSelectedLabel:function(e,t){return this.settings.moveSelectedLabel=e,this.elements.moveButton.attr("title",e),t&&v(this),this.element},setMoveAllLabel:function(e,t){return this.settings.moveAllLabel=e,this.elements.moveAllButton.attr("title",e),t&&v(this),this.element},setRemoveSelectedLabel:function(e,t){return this.settings.removeSelectedLabel=e,this.elements.removeButton.attr("title",e),t&&v(this),this.element},setRemoveAllLabel:function(e,t){return this.settings.removeAllLabel=e,this.elements.removeAllButton.attr("title",e),t&&v(this),this.element},setMoveOnSelect:function(e,t){if(i&&(e=!0),this.settings.moveOnSelect=e,this.settings.moveOnSelect){this.container.addClass("moveonselect");var n=this;this.elements.select1.on("change",function(){b(n)}),this.elements.select2.on("change",function(){x(n)})}else this.container.removeClass("moveonselect"),this.elements.select1.off("change"),this.elements.select2.off("change");return t&&v(this),this.element},setMoveOnDoubleClick:function(e,t){if(i&&(e=!1),this.settings.moveOnDoubleClick=e,this.settings.moveOnDoubleClick){this.container.addClass("moveondoubleclick");var n=this;this.elements.select1.on("dblclick",function(){b(n)}),this.elements.select2.on("dblclick",function(){x(n)})}else this.container.removeClass("moveondoubleclick"),this.elements.select1.off("dblclick"),this.elements.select2.off("dblclick");return t&&v(this),this.element},setPreserveSelectionOnMove:function(e,t){return i&&(e=!1),this.settings.preserveSelectionOnMove=e,t&&v(this),this.element},setSelectedListLabel:function(e,t){return(this.settings.selectedListLabel=e)?this.elements.label2.show().html(e):this.elements.label2.hide().html(e),t&&v(this),this.element},setNonSelectedListLabel:function(e,t){return(this.settings.nonSelectedListLabel=e)?this.elements.label1.show().html(e):this.elements.label1.hide().html(e),t&&v(this),this.element},setHelperSelectNamePostfix:function(e,t){return(this.settings.helperSelectNamePostfix=e)?(this.elements.select1.attr("name",this.originalSelectName+e+"1"),this.elements.select2.attr("name",this.originalSelectName+e+"2")):(this.elements.select1.removeAttr("name"),this.elements.select2.removeAttr("name")),t&&v(this),this.element},setSelectOrMinimalHeight:function(e,t){this.settings.selectorMinimalHeight=e;var n=this.element.height();return this.element.height()<e&&(n=e),this.elements.select1.height(n),this.elements.select2.height(n),t&&v(this),this.element},setShowFilterInputs:function(e,t){return e?(this.elements.filterInput1.show(),this.elements.filterInput2.show()):(this.setNonSelectedFilter(""),this.setSelectedFilter(""),v(this),this.elements.filterInput1.hide(),this.elements.filterInput2.hide()),this.settings.showFilterInputs=e,t&&v(this),this.element},setNonSelectedFilter:function(e,t){if(this.settings.showFilterInputs)return this.settings.nonSelectedFilter=e,this.elements.filterInput1.val(e),t&&v(this),this.element},setSelectedFilter:function(e,t){if(this.settings.showFilterInputs)return this.settings.selectedFilter=e,this.elements.filterInput2.val(e),t&&v(this),this.element},setInfoText:function(e,t){return(this.settings.infoText=e)?(this.elements.info1.show(),this.elements.info2.show()):(this.elements.info1.hide(),this.elements.info2.hide()),t&&v(this),this.element},setInfoTextFiltered:function(e,t){return this.settings.infoTextFiltered=e,t&&v(this),this.element},setInfoTextEmpty:function(e,t){return this.settings.infoTextEmpty=e,t&&v(this),this.element},setFilterOnValues:function(e,t){return this.settings.filterOnValues=e,t&&v(this),this.element},setSortByInputOrder:function(e,t){return this.settings.sortByInputOrder=e,t&&v(this),this.element},setEventMoveOverride:function(e,t){return this.settings.eventMoveOverride=e,t&&v(this),this.element},setEventMoveAllOverride:function(e,t){return this.settings.eventMoveAllOverride=e,t&&v(this),this.element},setEventRemoveOverride:function(e,t){return this.settings.eventRemoveOverride=e,t&&v(this),this.element},setEventRemoveAllOverride:function(e,t){return this.settings.eventRemoveAllOverride=e,t&&v(this),this.element},getContainer:function(){return this.container},refresh:function(e){var t;c(this),e?(t=this).elements.select1.find("option").each(function(){t.element.find("option").data("_selected",!1)}):(u(this,1),u(this,2)),v(this)},destroy:function(){return this.container.remove(),this.element.show(),a.data(this,"plugin_"+l,null),this.element}},a.fn[l]=function(n){var t,i=arguments;return n===s||"object"==typeof n?this.each(function(){a(this).is("select")?a.data(this,"plugin_"+l)||a.data(this,"plugin_"+l,new o(this,n)):a(this).find("select").each(function(e,t){a(t).bootstrapDualListbox(n)})}):"string"==typeof n&&"_"!==n[0]&&"init"!==n?(this.each(function(){var e=a.data(this,"plugin_"+l);e instanceof o&&"function"==typeof e[n]&&(t=e[n].apply(e,Array.prototype.slice.call(i,1)))}),t!==s?t:this):void 0}}(jQuery,window,document);
|