(function(t){t.fn.niceSelect=function(c){function o(s){s.after(t("<div></div>").addClass("nice-select").addClass(s.attr("class")||"").addClass(s.attr("disabled")?"disabled":"").attr("tabindex",s.attr("disabled")?null:"0").html('<span class="current"></span><ul class="list"></ul>'));var e=s.next(),n=s.find("option"),i=s.find("option:selected");e.find(".current").html(i.data("display")||i.text()),n.each(function(a){var l=t(this),r=l.data("display");e.find("ul").append(t("<li></li>").attr("data-value",l.val()).attr("data-display",r||null).addClass("option"+(l.is(":selected")?" selected":"")+(l.is(":disabled")?" disabled":"")).html(l.text()))})}if(typeof c=="string")return c=="update"?this.each(function(){var s=t(this),e=t(this).next(".nice-select"),n=e.hasClass("open");e.length&&(e.remove(),o(s),n&&s.next().trigger("click"))}):c=="destroy"?(this.each(function(){var s=t(this),e=t(this).next(".nice-select");e.length&&(e.remove(),s.css("display",""))}),t(".nice-select").length==0&&t(document).off(".nice_select")):console.log('Method "'+c+'" does not exist.'),this;this.hide(),this.each(function(){var s=t(this);s.next().hasClass("nice-select")||o(s)}),t(document).off(".nice_select"),t(document).on("click.nice_select",".nice-select",function(s){var e=t(this);t(".nice-select").not(e).removeClass("open"),e.toggleClass("open"),e.hasClass("open")?(e.find(".option"),e.find(".focus").removeClass("focus"),e.find(".selected").addClass("focus")):e.focus()}),t(document).on("click.nice_select",function(s){t(s.target).closest(".nice-select").length===0&&t(".nice-select").removeClass("open").find(".option")}),t(document).on("click.nice_select",".nice-select .option:not(.disabled)",function(s){var e=t(this),n=e.closest(".nice-select");n.find(".selected").removeClass("selected"),e.addClass("selected");var i=e.data("display")||e.text();n.find(".current").text(i),n.prev("select").val(e.data("value")).trigger("change")}),t(document).on("keydown.nice_select",".nice-select",function(s){var e=t(this),n=t(e.find(".focus")||e.find(".list .option.selected"));if(s.keyCode==32||s.keyCode==13)return e.hasClass("open")?n.trigger("click"):e.trigger("click"),!1;if(s.keyCode==40){if(e.hasClass("open")){var i=n.nextAll(".option:not(.disabled)").first();i.length>0&&(e.find(".focus").removeClass("focus"),i.addClass("focus"))}else e.trigger("click");return!1}if(s.keyCode==38){if(e.hasClass("open")){var a=n.prevAll(".option:not(.disabled)").first();a.length>0&&(e.find(".focus").removeClass("focus"),a.addClass("focus"))}else e.trigger("click");return!1}if(s.keyCode==27)e.hasClass("open")&&e.trigger("click");else if(s.keyCode==9&&e.hasClass("open"))return!1});var d=document.createElement("a").style;return d.cssText="pointer-events:auto",d.pointerEvents!=="auto"&&t("html").addClass("no-csspointerevents"),this}})(jQuery);
