/*! UIkit 2.9.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:{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"},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),this.options.iframe?(this.iframe=a(''),this.preview.append(this.iframe),this.iframe[0].contentWindow.document.open(),this.iframe[0].contentWindow.document.close(),this.preview.container=a(this.iframe[0].contentWindow.document).find("body"),"string"==typeof this.options.iframe&&this.preview.container.parent().append('')):this.preview.container=this.preview,b.$win.on("resize",b.Utils.debounce(function(){d.fit()},200));var f=this.iframe?this.preview.container: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-(d.iframe?d.iframe.height():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()}),this.element.attr("data-uk-check-display",1).on("uk-check-display",function(){this.htmleditor.is(":visible")&&this.fit()}.bind(this)),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.from.ch||b.line>a.from.line&&b.line'+a.buttons[c].label+"")}}),this.toolbar.html(b.join("\n"))}},fit:function(){var a=this.options.mode;"split"==a&&this.htmleditor.width()','
','
    ','
    ','","
    ","
    ",'
    ','
    ','
    ',"
    ",""].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:''},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:''}}),c("bold","$1"),c("italic","$1"),c("strike","$1"),c("blockquote","

    $1

    ","replaceLine"),c("link",'$1'),c("image",'$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"+b.getLine(e)+"",{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;e0){var f,g=a.getLine(c.line-1);(f=g.match(/^(\d+)\./))&&(e=Number(f[1])+1)}for(var h=c.line;h