You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
7.5 KiB
3 lines
7.5 KiB
/*! UIkit 2.5.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
|
|
|
(function(t){"function"==typeof define&&define.amd&&define("uikit-markdownarea",["uikit"],function(){return jQuery.UIkit.markdownarea||t(window,window.jQuery,window.jQuery.UIkit)}),window&&window.jQuery&&window.jQuery.UIkit&&t(window,window.jQuery,window.jQuery.UIkit)})(function(t,e,i){var n=function(t,i){var o=e(t);o.data("markdownarea")||(this.element=o,this.options=e.extend({},n.defaults,i),this.marked=this.options.marked||marked,this.CodeMirror=this.options.CodeMirror||CodeMirror,this.marked.setOptions({gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:!1,smartLists:!0,smartypants:!1,langPrefix:"lang-"}),this.init(),this.element.data("markdownarea",this))};e.extend(n.prototype,{init:function(){var t=this,o=n.template;o=o.replace(/\{\:lblPreview\}/g,this.options.lblPreview),o=o.replace(/\{\:lblCodeview\}/g,this.options.lblCodeview),this.markdownarea=e(o),this.content=this.markdownarea.find(".uk-markdownarea-content"),this.toolbar=this.markdownarea.find(".uk-markdownarea-toolbar"),this.preview=this.markdownarea.find(".uk-markdownarea-preview").children().eq(0),this.code=this.markdownarea.find(".uk-markdownarea-code"),this.element.before(this.markdownarea).appendTo(this.code),this.editor=this.CodeMirror.fromTextArea(this.element[0],this.options.codemirror),this.editor.markdownarea=this,this.editor.on("change",function(){var e=function(){var e=t.editor.getValue();t.currentvalue=e+"",t.element.trigger("markdownarea-before",[t]),t.applyPlugins(),t.marked(t.currentvalue,function(e,i){if(e)throw e;t.preview.html(i),t.element.val(t.editor.getValue()).trigger("markdownarea-update",[t])})};return e(),i.Utils.debounce(e,150)}()),this.code.find(".CodeMirror").css("height",this.options.height),this._buildtoolbar(),this.fit(),e(window).on("resize",i.Utils.debounce(function(){t.fit()},200));var s=t.preview.parent(),a=this.code.find(".CodeMirror-sizer"),r=this.code.find(".CodeMirror-scroll").on("scroll",i.Utils.debounce(function(){if("tab"!=t.markdownarea.attr("data-mode")){var e=a.height()-r.height(),i=s[0].scrollHeight-s.height(),n=i/e,o=r.scrollTop()*n;s.scrollTop(o)}},10));this.markdownarea.on("click",".uk-markdown-button-markdown, .uk-markdown-button-preview",function(i){i.preventDefault(),"tab"==t.markdownarea.attr("data-mode")&&(t.markdownarea.find(".uk-markdown-button-markdown, .uk-markdown-button-preview").removeClass("uk-active").filter(this).addClass("uk-active"),t.activetab=e(this).hasClass("uk-markdown-button-markdown")?"code":"preview",t.markdownarea.attr("data-active-tab",t.activetab))}),this.preview.parent().css("height",this.code.height())},applyPlugins:function(){var t=this,e=Object.keys(n.plugins),i=n.plugins;if(this.markers={},e.length){var o=this.currentvalue.split("\n");e.forEach(function(t){this.markers[t]=[]},this);for(var s=0,a=o.length;a>s;s++)(function(n){e.forEach(function(e){var s=0;o[n]=o[n].replace(i[e].identifier,function(){var o=i[e].cb({area:t,found:arguments,line:n,pos:s++,uid:[e,n,s,(new Date).getTime()+"RAND"+Math.ceil(1e5*Math.random())].join("-"),replace:function(t){var e=this.area.editor.getLine(this.line),i=e.indexOf(this.found[0]);end=this.found[0].length,this.area.editor.replaceRange(t,{line:this.line,ch:i},{line:this.line,ch:end})}});return o})})})(s);this.currentvalue=o.join("\n")}},_buildtoolbar:function(){if(this.options.toolbar&&this.options.toolbar.length){var t=this,i=[];this.options.toolbar.forEach(function(e){if(n.commands[e]){var o=n.commands[e].title?n.commands[e].title:e;i.push('<li><a data-markdownarea-cmd="'+e+'" title="'+o+'" data-uk-tooltip>'+n.commands[e].label+"</a></li>"),n.commands[e].shortcut&&t.registerShortcut(n.commands[e].shortcut,n.commands[e].action)}}),this.toolbar.html(i.join("\n")),this.markdownarea.on("click","a[data-markdownarea-cmd]",function(){var i=e(this).data("markdownareaCmd");!i||!n.commands[i]||t.activetab&&"code"!=t.activetab&&"fullscreen"!=i||n.commands[i].action.apply(t,[t.editor])})}},fit:function(){var t=this.options.mode;"split"==t&&this.markdownarea.width()<this.options.maxsplitsize&&(t="tab"),"tab"==t&&(this.activetab||(this.activetab="code",this.markdownarea.attr("data-active-tab",this.activetab)),this.markdownarea.find(".uk-markdown-button-markdown, .uk-markdown-button-preview").removeClass("uk-active").filter("code"==this.activetab?".uk-markdown-button-markdown":".uk-markdown-button-preview").addClass("uk-active")),this.editor.refresh(),this.preview.parent().css("height",this.code.height()),this.markdownarea.attr("data-mode",t)},registerShortcut:function(t,i){var n=this;t=e.isArray(t)?t:[t];for(var o=0,s=t.length;s>o;o++){var a={};a[t[o]]=function(){i.apply(n,[n.editor])},n.editor.addKeyMap(a)}}}),e.fn.markdownarea=function(t){return this.each(function(){var i=e(this);i.data("markdownarea")||new n(i,t)})};var o=function(t,e){var i=e.getSelection(),n=t.replace("$1",i);e.replaceSelection(n,"end")};return n.commands={fullscreen:{title:"Fullscreen",label:'<i class="uk-icon-expand"></i>',action:function(t){t.markdownarea.markdownarea.toggleClass("uk-markdownarea-fullscreen");var e=t.getWrapperElement();if(t.markdownarea.markdownarea.hasClass("uk-markdownarea-fullscreen"))t.state.fullScreenRestore={scrollTop:window.pageYOffset,scrollLeft:window.pageXOffset,width:e.style.width,height:e.style.height},e.style.width="",e.style.height=t.markdownarea.content.height()+"px",document.documentElement.style.overflow="hidden";else{document.documentElement.style.overflow="";var i=t.state.fullScreenRestore;e.style.width=i.width,e.style.height=i.height,window.scrollTo(i.scrollLeft,i.scrollTop)}t.refresh(),t.markdownarea.preview.parent().css("height",t.markdownarea.code.height())}},bold:{title:"Bold",label:'<i class="uk-icon-bold"></i>',shortcut:["Ctrl-B","Cmd-B"],action:function(t){o("**$1**",t)}},italic:{title:"Italic",label:'<i class="uk-icon-italic"></i>',action:function(t){o("*$1*",t)}},strike:{title:"Strikethrough",label:'<i class="uk-icon-strikethrough"></i>',action:function(t){o("~~$1~~",t)}},blockquote:{title:"Blockquote",label:'<i class="uk-icon-quote-right"></i>',action:function(t){o("> $1",t)}},link:{title:"Link",label:'<i class="uk-icon-link"></i>',action:function(t){o("[$1](http://)",t)}},picture:{title:"Picture",label:'<i class="uk-icon-picture-o"></i>',action:function(t){o("![$1](http://)",t)}},listUl:{title:"Unordered List",label:'<i class="uk-icon-list-ul"></i>',action:function(t){o("* $1",t)}},listOl:{title:"Ordered List",label:'<i class="uk-icon-list-ol"></i>',action:function(t){o("1. $1",t)}}},n.defaults={mode:"split",height:500,maxsplitsize:1e3,codemirror:{mode:"gfm",tabMode:"indent",tabindex:"2",lineWrapping:!0,dragDrop:!1},toolbar:["bold","italic","strike","link","picture","blockquote","listUl","listOl"],lblPreview:"Preview",lblCodeview:"Markdown"},n.template='<div class="uk-markdownarea uk-clearfix" data-mode="split"><div class="uk-markdownarea-navbar"><ul class="uk-markdownarea-navbar-nav uk-markdownarea-toolbar"></ul><div class="uk-markdownarea-navbar-flip"><ul class="uk-markdownarea-navbar-nav"><li class="uk-markdown-button-markdown"><a>{:lblCodeview}</a></li><li class="uk-markdown-button-preview"><a>{:lblPreview}</a></li><li><a data-markdownarea-cmd="fullscreen"><i class="uk-icon-expand"></i></a></li></ul></div></div><div class="uk-markdownarea-content"><div class="uk-markdownarea-code"></div><div class="uk-markdownarea-preview"><div></div></div></div></div>',n.plugins={},n.addPlugin=function(t,e,i){n.plugins[t]={identifier:e,cb:i}},i.markdownarea=n,e(function(){e("textarea[data-uk-markdownarea]").each(function(){var t,o=e(this);o.data("markdownarea")||(t=new n(o,i.Utils.options(o.attr("data-uk-markdownarea"))))})}),n});
|