text: /*! UIkit 2.8.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
  
  !function(a){var b;jQuery&&jQuery.UIkit&&(b=a(jQuery,jQuery.UIkit)),"function"==typeof define&&define.amd&&define("uikit-htmleditor",["uikit"],function(){return b||a(jQuery,jQuery.UIkit)})}(function(a,b){var c=[];return b.component("htmleditor",{defaults:{mode:"split",markdown:!1,autocomplete:!0,height:500,maxsplitsize:1e3,markedOptions:{gfm:!0,tables:!0,breaks:!0,pedantic:!0,sanitize:!1,smartLists:!0,smartypants:!1,langPrefix:"lang-"},codemirror:{mode:"htmlmixed",tabMode:"indent",tabsize:4,lineWrapping:!0,dragDrop:!1,autoCloseTags:!0,matchTags:!0,autoCloseBrackets:!0,matchBrackets:!0,indentUnit:4,hintOptions:{completionSingle:!1}},toolbar:["bold","italic","strike","link","image","blockquote","listUl","listOl"],lblPreview:"Preview",lblCodeview:"HTML",lblMarkedview:"Markdown"},init:function(){var d=this,e=b.components.htmleditor.template;this.CodeMirror=this.options.CodeMirror||CodeMirror,this.buttons={},e=e.replace(/\{:lblPreview\}/g,this.options.lblPreview),e=e.replace(/\{:lblCodeview\}/g,this.options.lblCodeview),this.htmleditor=a(e),this.content=this.htmleditor.find(".uk-htmleditor-content"),this.toolbar=this.htmleditor.find(".uk-htmleditor-toolbar"),this.preview=this.htmleditor.find(".uk-htmleditor-preview").children().eq(0),this.code=this.htmleditor.find(".uk-htmleditor-code"),this.element.before(this.htmleditor).appendTo(this.code),this.editor=this.CodeMirror.fromTextArea(this.element[0],this.options.codemirror),this.editor.htmleditor=this,this.editor.on("change",b.Utils.debounce(function(){d.render()},150)),this.editor.on("change",function(){d.editor.save()}),this.code.find(".CodeMirror").css("height",this.options.height),a(window).on("resize",b.Utils.debounce(function(){d.fit()},200));var f=d.preview.parent(),g=this.code.find(".CodeMirror-sizer"),h=this.code.find(".CodeMirror-scroll").on("scroll",b.Utils.debounce(function(){if("tab"!=d.htmleditor.attr("data-mode")){var a=g.height()-h.height(),b=f[0].scrollHeight-f.height(),c=b/a,e=h.scrollTop()*c;f.scrollTop(e)}},10));this.htmleditor.on("click",".uk-htmleditor-button-code, .uk-htmleditor-button-preview",function(b){b.preventDefault(),"tab"==d.htmleditor.attr("data-mode")&&(d.htmleditor.find(".uk-htmleditor-button-code, .uk-htmleditor-button-preview").removeClass("uk-active").filter(this).addClass("uk-active"),d.activetab=a(this).hasClass("uk-htmleditor-button-code")?"code":"preview",d.htmleditor.attr("data-active-tab",d.activetab),d.editor.refresh())}),this.htmleditor.on("click","a[data-htmleditor-button]",function(){d.code.is(":visible")&&d.trigger("action."+a(this).data("htmleditor-button"),[d.editor])}),this.preview.parent().css("height",this.code.height()),this.options.autocomplete&&this.CodeMirror.showHint&&this.CodeMirror.hint&&this.CodeMirror.hint.html&&this.editor.on("inputRead",b.Utils.debounce(function(){var a=d.editor.getDoc(),b=a.getCursor(),c=d.CodeMirror.innerMode(d.editor.getMode(),d.editor.getTokenAt(b).state).mode.name;if("xml"==c){var e=d.editor.getCursor(),f=d.editor.getTokenAt(e);("<"==f.string.charAt(0)||"attribute"==f.type)&&d.CodeMirror.showHint(d.editor,d.CodeMirror.hint.html,{completeSingle:!1})}},100)),this.debouncedRedraw=b.Utils.debounce(function(){d.redraw()},5),this.on("init",function(){d.redraw()}),c.push(this)},addButton:function(a,b){this.buttons[a]=b},addButtons:function(b){a.extend(this.buttons,b)},replaceInPreview:function(a,b){function c(a){var b=d.getValue().substring(0,a).split("\n");return{line:b.length-1,ch:b[b.length-1].length}}var d=this.editor,e=[],f=d.getValue(),g=-1;return this.currentvalue=this.currentvalue.replace(a,function(){g=f.indexOf(arguments[0],++g);var a={matches:arguments,from:c(g),to:c(g+arguments[0].length),replace:function(b){d.replaceRange(b,a.from,a.to)},inRange:function(b){return b.line===a.from.line&&b.line===a.to.line?b.ch>=a.from.ch&&b.ch<a.to.ch:b.line===a.from.line&&b.ch>=a.from.ch||b.line>a.from.line&&b.line<a.to.line||b.line===a.to.line&&b.ch<a.to.ch}},h=b(a);return 0==h?arguments[0]:(e.push(a),h)}),e},_buildtoolbar:function(){if(this.options.toolbar&&this.options.toolbar.length){var a=this,b=[];this.toolbar.empty(),this.options.toolbar.forEach(function(c){if(a.buttons[c]){var d=a.buttons[c].title?a.buttons[c].title:c;b.push('<li><a data-htmleditor-button="'+c+'" title="'+d+'" data-uk-tooltip>'+a.buttons[c].label+"</a></li>")}}),this.toolbar.html(b.join("\n"))}},fit:function(){var a=this.options.mode;"split"==a&&this.htmleditor.width()<this.options.maxsplitsize&&(a="tab"),"tab"==a&&(this.activetab||(this.activetab="code",this.htmleditor.attr("data-active-tab",this.activetab)),this.htmleditor.find(".uk-htmleditor-button-code, .uk-htmleditor-button-preview").removeClass("uk-active").filter("code"==this.activetab?".uk-htmleditor-button-code":".uk-htmleditor-button-preview").addClass("uk-active")),this.editor.refresh(),this.preview.parent().css("height",this.code.height()),this.htmleditor.attr("data-mode",a)},redraw:function(){this._buildtoolbar(),this.render(),this.fit()},getMode:function(){return this.editor.getOption("mode")},getCursorMode:function(){var a={mode:"html"};return this.trigger("cursorMode",[a]),a.mode},render:function(){return this.currentvalue=this.editor.getValue(),this.currentvalue?(this.trigger("render",[this]),this.trigger("renderLate",[this]),void this.preview.html(this.currentvalue)):(this.element.val(""),void this.preview.html(""))},addShortcut:function(b,c){var d={};return a.isArray(b)||(b=[b]),b.forEach(function(a){d[a]=c}),this.editor.addKeyMap(d),d},addShortcutAction:function(a,b){var c=this;this.addShortcut(b,function(){c.element.trigger("action."+a,[c.editor])})},replaceSelection:function(a){var b=this.editor.getSelection();if(!b.length){for(var c=this.editor.getCursor(),d=this.editor.getLine(c.line),e=c.ch,f=e;f<d.length&&/[\w$]+/.test(d.charAt(f));)++f;for(;e&&/[\w$]+/.test(d.charAt(e-1));)--e;var g=e!=f&&d.slice(e,f);g&&(this.editor.setSelection({line:c.line,ch:e},{line:c.line,ch:f}),b=g)}var h=a.replace("$1",b);this.editor.replaceSelection(h,"end"),this.editor.focus()},replaceLine:function(a){var b=this.editor.getDoc().getCursor(),c=this.editor.getLine(b.line),d=a.replace("$1",c);this.editor.replaceRange(d,{line:b.line,ch:0},{line:b.line,ch:c.length}),this.editor.setCursor({line:b.line,ch:d.length}),this.editor.focus()},save:function(){this.editor.save()}}),b.components.htmleditor.template=['<div class="uk-htmleditor uk-clearfix" data-mode="split">','<div class="uk-htmleditor-navbar">','<ul class="uk-htmleditor-navbar-nav uk-htmleditor-toolbar"></ul>','<div class="uk-htmleditor-navbar-flip">','<ul class="uk-htmleditor-navbar-nav">','<li class="uk-htmleditor-button-code"><a>{:lblCodeview}</a></li>','<li class="uk-htmleditor-button-preview"><a>{:lblPreview}</a></li>','<li><a data-htmleditor-button="fullscreen"><i class="uk-icon-expand"></i></a></li>',"</ul>","</div>","</div>",'<div class="uk-htmleditor-content">','<div class="uk-htmleditor-code"></div>','<div class="uk-htmleditor-preview"><div></div></div>',"</div>","</div>"].join(""),b.plugin("htmleditor","base",{init:function(a){function c(b,c,d){a.on("action."+b,function(){"html"==a.getCursorMode()&&a["replaceLine"==d?"replaceLine":"replaceSelection"](c)})}a.addButtons({fullscreen:{title:"Fullscreen",label:'<i class="uk-icon-expand"></i>'},bold:{title:"Bold",label:'<i class="uk-icon-bold"></i>'},italic:{title:"Italic",label:'<i class="uk-icon-italic"></i>'},strike:{title:"Strikethrough",label:'<i class="uk-icon-strikethrough"></i>'},blockquote:{title:"Blockquote",label:'<i class="uk-icon-quote-right"></i>'},link:{title:"Link",label:'<i class="uk-icon-link"></i>'},image:{title:"Image",label:'<i class="uk-icon-picture-o"></i>'},listUl:{title:"Unordered List",label:'<i class="uk-icon-list-ul"></i>'},listOl:{title:"Ordered List",label:'<i class="uk-icon-list-ol"></i>'}}),c("bold","<strong>$1</strong>"),c("italic","<em>$1</em>"),c("strike","<del>$1</del>"),c("blockquote","<blockquote><p>$1</p></blockquote>","replaceLine"),c("link",'<a href="http://">$1</a>'),c("image",'<img src="http://" alt="$1">');var d=function(){if("html"==a.getCursorMode()){for(var b=a.editor,c=b.getDoc().getCursor(!0),d=b.getDoc().getCursor(!1),e=c.line;e<d.line+1;e++)b.replaceRange("<li>"+b.getLine(e)+"</li>",{line:e,ch:0},{line:e,ch:b.getLine(e).length});b.setCursor({line:d.line,ch:b.getLine(d.line).length}),b.focus()}};a.on("action.listUl",function(){d()}),a.on("action.listOl",function(){d()}),a.htmleditor.on("click",'a[data-htmleditor-button="fullscreen"]',function(){a.htmleditor.toggleClass("uk-htmleditor-fullscreen");var c=a.editor.getWrapperElement();if(a.htmleditor.hasClass("uk-htmleditor-fullscreen"))a.editor.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:c.style.width,height:c.style.height},c.style.width="",c.style.height=a.content.height()+"px",document.documentElement.style.overflow="hidden";else{document.documentElement.style.overflow="";var d=a.editor.state.fullScreenRestore;c.style.width=d.width,c.style.height=d.height,window.scrollTo(d.scrollLeft,d.scrollTop)}setTimeout(function(){a.fit(),b.$win.trigger("resize")},50)}),a.addShortcut(["Ctrl-S","Cmd-S"],function(){a.element.trigger("htmleditor-save",[a])}),a.addShortcutAction("bold",["Ctrl-B","Cmd-B"])}}),b.plugin("htmleditor","markdown",{init:function(b){function c(){b.editor.setOption("mode","gfm"),b.htmleditor.find(".uk-htmleditor-button-code a").html(b.options.lblMarkedview)}function d(a,c,d){b.on("action."+a,function(){"markdown"==b.getCursorMode()&&b["replaceLine"==d?"replaceLine":"replaceSelection"](c)})}var e=b.options.marked||marked;e&&(e.setOptions(b.options.markedOptions),b.options.markdown&&c(),d("bold","**$1**"),d("italic","*$1*"),d("strike","~~$1~~"),d("blockquote","> $1","replaceLine"),d("link","[$1](http://)"),d("image","![$1](http://)"),b.on("action.listUl",function(){if("markdown"==b.getCursorMode()){for(var a=b.editor,c=a.getDoc().getCursor(!0),d=a.getDoc().getCursor(!1),e=c.line;e<d.line+1;e++)a.replaceRange("* "+a.getLine(e),{line:e,ch:0},{line:e,ch:a.getLine(e).length});a.setCursor({line:d.line,ch:a.getLine(d.line).length}),a.focus()}}),b.on("action.listOl",function(){if("markdown"==b.getCursorMode()){var a=b.editor,c=a.getDoc().getCursor(!0),d=a.getDoc().getCursor(!1),e=1;if(c.line>0){var f,g=a.getLine(c.line-1);(f=g.match(/^(\d+)\./))&&(e=Number(f[1])+1)}for(var h=c.line;h<d.line+1;h++)a.replaceRange(e+". "+a.getLine(h),{line:h,ch:0},{line:h,ch:a.getLine(h).length}),e++;a.setCursor({line:d.line,ch:a.getLine(d.line).length}),a.focus()}}),b.on("renderLate",function(){"gfm"==b.editor.options.mode&&(b.currentvalue=e(b.currentvalue))}),b.on("cursorMode",function(a,c){if("gfm"==b.editor.options.mode){var d=b.editor.getDoc().getCursor();b.editor.getTokenAt(d).state.base.htmlState||(c.mode="markdown")}}),a.extend(b,{enableMarkdown:function(){c(),this.render()},disableMarkdown:function(){this.editor.setOption("mode","htmlmixed"),this.htmleditor.find(".uk-htmleditor-button-code a").html(this.options.lblCodeview),this.render()}}),b.on({enableMarkdown:function(){b.enableMarkdown()},disableMarkdown:function(){b.disableMarkdown()}}))}}),a(function(){a("textarea[data-uk-htmleditor]").each(function(){var c,d=a(this);d.data("htmleditor")||(c=b.htmleditor(d,b.Utils.options(d.attr("data-uk-htmleditor"))))})}),a(document).on("uk-check-display",function(){c.forEach(function(a){a.htmleditor.is(":visible")&&a.fit()})}),b.htmleditor});