Files
old-gravityflow/js/multi-select.min.js

1 line
11 KiB
JavaScript
Raw Normal View History

2018-08-06 15:41:19 +02:00
!function(C){"use strict";var n=function(e,t){this.options=t,this.$element=C(e),this.$container=C("<div/>",{class:"ms-container"}),this.$selectableContainer=C("<div/>",{class:"ms-selectable"}),this.$selectionContainer=C("<div/>",{class:"ms-selection"}),this.$selectableUl=C("<ul/>",{class:"ms-list",tabindex:"-1"}),this.$selectionUl=C("<ul/>",{class:"ms-list",tabindex:"-1"}),this.scrollTo=0,this.elemsSelector="li:visible:not(.ms-optgroup-label,.ms-optgroup-container,."+t.disabledClass+")"};n.prototype={constructor:n,init:function(){var e=this,t=this.$element;if(0===t.next(".ms-container").length){t.css({position:"absolute",left:"-9999px"}),t.attr("id",t.attr("id")?t.attr("id"):Math.ceil(1e3*Math.random())+"multiselect"),this.$container.attr("id","ms-"+t.attr("id")),this.$container.addClass(e.options.cssClass),t.find("option").each(function(){e.generateLisFromOption(this)}),this.$selectionUl.find(".ms-optgroup-label").hide(),e.options.selectableHeader&&e.$selectableContainer.append(e.options.selectableHeader),e.$selectableContainer.append(e.$selectableUl),e.options.selectableFooter&&e.$selectableContainer.append(e.options.selectableFooter),e.options.selectionHeader&&e.$selectionContainer.append(e.options.selectionHeader),e.$selectionContainer.append(e.$selectionUl),e.options.selectionFooter&&e.$selectionContainer.append(e.options.selectionFooter),e.$container.append(e.$selectableContainer),e.$container.append(e.$selectionContainer),t.after(e.$container),e.activeMouse(e.$selectableUl),e.activeKeyboard(e.$selectableUl);var s=e.options.dblClick?"dblclick":"click";e.$selectableUl.on(s,".ms-elem-selectable",function(){e.select(C(this).data("ms-value"))}),e.$selectionUl.on(s,".ms-elem-selection",function(){e.deselect(C(this).data("ms-value"))}),e.activeMouse(e.$selectionUl),e.activeKeyboard(e.$selectionUl),t.on("focus",function(){e.$selectableUl.focus()})}var l=t.find("option:selected").map(function(){return C(this).val()}).get();e.select(l,"init"),"function"==typeof e.options.afterInit&&e.options.afterInit.call(this,this.$container)},generateLisFromOption:function(e,t,s){for(var l=this,i=l.$element,n="",o=C(e),a=0;a<e.attributes.length;a++){var r=e.attributes[a];"value"!==r.name&&"disabled"!==r.name&&(n+=r.name+'="'+r.value+'" ')}var c=C("<li "+n+"><span>"+l.escapeHTML(o.text())+"</span></li>"),d=c.clone(),h=o.val(),p=l.sanitize(h);c.data("ms-value",h).addClass("ms-elem-selectable").attr("id",p+"-selectable"),d.data("ms-value",h).addClass("ms-elem-selection").attr("id",p+"-selection").hide(),(o.prop("disabled")||i.prop("disabled"))&&(d.addClass(l.options.disabledClass),c.addClass(l.options.disabledClass));var f=o.parent("optgroup");if(0<f.length){var u=f.attr("label"),m=l.sanitize(u),v=l.$selectableUl.find("#optgroup-selectable-"+m),b=l.$selectionUl.find("#optgroup-selection-"+m);if(0===v.length){var g='<li class="ms-optgroup-container"></li>',$='<ul class="ms-optgroup"><li class="ms-optgroup-label"><span>'+u+"</span></li></ul>";v=C(g),b=C(g),v.attr("id","optgroup-selectable-"+m),b.attr("id","optgroup-selection-"+m),v.append(C($)),b.append(C($)),l.options.selectableOptgroup&&(v.find(".ms-optgroup-label").on("click",function(){var e=f.children(":not(:selected, :disabled)").map(function(){return C(this).val()}).get();l.select(e)}),b.find(".ms-optgroup-label").on("click",function(){var e=f.children(":selected:not(:disabled)").map(function(){return C(this).val()}).get();l.deselect(e)})),l.$selectableUl.append(v),l.$selectionUl.append(b)}t=null==t?v.find("ul").children().length:t+1,c.insertAt(t,v.children()),d.insertAt(t,b.children())}else t=null==t?l.$selectableUl.children().length:t,c.insertAt(t,l.$selectableUl),d.insertAt(t,l.$selectionUl)},addOption:function(e){var i=this;void 0!==e.value&&null!==e.value&&(e=[e]),C.each(e,function(e,t){if(void 0!==t.value&&null!==t.value&&0===i.$element.find("option[value='"+t.value+"']").length){var s=C('<option value="'+t.value+'">'+t.text+"</option>"),l=(e=parseInt(void 0===t.index?i.$element.children().length:t.index),null==t.nested?i.$element:C("optgroup[label='"+t.nested+"']"));s.insertAt(