deepseektest/addons/markdown/assets/js/bootstrap-markdown.min.js

2 lines
25 KiB
JavaScript
Raw Normal View History

2025-02-28 09:29:43 +08:00
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory)}else if(typeof exports==="object"){factory(require("jquery"))}else{factory(jQuery)}})(function($){"use strict";var Markdown=function(element,options){var opts=["autofocus","savable","hideable","width","height","resize","iconlibrary","language","footer","fullscreen","hiddenButtons","disabledButtons"];$.each(opts,function(_,opt){if(typeof $(element).data(opt)!=="undefined"){options=typeof options=="object"?options:{};options[opt]=$(element).data(opt)}});this.$ns="bootstrap-markdown";this.$element=$(element);this.$editable={el:null,type:null,attrKeys:[],attrValues:[],content:null};this.$options=$.extend(true,{},$.fn.markdown.defaults,options,this.$element.data("options"));this.$oldContent=null;this.$isPreview=false;this.$isFullscreen=false;this.$editor=null;this.$textarea=null;this.$handler=[];this.$callback=[];this.$nextTab=[];this.showEditor()};Markdown.prototype={constructor:Markdown,__alterButtons:function(name,alter){var handler=this.$handler,isAll=name=="all",that=this;$.each(handler,function(k,v){var halt=true;if(isAll){halt=false}else{halt=v.indexOf(name)<0}if(halt===false){alter(that.$editor.find('button[data-handler="'+v+'"]'))}})},__buildButtons:function(buttonsArray,container){var i,ns=this.$ns,handler=this.$handler,callback=this.$callback;for(i=0;i<buttonsArray.length;i++){var y,btnGroups=buttonsArray[i];for(y=0;y<btnGroups.length;y++){var z,buttons=btnGroups[y].data,btnGroupContainer=$("<div/>",{class:"btn-group"});for(z=0;z<buttons.length;z++){var button=buttons[z],buttonContainer,buttonIconContainer,buttonHandler=ns+"-"+button.name,buttonIcon=this.__getIcon(button.icon),btnText=button.btnText?button.btnText:"",btnClass=button.btnClass?button.btnClass:"btn",tabIndex=button.tabIndex?button.tabIndex:"-1",hotkey=typeof button.hotkey!=="undefined"?button.hotkey:"",hotkeyCaption=typeof jQuery.hotkeys!=="undefined"&&hotkey!==""?" ("+hotkey+")":"";buttonContainer=$("<button></button>");buttonContainer.text(" "+this.__localize(btnText)).addClass("btn-light").addClass(btnClass);if(btnClass.match(/btn\-(primary|success|info|warning|danger|link)/)){buttonContainer.removeClass("btn-light")}buttonContainer.attr({type:"button",title:this.__localize(button.title)+hotkeyCaption,tabindex:tabIndex,"data-provider":ns,"data-handler":buttonHandler,"data-hotkey":hotkey});if(button.toggle===true){buttonContainer.attr("data-toggle","button")}buttonIconContainer=$("<span/>");buttonIconContainer.addClass(buttonIcon);buttonIconContainer.prependTo(buttonContainer);btnGroupContainer.addClass("mr-2");btnGroupContainer.append(buttonContainer);handler.push(buttonHandler);callback.push(button.callback)}container.append(btnGroupContainer)}}return container},__setListener:function(){var hasRows=typeof this.$textarea.attr("rows")!=="undefined",maxRows=this.$textarea.val().split("\n").length>5?this.$textarea.val().split("\n").length:"5",rowsVal=hasRows?this.$textarea.attr("rows"):maxRows;this.$textarea.attr("rows",rowsVal);if(this.$options.resize){this.$textarea.css("resize",this.$options.resize)}this.$textarea.on({focus:$.proxy(this.focus,this),keyup:$.proxy(this.keyup,this),change:$.proxy(this.change,this),select:$.proxy(this.select,this)});if(this.eventSupported("keydown")){this.$textarea.on("keydown",$.proxy(this.keydown,this))}if(this.eventSupported("keypress")){this.$textarea.on("keypress",$.proxy(this.keypress,this))}this.$textarea.data("markdown",this)},__handle:function(e){var target=$(e.currentTarget),handler=this.$handler,callback=this.$callback,handlerName=target.attr("data-handler"),callbackIndex=handler.indexOf(handlerName),callbackHandler=callback[callbackIndex];$(e.currentTarget).focus();callbackHandler(this);this.change(this);if(handlerName.indexOf("cmdSave")<0){this.$textarea.focus()}e.preventDefault()},__localize:function(string){var messages=$.fn.markdown.messages,language=this.$options.language;if(typeof messages!=="undefined"&&typeof messages[language]!=="undefined"&&typeof messages[language][string]!=="undefined"){return messages[lang