-
Notifications
You must be signed in to change notification settings - Fork 3
/
ractive-multiselect.min.js
1 lines (1 loc) · 13.2 KB
/
ractive-multiselect.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.RactiveMultiselect=t():e.RactiveMultiselect=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){r(8);var n=r(10),o=window,i=document,l="ractive-multiselect-dropdown-container";e.exports=Ractive.extend({template:r(6),isolated:!0,modifyArrays:!1,data:function(){return{selected:[],clearFilterOnSelect:!0,autoClose:!1,consume:!0,highlighted:-1,highlightedSelected:-1,open:!1,showCross:!0,allowCustom:!0}},decorators:{preventOverscroll:r(9)},events:{escape:n.escape,enter:n.enter,uparrow:n.uparrow,downarrow:n.downarrow,leftarrow:n.leftarrow,rightarrow:n.rightarrow,backspace:n.backspace,delete:n.delete},computed:{items:function(){var e=this,t=e.get("filter").toLowerCase(),r=e.get("data"),n=e.get("selected"),o=e.get("consume");if(!(r&&r instanceof Array))return null;r=r.slice().filter(function(e){if(!(o&&n.indexOf(e)>-1)){if("object"!=typeof e)return e.toLowerCase().indexOf(t)>-1;for(var r in e)if("string"==typeof e[r]&&e[r].toLowerCase().indexOf(t)>-1)return!0}});for(var i={},l=[],s=0;s<r.length;s++){var a=r[s];a.group&&(i[a.group]?i[a.group].push(a):(i[a.group]=[a],l.push(a.group)),r.splice(s,1),s--)}return l.length&&l.forEach(function(e){r=r.concat({title:e,group:!0}),r=r.concat(i[e])}),r}},partials:{selectedItem_default:r(5),_selectedItem:function(){return this.partials.selectedItem?this.partials.selectedItem:this.partials.selectedItem_default},item_default:r(4),_item:function(){return this.partials.item?this.partials.item:this.partials.item_default},group_default:r(3),_group:function(){return this.partials.group?this.partials.group:this.partials.group_default}},onrender:function(){var e=this,t=e.find(".dropdown");e.dropdown=t;var r=i.getElementById(l);r||(r=i.createElement("div"),r.id=l,r.className="ractive-multiselect",i.body.appendChild(r)),r.appendChild(t)},oncomplete:function(){var e=this,t=e.find("*"),r=e.find(".dropdown");e.clickHandler=function(n){var o=n.target;t.contains(o)||o===r||r.contains(o)||e.set("open",!1)},e.scrollHandler=function(t){requestAnimationFrame(function(){e.updateBounds()})},e.observe("open",function(t){t?(i.addEventListener("click",e.clickHandler),o.addEventListener("scroll",e.scrollHandler)):(i.removeEventListener("click",e.clickHandler),o.removeEventListener("scroll",e.scrollHandler)),e.updateBounds()}),e.on("uparrow downarrow leftarrow rightarrow enter delete",function(t){var r=e.get("open"),n=t.name,o=t.original,i=e.get("highlighted"),l=e.get("highlightedSelected"),s=e.get("items"),a=e.get("selected"),c=e.get("filter");if("uparrow"==n){if(i<=0)return;do i--;while(s[i]&&s[i].group===!0);i=Math.max(0,i),e.set("highlighted",i)}else if("downarrow"==n){do i++;while(s[i]&&s[i].group===!0);i=Math.min(s.length,i),e.set("highlighted",i)}if("leftarrow"==n){if(0===l)return;l=l===-1?a.length-1:Math.max(0,l-1),e.set("highlightedSelected",l)}if("rightarrow"==n)l=Math.min(a.length,l+1),e.set("highlightedSelected",l);else if("enter"==n)if(i!==-1)r&&(e.select(e.get("items."+i)),e.set("highlighted",-1));else{var d=e.get("allowCustom");c.length>1&&d&&e.select(c)}else if("delete"==n){var c=e.get("filter");if(c.length>0)return;l!==-1?(e.select(e.get("selected."+l)),e.set("highlightedSelected",-1),o.preventDefault()):""===c&&e.set("highlightedSelected",a.length-1)}}),e.on("keydown keyup keypress input",function(t){var r=t.original;e.fire(r.type)})},onunrender:function(){const e=this;i.removeEventListener("click",e.clickHandler),o.removeEventListener("scroll",e.scrollHandler);var t=e.find(".dropdown");t&&t.parentNode.removeChild(t);var r=i.getElementById(l);r&&0==r.childNodes.length&&r.parentNode.removeChild(r)},open:function(e){this.set("open",!0)},close:function(e){this.set("open",!1)},select:function(e){if(e){var t=this;e.keypath&&(e=t.get(e.keypath));var r=t.get("selected"),n=(t.get("items"),r.indexOf(e));e.group!==!0&&(n==-1?t.push("selected",e):t.splice("selected",n,1),t.get("clearFilterOnSelect")&&t.set("filter",""),t.get("autoClose")&&t.close(),t.update("items"),t.updateBounds())}},updateBounds:function(){var e=this,t=e.find("*"),r=e.get("open"),n=t.getBoundingClientRect();e.dropdown.style.width=n.width+"px";var o=e.dropdown;r?(o.style.left=n.left+"px",o.style.top=n.bottom+3+"px"):o.style.left="-9999px"}})},function(e,t,r){t=e.exports=r(2)(),t.push([e.id,".ractive-multiselect{display:flex;display:inline-flex;flex-wrap:wrap;cursor:default;user-multiselect:none;line-height:1;padding:.2em;background:#fff;border:1px solid #999}.ractive-multiselect,.ractive-multiselect *,.ractive-multiselect :after,.ractive-multiselect :before{box-sizing:border-box}.ractive-multiselect label{margin-right:.5em}.ractive-multiselect .item{display:inline-block;margin:.2em;background:#f0f0f0;font-size:.8em;padding:.3em .6em;border-radius:99px}.ractive-multiselect .item .cross{width:8px;height:8px;vertical-align:middle;margin-left:4px;cursor:pointer}.ractive-multiselect .item.selecting{border:1px solid #0a63c2}.ractive-multiselect input{flex:1 1 auto;background:none;border:none;box-shadow:none;outline:none;text-indent:.5em;min-height:2em}.ractive-multiselect .dropdown{margin:3px 0 0;background:#fff;color:#333;border-radius:3px;padding:2px 0;cursor:default;list-style:none;z-index:50;box-shadow:0 3px 9px rgba(0,0,0,.4);max-height:400px;overflow-y:auto}.ractive-multiselect .dropdown:not(.open){display:none}.ractive-multiselect li{padding:.3em .5em;border-top:1px solid transparent;border-bottom:1px solid transparent;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ractive-multiselect li.group{background:#f0f0f0;color:#aaa;text-align:center;padding:.4em 0;text-transform:uppercase;font-size:.8em;letter-spacing:1px}.ractive-multiselect li.group.selecting,.ractive-multiselect li.group:hover{background:#f0f0f0;color:#aaa;border-top-color:transparent;border-bottom-color:transparent}.ractive-multiselect li.selected{color:#3d96f5}.ractive-multiselect li.selecting,.ractive-multiselect li:hover{background:linear-gradient(#3d96f5,#0d7cf2);color:#fff;border-top-color:#0a63c2;border-bottom-color:#004a99}#ractive-multiselect-dropdown-container{position:absolute}#ractive-multiselect-dropdown-container .dropdown{position:fixed;left:-9999px}",""])},function(e,t){e.exports=function(){var e=[];return e.toString=function(){for(var e=[],t=0;t<this.length;t++){var r=this[t];r[2]?e.push("@media "+r[2]+"{"+r[1]+"}"):e.push(r[1])}return e.join("")},e.i=function(t,r){"string"==typeof t&&(t=[[null,t,""]]);for(var n={},o=0;o<this.length;o++){var i=this[o][0];"number"==typeof i&&(n[i]=!0)}for(o=0;o<t.length;o++){var l=t[o];"number"==typeof l[0]&&n[l[0]]||(r&&!l[2]?l[2]=r:r&&(l[2]="("+l[2]+") and ("+r+")"),e.push(l))}},e}},function(e,t){e.exports={v:4,t:[{t:2,r:"./title"}]}},function(e,t){e.exports={v:4,t:[{t:2,r:"."}]}},function(e,t){e.exports={v:4,t:[{t:2,r:"."}]}},function(e,t){e.exports={v:4,t:[{t:7,e:"div",m:[{n:"class",f:["ractive-multiselect ",{t:2,r:"class"}],t:13},{n:"style",f:[{t:2,r:"style"}],t:13}],f:[{t:4,f:[{t:7,e:"span",m:[{n:"class",f:["item ",{t:4,f:["selecting"],n:50,x:{r:["~/highlightedSelected","@index"],s:"_0==_1"}}],t:13}],f:[{t:8,r:"_selectedItem"}," ",{t:4,f:[{t:7,e:"svg",m:[{n:"class",f:"cross",t:13},{n:"click",f:{x:{r:["@this","."],s:"[_0.select(_1)]"}},t:70},{n:"xmlns",f:"http://www.w3.org/2000/svg",t:13},{n:"viewBox",f:"0 0 12 12",t:13}],f:[{t:7,e:"path",m:[{n:"d",f:"M8.432 6l3.442-3.442a.433.433 0 0 0 0-.61L10.05.126a.43.43 0 0 0-.607 0L6 3.568 2.557.125a.432.432 0 0 0-.608 0L.124 1.95a.433.433 0 0 0 0 .608L3.568 6 .126 9.442a.432.432 0 0 0 0 .608l1.824 1.825c.167.166.44.166.608 0L6 8.432l3.442 3.443c.167.166.44.166.608 0l1.824-1.825a.432.432 0 0 0 0-.608L8.432 6z",t:13}]}]}],n:50,r:"showCross"}]}],n:52,r:"selected"}," ",{t:7,e:"input",m:[{n:"type",f:"text",t:13},{n:"value",f:[{t:2,r:".filter"}],t:13},{n:"placeholder",f:[{t:2,x:{r:["placeholder"],s:'_0||"Select an item..."'}}],t:13},{n:"focus",f:{x:{r:["@this"],s:"[_0.open()]"}},t:70},{n:"uparrow",f:"uparrow",t:70},{n:"downarrow",f:"downarrow",t:70},{n:"leftarrow",f:"leftarrow",t:70},{n:"rightarrow",f:"rightarrow",t:70},{n:"enter",f:"enter",t:70},{n:"input",f:"input",t:70},{n:"keyup",f:"keyup",t:70},{n:"keydown",f:"keydown",t:70},{n:"keypress",f:"keypress",t:70},{n:"backspace-delete",f:"delete",t:70}]}," ",{t:7,e:"ul",m:[{n:"class",f:["dropdown",{t:4,f:[" open"],n:50,x:{r:["items","items.length","open"],s:"_0&&_1&&_2"}}," ",{t:2,r:"class"}],t:13},{f:"preventOverscroll",t:71}],f:[{t:4,f:[{t:7,e:"li",m:[{n:"class",f:[{t:4,f:["selecting"],n:50,x:{r:["~/highlighted","@index"],s:"_0==_1"}}," ",{t:4,f:["selected"],n:50,x:{r:["~/selected","."],s:"_0.indexOf(_1)>-1"}}," ",{t:4,f:["group"],n:50,x:{r:[".group"],s:"_0===true"}}],t:13},{n:"click",f:{x:{r:["@this","event"],s:"[_0.select(_1)]"}},t:70}],f:[{t:4,f:[{t:8,r:"_group"}],n:50,x:{r:["./group"],s:"_0===true"}},{t:4,n:51,f:[{t:8,r:"_item"}],l:1}]}],n:52,r:"items"}]}]}],e:{}}},function(e,t,r){function n(e,t){for(var r=0;r<e.length;r++){var n=e[r],o=p[n.id];if(o){o.refs++;for(var i=0;i<o.parts.length;i++)o.parts[i](n.parts[i]);for(;i<n.parts.length;i++)o.parts.push(c(n.parts[i],t))}else{for(var l=[],i=0;i<n.parts.length;i++)l.push(c(n.parts[i],t));p[n.id]={id:n.id,refs:1,parts:l}}}}function o(e){for(var t=[],r={},n=0;n<e.length;n++){var o=e[n],i=o[0],l=o[1],s=o[2],a=o[3],c={css:l,media:s,sourceMap:a};r[i]?r[i].parts.push(c):t.push(r[i]={id:i,parts:[c]})}return t}function i(e,t){var r=m(),n=x[x.length-1];if("top"===e.insertAt)n?n.nextSibling?r.insertBefore(t,n.nextSibling):r.appendChild(t):r.insertBefore(t,r.firstChild),x.push(t);else{if("bottom"!==e.insertAt)throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");r.appendChild(t)}}function l(e){e.parentNode.removeChild(e);var t=x.indexOf(e);t>=0&&x.splice(t,1)}function s(e){var t=document.createElement("style");return t.type="text/css",i(e,t),t}function a(e){var t=document.createElement("link");return t.rel="stylesheet",i(e,t),t}function c(e,t){var r,n,o;if(t.singleton){var i=w++;r=g||(g=s(t)),n=d.bind(null,r,i,!1),o=d.bind(null,r,i,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(r=a(t),n=f.bind(null,r),o=function(){l(r),r.href&&URL.revokeObjectURL(r.href)}):(r=s(t),n=u.bind(null,r),o=function(){l(r)});return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else o()}}function d(e,t,r,n){var o=r?"":n.css;if(e.styleSheet)e.styleSheet.cssText=b(t,o);else{var i=document.createTextNode(o),l=e.childNodes;l[t]&&e.removeChild(l[t]),l.length?e.insertBefore(i,l[t]):e.appendChild(i)}}function u(e,t){var r=t.css,n=t.media;if(n&&e.setAttribute("media",n),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}function f(e,t){var r=t.css,n=t.sourceMap;n&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */");var o=new Blob([r],{type:"text/css"}),i=e.href;e.href=URL.createObjectURL(o),i&&URL.revokeObjectURL(i)}var p={},h=function(e){var t;return function(){return"undefined"==typeof t&&(t=e.apply(this,arguments)),t}},v=h(function(){return/msie [6-9]\b/.test(self.navigator.userAgent.toLowerCase())}),m=h(function(){return document.head||document.getElementsByTagName("head")[0]}),g=null,w=0,x=[];e.exports=function(e,t){t=t||{},"undefined"==typeof t.singleton&&(t.singleton=v()),"undefined"==typeof t.insertAt&&(t.insertAt="bottom");var r=o(e);return n(r,t),function(e){for(var i=[],l=0;l<r.length;l++){var s=r[l],a=p[s.id];a.refs--,i.push(a)}if(e){var c=o(e);n(c,t)}for(var l=0;l<i.length;l++){var a=i[l];if(0===a.refs){for(var d=0;d<a.parts.length;d++)a.parts[d]();delete p[a.id]}}}};var b=function(){var e=[];return function(t,r){return e[t]=r,e.filter(Boolean).join("\n")}}()},function(e,t,r){var n=r(1);"string"==typeof n&&(n=[[e.id,n,""]]);r(7)(n,{});n.locals&&(e.exports=n.locals)},function(e,t){var r=window,n=document;e.exports=function(e,t){function o(t){if(t=t||r.event,e.scrollTop<=1&&t.deltaY<0||e.scrollTop>=s&&t.deltaY>0)return t.preventDefault&&t.preventDefault(),t.returnValue=!1,!1}function i(){s=e.scrollHeight-e.offsetHeight-1,r.addEventListener("DOMMouseScroll",o,!1),r.addEventListener("wheel",o),r.addEventListener("mousewheel",o),n.addEventListener("mousewheel",o),r.addEventListener("touchmove",o)}function l(){r.removeEventListener("DOMMouseScroll",o,!1),r.removeEventListener("wheel",o),r.removeEventListener("mousewheel",o),n.removeEventListener("mousewheel",o),r.removeEventListener("touchmove",o)}e.addEventListener("mouseenter",i),e.addEventListener("mouseleave",l),e.addEventListener("click",l);var s;return{teardown:function(){e.removeEventListener("mouseenter",i),e.removeEventListener("mouseleave",l)}}}},function(e,t){function r(e){return function(t,r){function n(n){var o=n.which||n.keyCode;o===e&&r({node:t,original:n})}return t.addEventListener("keydown",n,!1),{teardown:function(){t.removeEventListener("keydown",n,!1)}}}}e.exports={enter:r(13),tab:r(9),escape:r(27),space:r(32),leftarrow:r(37),rightarrow:r(39),downarrow:r(40),uparrow:r(38),backspace:r(8),delete:r(46)}}])});