/* =================================================== * bootstrap-markdown.js v2.10.0 * http://github.com/toopay/bootstrap-markdown * =================================================== * Copyright 2013-2016 Taufan Aditya * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================== */ !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){"use strict";var b=function(b,c){var d=["autofocus","savable","hideable","width","height","resize","iconlibrary","language","footer","fullscreen","hiddenButtons","disabledButtons"];a.each(d,function(d,e){"undefined"!=typeof a(b).data(e)&&(c="object"==typeof c?c:{},c[e]=a(b).data(e))}),this.$ns="bootstrap-markdown",this.$element=a(b),this.$editable={el:null,type:null,attrKeys:[],attrValues:[],content:null},this.$options=a.extend(!0,{},a.fn.markdown.defaults,c,this.$element.data("options")),this.$oldContent=null,this.$isPreview=!1,this.$isFullscreen=!1,this.$editor=null,this.$textarea=null,this.$handler=[],this.$callback=[],this.$nextTab=[],this.showEditor()};b.prototype={constructor:b,__alterButtons:function(b,c){var d=this.$handler,e="all"==b,f=this;a.each(d,function(a,d){var g=!0;g=e?!1:d.indexOf(b)<0,g===!1&&c(f.$editor.find('button[data-handler="'+d+'"]'))})},__buildButtons:function(b,c){var d,e=this.$ns,f=this.$handler,g=this.$callback;for(d=0;d",{"class":"btn-group"});for(j=0;j"),m.text(" "+this.__localize(r)).addClass("btn-default btn-sm").addClass(s),s.match(/btn\-(primary|success|info|warning|danger|link)/)&&m.removeClass("btn-default"),m.attr({type:"button",title:this.__localize(o.title)+v,tabindex:t,"data-provider":e,"data-handler":p,"data-hotkey":u}),o.toggle===!0&&m.attr("data-toggle","button"),n=a(""),n.addClass(q),n.prependTo(m),l.append(m),f.push(p),g.push(o.callback)}c.append(l)}}return c},__setListener:function(){var b="undefined"!=typeof this.$textarea.attr("rows"),c=this.$textarea.val().split("\n").length>5?this.$textarea.val().split("\n").length:"5",d=b?this.$textarea.attr("rows"):c;this.$textarea.attr("rows",d),this.$options.resize&&this.$textarea.css("resize",this.$options.resize),this.$textarea.on({focus:a.proxy(this.focus,this),keyup:a.proxy(this.keyup,this),change:a.proxy(this.change,this),select:a.proxy(this.select,this)}),this.eventSupported("keydown")&&this.$textarea.on("keydown",a.proxy(this.keydown,this)),this.eventSupported("keypress")&&this.$textarea.on("keypress",a.proxy(this.keypress,this)),this.$textarea.data("markdown",this)},__handle:function(b){var c=a(b.currentTarget),d=this.$handler,e=this.$callback,f=c.attr("data-handler"),g=d.indexOf(f),h=e[g];a(b.currentTarget).focus(),h(this),this.change(this),f.indexOf("cmdSave")<0&&this.$textarea.focus(),b.preventDefault()},__localize:function(b){var c=a.fn.markdown.messages,d=this.$options.language;return"undefined"!=typeof c&&"undefined"!=typeof c[d]&&"undefined"!=typeof c[d][b]?c[d][b]:b},__getIcon:function(a){return"object"==typeof a?a[this.$options.iconlibrary]:a},setFullscreen:function(b){var c=this.$editor,d=this.$textarea;b===!0?(c.addClass("md-fullscreen-mode"),a("body").addClass("md-nooverflow"),this.$options.onFullscreen(this)):(c.removeClass("md-fullscreen-mode"),a("body").removeClass("md-nooverflow"),1==this.$isPreview&&this.hidePreview().showPreview()),this.$isFullscreen=b,d.focus()},showEditor:function(){var b,c=this,d=this.$ns,e=this.$element,f=(e.css("height"),e.css("width"),this.$editable),g=this.$handler,h=this.$callback,i=this.$options,j=a("
",{"class":"md-editor",click:function(){c.focus()}});if(null===this.$editor){var k=a("
",{"class":"md-header btn-toolbar"}),l=[];if(i.buttons.length>0&&(l=l.concat(i.buttons[0])),i.additionalButtons.length>0&&a.each(i.additionalButtons[0],function(b,c){var d=a.grep(l,function(a,b){return a.name===c.name});d.length>0?d[0].data=d[0].data.concat(c.data):l.push(i.additionalButtons[0][b])}),i.reorderButtonGroups.length>0&&(l=l.filter(function(a){return i.reorderButtonGroups.indexOf(a.name)>-1}).sort(function(a,b){return i.reorderButtonGroups.indexOf(a.name)i.reorderButtonGroups.indexOf(b.name)?1:0})),l.length>0&&(k=this.__buildButtons([l],k)),i.fullscreen.enable&&k.append('
').on("click",".md-control-fullscreen",function(a){a.preventDefault(),c.setFullscreen(!0)}),j.append(k),e.is("textarea"))e.before(j),b=e,b.addClass("md-input"),j.append(b);else{var m="function"==typeof toMarkdown?toMarkdown(e.html()):e.html(),n=a.trim(m);b=a("