玛氪宕·梦魔(Markdown Memo),使用Markdown的云端备忘录,百度IFE的RIA启航班的不合格的作业,才……才没有什么阴谋呢!
源gitee链接https://gitee.com/arathi/MarkdownMemo?_from=gitee_search
				
			
			
		
			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.
		
		
		
		
		
			
		
			
				
					
					
						
							140 lines
						
					
					
						
							6.4 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							140 lines
						
					
					
						
							6.4 KiB
						
					
					
				
								<!DOCTYPE html>
							 | 
						|
								<html lang="zh">
							 | 
						|
								    <head>
							 | 
						|
								        <meta charset="utf-8" />
							 | 
						|
								        <title>自定义工具栏 - Editor.md examples</title>
							 | 
						|
								        <link rel="stylesheet" href="css/style.css" />
							 | 
						|
								        <link rel="stylesheet" href="../dist/css/editormd.css" />
							 | 
						|
								    </head>
							 | 
						|
								    <body>
							 | 
						|
								        <div id="layout">
							 | 
						|
								            <header>
							 | 
						|
								                <h1>自定义工具栏</h1> 
							 | 
						|
								                <p>Custom toolbar (icons handler)</p>   
							 | 
						|
								            </header>
							 | 
						|
								            <div id="test-editormd">
							 | 
						|
								                <textarea style="display:none;">###自定义工具栏
							 | 
						|
								```javascript
							 | 
						|
								$(function() {                
							 | 
						|
								    var testEditor = editormd("test-editormd", {
							 | 
						|
								        width: "90%",
							 | 
						|
								        height: 640,
							 | 
						|
								        path : '../lib/',
							 | 
						|
								        toolbarIcons : function() {
							 | 
						|
								            return ["undo", "redo", "|", "bold", "hr", "|", "preview", "watch", "|", "fullscreen", "info", "testIcon", "testIcon2"]
							 | 
						|
								        },
							 | 
						|
								        toolbarIconsClass : {
							 | 
						|
								            testIcon : "fa-gears"  // 指定一个FontAawsome的图标类
							 | 
						|
								        },
							 | 
						|
								        toolbarIconTexts : {
							 | 
						|
								            testIcon2 : "测试按钮"  // 如果没有图标,则可以这样直接插入内容,可以是字符串或HTML标签
							 | 
						|
								        },
							 | 
						|
								
							 | 
						|
								        // 自定义工具栏按钮的事件处理
							 | 
						|
								        toolbarHandlers : {
							 | 
						|
								            /**
							 | 
						|
								             * @param {Object}      cm         CodeMirror对象
							 | 
						|
								             * @param {Object}      icon       图标按钮jQuery元素对象
							 | 
						|
								             * @param {Object}      cursor     CodeMirror的光标对象,可获取光标所在行和位置
							 | 
						|
								             * @param {String}      selection  编辑器选中的文本
							 | 
						|
								             */
							 | 
						|
								            testIcon : function(cm, icon, cursor, selection) {
							 | 
						|
								
							 | 
						|
								                //var cursor    = cm.getCursor();     //获取当前光标对象,同cursor参数
							 | 
						|
								                //var selection = cm.getSelection();  //获取当前选中的文本,同selection参数
							 | 
						|
								
							 | 
						|
								                // 替换选中文本,如果没有选中文本,则直接插入
							 | 
						|
								                cm.replaceSelection("[" + selection + ":testIcon]");
							 | 
						|
								
							 | 
						|
								                // 如果当前没有选中的文本,将光标移到要输入的位置
							 | 
						|
								                if(selection === "") {
							 | 
						|
								                    cm.setCursor(cursor.line, cursor.ch + 1);
							 | 
						|
								                }
							 | 
						|
								
							 | 
						|
								                // this == 当前editormd实例
							 | 
						|
								                console.log("testIcon =>", this, cm, icon, cursor, selection);
							 | 
						|
								            },
							 | 
						|
								
							 | 
						|
								            testIcon2 : function(cm, icon, cursor, selection) {
							 | 
						|
								                cm.replaceSelection("[" + selection + ":testIcon2](" + icon.html() + ")");
							 | 
						|
								                console.log("testIcon2 =>", this, icon.html());
							 | 
						|
								            }
							 | 
						|
								        },
							 | 
						|
								
							 | 
						|
								        lang : {
							 | 
						|
								            toolbar : {
							 | 
						|
								                testIcon : "自定义按钮testIcon",  // 自定义按钮的提示文本,即title属性
							 | 
						|
								                testIcon2 : "自定义按钮testIcon2",  
							 | 
						|
								                undo : "撤销 (Ctrl+Z)"
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								    });
							 | 
						|
								});
							 | 
						|
								```
							 | 
						|
								</textarea>
							 | 
						|
								            </div>
							 | 
						|
								        </div>
							 | 
						|
								        
							 | 
						|
								        <script src="../lib/jquery.min.js"></script>
							 | 
						|
								        <script src="../src/js/editormd.js"></script> 
							 | 
						|
								        <!-- 多语言和自定义工具栏的整合测试 -->
							 | 
						|
								        <script src="../src/js/languages/en.js"></script>   
							 | 
						|
								        <script type="text/javascript">
							 | 
						|
								            $(function() {                
							 | 
						|
								                var testEditor = editormd("test-editormd", {
							 | 
						|
								                    width: "90%",
							 | 
						|
								                    height: 640,
							 | 
						|
								                    path : '../lib/',
							 | 
						|
								                    toolbarIcons : function() {
							 | 
						|
								                        return ["undo", "redo", "|", "bold", "hr", "|", "preview", "watch", "|", "fullscreen", "info", "testIcon", "testIcon2"]
							 | 
						|
								                    },
							 | 
						|
								                    toolbarIconsClass : {
							 | 
						|
								                        testIcon : "fa-gears"  // 指定一个FontAawsome的图标类
							 | 
						|
								                    },
							 | 
						|
								                    toolbarIconTexts : {
							 | 
						|
								                        testIcon2 : "测试按钮"  // 如果没有图标,则可以这样直接插入内容,可以是字符串或HTML标签
							 | 
						|
								                    },
							 | 
						|
								                    
							 | 
						|
								                    // 自定义工具栏按钮的事件处理
							 | 
						|
								                    toolbarHandlers : {
							 | 
						|
								                        /**
							 | 
						|
								                         * @param {Object}      cm         CodeMirror对象
							 | 
						|
								                         * @param {Object}      icon       图标按钮jQuery元素对象
							 | 
						|
								                         * @param {Object}      cursor     CodeMirror的光标对象,可获取光标所在行和位置
							 | 
						|
								                         * @param {String}      selection  编辑器选中的文本
							 | 
						|
								                         */
							 | 
						|
								                        testIcon : function(cm, icon, cursor, selection) {
							 | 
						|
								                            
							 | 
						|
								                            //var cursor    = cm.getCursor();     //获取当前光标对象,同cursor参数
							 | 
						|
								                            //var selection = cm.getSelection();  //获取当前选中的文本,同selection参数
							 | 
						|
								                            
							 | 
						|
								                            // 替换选中文本,如果没有选中文本,则直接插入
							 | 
						|
								                            cm.replaceSelection("[" + selection + ":testIcon]");
							 | 
						|
								                            
							 | 
						|
								                            // 如果当前没有选中的文本,将光标移到要输入的位置
							 | 
						|
								                            if(selection === "") {
							 | 
						|
								                                cm.setCursor(cursor.line, cursor.ch + 1);
							 | 
						|
								                            }
							 | 
						|
								                            
							 | 
						|
								                            // this == 当前editormd实例
							 | 
						|
								                            console.log("testIcon =>", this, cm, icon, cursor, selection);
							 | 
						|
								                        },
							 | 
						|
								                        
							 | 
						|
								                        testIcon2 : function(cm, icon, cursor, selection) {
							 | 
						|
								                            cm.replaceSelection("[" + selection + ":testIcon2](" + icon.html() + ")");
							 | 
						|
								                            console.log("testIcon2 =>", this, icon.html());
							 | 
						|
								                        }
							 | 
						|
								                    },
							 | 
						|
								                    
							 | 
						|
								                    lang : {
							 | 
						|
								                        toolbar : {
							 | 
						|
								                            testIcon : "自定义按钮testIcon",  // 自定义按钮的提示文本,即title属性
							 | 
						|
								                            testIcon2 : "自定义按钮testIcon2",  
							 | 
						|
								                            undo : "撤销 (Ctrl+Z)"
							 | 
						|
								                        }
							 | 
						|
								                    }
							 | 
						|
								                });
							 | 
						|
								            });
							 | 
						|
								        </script>
							 | 
						|
								    </body>
							 | 
						|
								</html>
							 |