-
Notifications
You must be signed in to change notification settings - Fork 16
/
listgroup.min.js
8 lines (8 loc) · 2.49 KB
/
listgroup.min.js
1
2
3
4
5
6
7
8
/*!========================================================================
* listgroup.js v1.1.2
* http://rickardn.github.io/listgroup.js
* ========================================================================
* Copyright 2014 Rickard Nilsson
* Licensed under MIT (https://github.com/rickardn/listgroup.js/blob/master/LICENSE)
* ======================================================================== */
+function(n){"use strict";var i=function(t,i){this.$element=n(t);this.options=i||{};this.init()},t;i.prototype.init=function(){var r=this,i=this.$element,t=this.options;t.toggle&&i.attr("data-toggle",t.toggle);i.on("click",".list-group-item",function(){var u=n(this);return u.hasClass("disabled")||(i.data("toggle")=="items"?u.toggleClass("active"):r.unselect("*").select(u),t.click&&t.click.apply(this)),u.blur(),!1})};i.prototype.select=function(t){var i,r;if(t instanceof n&&t.addClass("active"),typeof t=="string"&&(t=[t]),Array.isArray(t))for(i in t)r=t[i],this.$element.find(".list-group-item[data-value='"+r+"']").addClass("active");return this};i.prototype.unselect=function(n){return this.$element.find(".list-group-item").filter(n||"*").removeClass("active"),this};t=function(t,i){this.$element=n(t);this.options=i;this.$listGroup=this.createListGroup()};t.prototype.select=function(t){if(t instanceof n){var i=[];t.each(function(t,r){i.push(n(r).val())});t=i}this.$element.val(t).change()};t.prototype.unselect=function(n){var t=this.$element.val(),i;Array.isArray(t)||(t=[t]);Array.isArray(n)||(n=[n]);for(i in n)t.pop(n[i]);this.$element.val(t).change()};t.prototype.createListGroup=function(){var t=this.$element,i=n("<ul>").addClass("list-group");return t.attr("multiple")&&i.attr("data-toggle","items"),t.find("option").each(function(t,r){var u=n(r),f=n("<a>").attr("href","#").addClass("list-group-item").attr("data-value",u.val()).text(u.text());u.is(":disabled")&&f.addClass("disabled");u.css("display")==="none"&&f.addClass("hidden");i.append(f)}),t.change(function(){i.listgroup({unselect:"*",select:t.val()})}),i.listgroup({select:t.val(),click:function(){var r=[];i.find(".list-group-item.active").each(function(t,i){var u=n(i).data("value");r.push(u)});r.length==1&&(r=r[0]);t.val(r)}}),t.before(i),this.$listGroup=i,t.hide(),i};n.fn.listgroup=function(r){return this.each(function(u,f){var o=n(f),e=o.data("listgroup");e||o.data("listgroup",e=o.is("select")?new t(f,r):new i(f,r));r&&(r.unselect&&e.unselect(r.unselect),r.select&&e.select(r.select))})};n(function(){n(".list-group").listgroup()})}(jQuery);