text: !function(t){"use strict";function e(e,i){this.itemsArray=[],this.$element=t(e),this.$element.hide(),this.isSelect="SELECT"===e.tagName,this.multiple=this.isSelect&&e.hasAttribute("multiple"),this.objectItems=i&&i.itemValue,this.placeholderText=e.hasAttribute("placeholder")?this.$element.attr("placeholder"):"",this.inputSize=Math.max(1,this.placeholderText.length),this.$container=t('<div class="bootstrap-tagsinput"></div>'),this.$input=t('<input size="'+this.inputSize+'" type="text" placeholder="'+this.placeholderText+'"/>').appendTo(this.$container),this.$element.after(this.$container),this.build(i)}function i(t,e){if("function"!=typeof t[e]){var i=t[e];t[e]=function(t){return t[i]}}}function n(t,e){if("function"!=typeof t[e]){var i=t[e];t[e]=function(){return i}}}function a(t){return t?s.text(t).html():""}function o(t){var e=0;if(document.selection){t.focus();var i=document.selection.createRange();i.moveStart("character",-t.value.length),e=i.text.length}else(t.selectionStart||"0"==t.selectionStart)&&(e=t.selectionStart);return e}var r={tagClass:function(){return"label label-info"},itemValue:function(t){return t?t.toString():t},itemText:function(t){return this.itemValue(t)},freeInput:!0,maxTags:void 0,confirmKeys:[13],onTagExists:function(t,e){e.hide().fadeIn()}};e.prototype={constructor:e,add:function(e,i){var n=this;if(!(n.options.maxTags&&n.itemsArray.length>=n.options.maxTags||e!==!1&&!e)){if("object"==typeof e&&!n.objectItems)throw"Can't add objects when itemValue option is not set";if(!e.toString().match(/^\s*$/)){if(n.isSelect&&!n.multiple&&n.itemsArray.length>0&&n.remove(n.itemsArray[0]),"string"==typeof e&&"INPUT"===this.$element[0].tagName){var o=e.split(",");if(o.length>1){for(var r=0;r<o.length;r++)this.add(o[r],!0);return void(i||n.pushVal())}}var s=n.options.itemValue(e),u=n.options.itemText(e),c=n.options.tagClass(e),l=t.grep(n.itemsArray,function(t){return n.options.itemValue(t)===s})[0];if(l){if(n.options.onTagExists){var p=t(".tag",n.$container).filter(function(){return t(this).data("item")===l});n.options.onTagExists(e,p)}}else{n.itemsArray.push(e);var m=t('<span class="tag '+a(c)+'">'+a(u)+'<span data-role="remove"></span></span>');if(m.data("item",e),n.findInputWrapper().before(m),m.after(" "),n.isSelect&&!t('option[value="'+escape(s)+'"]',n.$element)[0]){var h=t("<option selected>"+a(u)+"</option>");h.data("item",e),h.attr("value",s),n.$element.append(h)}i||n.pushVal(),n.options.maxTags===n.itemsArray.length&&n.$container.addClass("bootstrap-tagsinput-max"),n.$element.trigger(t.Event("itemAdded",{item:e}))}}}},remove:function(e,i){var n=this;n.objectItems&&(e="object"==typeof e?t.grep(n.itemsArray,function(t){return n.options.itemValue(t)==n.options.itemValue(e)})[0]:t.grep(n.itemsArray,function(t){return n.options.itemValue(t)==e})[0]),e&&(t(".tag",n.$container).filter(function(){return t(this).data("item")===e}).remove(),t("option",n.$element).filter(function(){return t(this).data("item")===e}).remove(),n.itemsArray.splice(t.inArray(e,n.itemsArray),1)),i||n.pushVal(),n.options.maxTags>n.itemsArray.length&&n.$container.removeClass("bootstrap-tagsinput-max"),n.$element.trigger(t.Event("itemRemoved",{item:e}))},removeAll:function(){var e=this;for(t(".tag",e.$container).remove(),t("option",e.$element).remove();e.itemsArray.length>0;)e.itemsArray.pop();e.pushVal(),e.options.maxTags&&!this.isEnabled()&&this.enable()},refresh:function(){var e=this;t(".tag",e.$container).each(function(){var i=t(this),n=i.data("item"),o=e.options.itemValue(n),r=e.options.itemText(n),s=e.options.tagClass(n);if(i.attr("class",null),i.addClass("tag "+a(s)),i.contents().filter(function(){return 3==this.nodeType})[0].nodeValue=a(r),e.isSelect){var u=t("option",e.$element).filter(function(){return t(this).data("item")===n});u.attr("value",o)}})},items:function(){return this.itemsArray},pushVal:function(){var e=this,i=t.map(e.items(),function(t){return e.options.itemValue(t).toString()});e.$element.val(i,!0).trigger("change")},build:function(e){var a=this;a.options=t.extend({},r,e);var s=a.options.typeahead||{};a.objectItems&&(a.options.freeInput=!1),i(a.options,"itemValue"),i(a.options,"itemText"),i(a.options,"tagClass"),a.options.source&&(s.source=a.options.source),s.source&&t.fn.typeahead&&(n(s,"source"),a.$input.typeahead({source:function(e,i){function n(t){for(var e=[],n=0;n<t.length;n++){var r=a.options.itemText(t[n]);o[r]=t[n],e.push(r)}i(e)}this.map={};var o=this.map,r=s.source(e);t.isFunction(r.success)?r.success(n):t.when(r).then(n)},updater:function(t){a.add(this.map[t])},matcher:function(t){return-1!==t.toLowerCase().indexOf(this.query.trim().toLowerCase())},sorter:function(t){return t.sort()},highlighter:function(t){var e=new RegExp("("+this.query+")","gi");return t.replace(e,"<strong>$1</strong>")}})),a.$container.on("click",t.proxy(function(){a.$input.focus()},a)),a.$container.on("keydown","input",t.proxy(function(e){var i=t(e.target),n=a.findInputWrapper();switch(e.which){case 8:if(0===o(i[0])){var r=n.prev();r&&a.remove(r.data("item"))}break;case 46:if(0===o(i[0])){var s=n.next();s&&a.remove(s.data("item"))}break;case 37:var u=n.prev();0===i.val().length&&u[0]&&(u.before(n),i.focus());break;case 39:var c=n.next();0===i.val().length&&c[0]&&(c.after(n),i.focus());break;default:a.options.freeInput&&t.inArray(e.which,a.options.confirmKeys)>=0&&(a.add(i.val()),i.val(""),e.preventDefault())}i.attr("size",Math.max(this.inputSize,i.val().length))},a)),a.$container.on("click","[data-role=remove]",t.proxy(function(e){a.remove(t(e.target).closest(".tag").data("item"))},a)),a.options.itemValue===r.itemValue&&("INPUT"===a.$element[0].tagName?a.add(a.$element.val()):t("option",a.$element).each(function(){a.add(t(this).attr("value"),!0)}))},destroy:function(){var t=this;t.$container.off("keypress","input"),t.$container.off("click","[role=remove]"),t.$container.remove(),t.$element.removeData("tagsinput"),t.$element.show()},focus:function(){this.$input.focus()},input:function(){return this.$input},findInputWrapper:function(){for(var e=this.$input[0],i=this.$container[0];e&&e.parentNode!==i;)e=e.parentNode;return t(e)}},t.fn.tagsinput=function(i,n){var a=[];return this.each(function(){var o=t(this).data("tagsinput");if(o){var r=o[i](n);void 0!==r&&a.push(r)}else o=new e(this,i),t(this).data("tagsinput",o),a.push(o),"SELECT"===this.tagName&&t("option",t(this)).attr("selected","selected"),t(this).val(t(this).val())}),"string"==typeof i?a.length>1?a:a[0]:a},t.fn.tagsinput.Constructor=e;var s=t("<div />");t(function(){t("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput()})}(window.jQuery);