text: /*
   *  multiline-control - v1.0.0
   *  Form control that allows to edit multiple lines, change order, remove lines.
   *  
   *
   *  Made by Vedmant
   *  Under MIT License
   */
  !function(a,b,c,d){"use strict";function e(b,c){this._name=g,this.$element=a(b);var d=f(this.$element.data("options"));this.defaults=h,this.options=a.extend({},h,c),this.options=a.extend({},this.options,d),this.init()}function f(a){if(a===d)return[];var b=[];return a.split(";").forEach(function(a){var c=a.split(":");2===c.length&&(b[c[0].trim()]=c[1].trim())}),b}var g="multiline_control",h={sortable:!0,templateContainer:'<div class="multiline-control"></div>',templateAddBtn:'<a href="#" class="mc-add-btn btn btn-success btn"><i class="glyphicon glyphicon-plus"></i></a>',templateLine:'<div class="form-group mc-row"><div class="input-group">{sorting_handle}<input type="text" class="form-control" name="{name}" value="{value}"><a href="#" class="input-group-addon btn btn-default btn-sm mc-remove-btn"><i class="glyphicon glyphicon-remove"></i></a></div></div>',templateHandle:'<div class="input-group-addon mc-handle" style="cursor: move;"><i class="glyphicon glyphicon-move"></i></div>',templateSortablePlaceholder:'<div class="mc-sortable-placeholder form-group form-control" style="border: 1px dashed blue;"></div>',onChange:a.noop};a.extend(e.prototype,{init:function(){var a=this;this.$element.hide(),this.buildTemplate(),this.bindEvents(),this.options.sortable&&this.initSorting();var b=this.$element.val().split(/\n/);b.forEach(function(b){""!==b&&a.addLine(b)})},buildTemplate:function(){this.$container=a(this.options.templateContainer),this.$element.after(this.$container),this.$addBtn=a(this.options.templateAddBtn),this.$container.after(this.$addBtn)},bindEvents:function(){var b=this;this.$addBtn.click(function(a){a.preventDefault(),b.addLine(),b.$container.find("input").last().focus()}),this.$container.on("click",".mc-remove-btn",function(c){c.preventDefault(),b.removeLine(a(this))}),this.$container.on("blur","input",function(){b.updateTextarea()}),this.$container.on("keydown","input",function(c){switch(c.which){case 13:return b.addLine("",a(c.target)).find("input").focus(),!1;case 8:if(""===a(c.target).val())return a(c.target).closest(".mc-row").prev().find("input").focus(),b.removeLine(a(c.target)),!1}})},initSorting:function(){var b,c,d=this,e=!1,f=a(this.options.templateSortablePlaceholder);this.$container.on("mousedown",".mc-handle",function(){e=!0}),this.$container.on("dragstart",".mc-row",function(d){if(e){b=(c=a(this)).addClass("mc-sortable-dragging").index();var f=d.originalEvent.dataTransfer;f.effectAllowed="move",f.setData("Text","dummy")}else d.preventDefault()}),this.$container.on("dragend",".mc-row",function(){e=!1,c&&(c.removeClass("mc-sortable-dragging").show(),f.detach(),b!==c.index()&&(c.parent().trigger("sortupdate",{item:c}),d.updateTextarea()),c=null)}),this.$container.on("dragover dragenter",".mc-row",function(b){var d=a(this);b.preventDefault(),b.originalEvent.dataTransfer.dropEffect="move",c.hide(),f.index()<d.index()?d.after(f):d.before(f)}),this.$container.on("drop",".mc-row, .mc-sortable-placeholder",function(a){return a.stopPropagation(),f.after(c),c.trigger("dragend"),!1}),this.$container.on("dragleave dragover",".mc-row, .mc-sortable-placeholder",function(a){a.preventDefault(),a.stopPropagation()})},updateTextarea:function(){var b="";this.$container.find("input").each(function(){""!==a(this).val()&&(b+=a(this).val()+"\n")}),this.$element.val(b),this.options.onChange(b)},addLine:function(b,c){"undefined"==typeof b&&(b="");var d=this.options.templateLine.replace("{value}",b).replace("{name}",this.$element.attr("name")+"_mc[]");d=d.replace("{sorting_handle}",this.options.sortable?this.options.templateHandle:"");var e=a(d);return this.options.sortable&&e.attr("draggable","true"),"undefined"!=typeof c?c.closest(".mc-row").after(e):this.$container.append(e),e},removeLine:function(a){a.closest(".mc-row").remove(),this.updateTextarea()},destroy:function(){this.$container.remove(),this.$addBtn.remove(),this.$element.show(),this.$element.removeData("plugin_"+this._name)},empty:function(){this.$container.find(".mc-row").remove()},update:function(a){var b=this;this.empty();var c=a.split(/\n/);c.forEach(function(a){""!==a&&b.addLine(a)})},getDefaults:function(){return this.defaults}}),a.fn[g]=function(b){var c=[].slice.call(arguments,1);return this.each(function(){a.data(this,"plugin_"+g)?a.isFunction(e.prototype[b])&&a.data(this,"plugin_"+g)[b].apply(a.data(this,"plugin_"+g),c):a.data(this,"plugin_"+g,new e(this,b))})}}(jQuery,window,document);