(function(){!function(t){var e;return null==t.gl&&(t.gl={}),null==(e=t.gl).text&&(e.text={}),gl.text.addDelimiter=function(t){return t?t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","):t},gl.text.randomString=function(){return Math.random().toString(36).substring(7)},gl.text.replaceRange=function(t,e,n,r){return t.substring(0,e)+r+t.substring(n)},gl.text.selectedText=function(t,e){return t.substring(e.selectionStart,e.selectionEnd)},gl.text.lineBefore=function(t,e){var n;return n=t.substring(0,e.selectionStart).trim().split("\n"),n[n.length-1]},gl.text.lineAfter=function(t,e){return t.substring(e.selectionEnd).trim().split("\n")[0]},gl.text.blockTagText=function(t,e,n,r){var i,l;return l=this.lineBefore(t,e),i=this.lineAfter(t,e),l===n&&i===n?(null!=n&&(e.selectionStart=e.selectionStart-(n.length+1),e.selectionEnd=e.selectionEnd+(n.length+1)),r):n+"\n"+r+"\n"+n},gl.text.insertText=function(t,e,n,r,i,l){var o,c,s,u;if(s=i.split("\n"),u=!l&&t.selectionStart>0?"\n":"",o=s.length>1&&(!l||null!=r)?null!=r?this.blockTagText(e,t,r,i):s.map(function(t){return 0===t.indexOf(n)?""+t.replace(n,""):""+n+t}).join("\n"):""+u+n+i+(l?n:" "),document.queryCommandSupported("insertText")&&(c=document.execCommand("insertText",!1,o)),!c){try{document.execCommand("ms-beginUndoUnit")}catch(a){}t.value=this.replaceRange(e,t.selectionStart,t.selectionEnd,o);try{document.execCommand("ms-endUndoUnit")}catch(a){}}return this.moveCursor(t,n,l)},gl.text.moveCursor=function(t,e,n){var r;if(t.setSelectionRange)return t.selectionStart===t.selectionEnd?(r=n?t.selectionStart-e.length:t.selectionStart,t.setSelectionRange(r,r)):void 0},gl.text.updateText=function(t,e,n,r){var i,l,o,c;return i=$(t),l=i.val(),t=i.get(0),c=i.val(),o=this.selectedText(c,t),i.focus(),this.insertText(t,c,e,n,o,r)},gl.text.init=function(t){var e;return e=this,$(".js-md",t).off("click").on("click",function(){var t;return t=$(this),e.updateText(t.closest(".md-area").find("textarea"),t.data("md-tag"),t.data("md-block"),!t.data("md-prepend"))})},gl.text.removeListeners=function(t){return $(".js-md",t).off()},gl.text.humanize=function(t){return t.charAt(0).toUpperCase()+t.replace(/_/g," ").slice(1)},gl.text.truncate=function(t,e){return t.substr(0,e-3)+"..."}}(window)}).call(this);