/*! UIkit 2.15.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
!function(t){var e;jQuery&&UIkit&&(e=t(jQuery,UIkit)),"function"==typeof define&&define.amd&&define("uikit-htmleditor",["uikit"],function(){return e||t(jQuery,UIkit)})}(function(t,e){"use strict";var i=[];return e.component("htmleditor",{defaults:{iframe:!1,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",lineWrapping:!0,dragDrop:!1,autoCloseTags:!0,matchTags:!0,autoCloseBrackets:!0,matchBrackets:!0,indentUnit:4,indentWithTabs:!1,tabSize:4,hintOptions:{completionSingle:!1}},toolbar:["bold","italic","strike","link","image","blockquote","listUl","listOl"],lblPreview:"Preview",lblCodeview:"HTML",lblMarkedview:"Markdown"},boot:function(){e.ready(function(t){e.$("textarea[data-@-htmleditor]",t).each(function(){var t,i=e.$(this);i.data("htmleditor")||(t=e.htmleditor(i,e.Utils.options(i.attr("data-@-htmleditor"))))})})},init:function(){var o=this,r=e.components.htmleditor.template;this.CodeMirror=this.options.CodeMirror||CodeMirror,this.buttons={},r=r.replace(/\{:lblPreview\}/g,this.options.lblPreview),r=r.replace(/\{:lblCodeview\}/g,this.options.lblCodeview),this.htmleditor=e.$(r),this.content=this.htmleditor.find(".@-htmleditor-content"),this.toolbar=this.htmleditor.find(".@-htmleditor-toolbar"),this.preview=this.htmleditor.find(".@-htmleditor-preview").children().eq(0),this.code=this.htmleditor.find(".@-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",e.Utils.debounce(function(){o.render()},150)),this.editor.on("change",function(){o.editor.save()}),this.code.find(".CodeMirror").css("height",this.options.height),this.options.iframe?(this.iframe=e.$(''),this.preview.append(this.iframe),this.iframe[0].contentWindow.document.open(),this.iframe[0].contentWindow.document.close(),this.preview.container=t(this.iframe[0].contentWindow.document).find("body"),"string"==typeof this.options.iframe&&this.preview.container.parent().append('')):this.preview.container=this.preview,e.$win.on("resize",e.Utils.debounce(function(){o.fit()},200));var n=this.iframe?this.preview.container:o.preview.parent(),l=this.code.find(".CodeMirror-sizer"),s=this.code.find(".CodeMirror-scroll").on("scroll",e.Utils.debounce(function(){if("tab"!=o.htmleditor.attr("data-mode")){var t=l.height()-s.height(),e=n[0].scrollHeight-(o.iframe?o.iframe.height():n.height()),i=e/t,r=s.scrollTop()*i;n.scrollTop(r)}},10));this.htmleditor.on("click",".@-htmleditor-button-code, .@-htmleditor-button-preview",function(t){t.preventDefault(),"tab"==o.htmleditor.attr("data-mode")&&(o.htmleditor.find(".@-htmleditor-button-code, .@-htmleditor-button-preview").removeClass("@-active").filter(this).addClass("@-active"),o.activetab=e.$(this).hasClass("@-htmleditor-button-code")?"code":"preview",o.htmleditor.attr("data-active-tab",o.activetab),o.editor.refresh())}),this.htmleditor.on("click","a[data-htmleditor-button]",function(){o.code.is(":visible")&&o.trigger("action."+e.$(this).data("htmleditor-button"),[o.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",e.Utils.debounce(function(){var t=o.editor.getDoc(),e=t.getCursor(),i=o.CodeMirror.innerMode(o.editor.getMode(),o.editor.getTokenAt(e).state).mode.name;if("xml"==i){var r=o.editor.getCursor(),n=o.editor.getTokenAt(r);("<"==n.string.charAt(0)||"attribute"==n.type)&&o.CodeMirror.showHint(o.editor,o.CodeMirror.hint.html,{completeSingle:!1})}},100)),this.debouncedRedraw=e.Utils.debounce(function(){o.redraw()},5),this.on("init.uk.component",function(){o.redraw()}),this.element.attr("data-@-check-display",1).on("display.uk.check",function(){this.htmleditor.is(":visible")&&this.fit()}.bind(this)),i.push(this)},addButton:function(t,e){this.buttons[t]=e},addButtons:function(e){t.extend(this.buttons,e)},replaceInPreview:function(t,e){function i(t){var e=o.getValue().substring(0,t).split("\n");return{line:e.length-1,ch:e[e.length-1].length}}var o=this.editor,r=[],n=o.getValue(),l=-1;return this.currentvalue=this.currentvalue.replace(t,function(){l=n.indexOf(arguments[0],++l);var t={matches:arguments,from:i(l),to:i(l+arguments[0].length),replace:function(e){o.replaceRange(e,t.from,t.to)},inRange:function(e){return e.line===t.from.line&&e.line===t.to.line?e.ch>=t.from.ch&&e.ch=t.from.ch||e.line>t.from.line&&e.line'+t.buttons[e].label+"")}}),this.toolbar.html(e.prefix(i.join("\n")))}},fit:function(){var t=this.options.mode;"split"==t&&this.htmleditor.width()','",'",""].join(""),e.plugin("htmleditor","base",{init:function(t){function i(e,i,o){t.on("action."+e,function(){"html"==t.getCursorMode()&&t["replaceLine"==o?"replaceLine":"replaceSelection"](i)})}t.addButtons({fullscreen:{title:"Fullscreen",label:''},bold:{title:"Bold",label:''},italic:{title:"Italic",label:''},strike:{title:"Strikethrough",label:''},blockquote:{title:"Blockquote",label:''},link:{title:"Link",label:''},image:{title:"Image",label:''},listUl:{title:"Unordered List",label:''},listOl:{title:"Ordered List",label:''}}),i("bold","$1"),i("italic","$1"),i("strike","$1"),i("blockquote","$1
","replaceLine"),i("link",'$1'),i("image",'');var o=function(){if("html"==t.getCursorMode()){for(var e=t.editor,i=e.getDoc().getCursor(!0),o=e.getDoc().getCursor(!1),r=i.line;r"+e.getLine(r)+"",{line:r,ch:0},{line:r,ch:e.getLine(r).length});e.setCursor({line:o.line,ch:e.getLine(o.line).length}),e.focus()}};t.on("action.listUl",function(){o()}),t.on("action.listOl",function(){o()}),t.htmleditor.on("click",'a[data-htmleditor-button="fullscreen"]',function(){t.htmleditor.toggleClass("@-htmleditor-fullscreen");var i=t.editor.getWrapperElement();if(t.htmleditor.hasClass("@-htmleditor-fullscreen"))t.editor.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:i.style.width,height:i.style.height},i.style.width="",i.style.height=t.content.height()+"px",document.documentElement.style.overflow="hidden";else{document.documentElement.style.overflow="";var o=t.editor.state.fullScreenRestore;i.style.width=o.width,i.style.height=o.height,window.scrollTo(o.scrollLeft,o.scrollTop)}setTimeout(function(){t.fit(),e.$win.trigger("resize")},50)}),t.addShortcut(["Ctrl-S","Cmd-S"],function(){t.element.trigger("htmleditor-save",[t])}),t.addShortcutAction("bold",["Ctrl-B","Cmd-B"])}}),e.plugin("htmleditor","markdown",{init:function(e){function i(){e.editor.setOption("mode","gfm"),e.htmleditor.find(".@-htmleditor-button-code a").html(e.options.lblMarkedview)}function o(t,i,o){e.on("action."+t,function(){"markdown"==e.getCursorMode()&&e["replaceLine"==o?"replaceLine":"replaceSelection"](i)})}var r=e.options.marked||marked;r&&(r.setOptions(e.options.markedOptions),e.options.markdown&&i(),o("bold","**$1**"),o("italic","*$1*"),o("strike","~~$1~~"),o("blockquote","> $1","replaceLine"),o("link","[$1](http://)"),o("image","![$1](http://)"),e.on("action.listUl",function(){if("markdown"==e.getCursorMode()){for(var t=e.editor,i=t.getDoc().getCursor(!0),o=t.getDoc().getCursor(!1),r=i.line;r0){var n,l=t.getLine(i.line-1);(n=l.match(/^(\d+)\./))&&(r=Number(n[1])+1)}for(var s=i.line;s