Browse Source

add onchange option and other method callback

mathjax-version
Pandao 10 years ago
parent
commit
53b3d3591e
  1. 40
      dist/js/editormd.js
  2. 2
      dist/js/editormd.min.js
  3. 6
      examples/index.html
  4. 33
      examples/onchange.html
  5. 33
      examples/onload.html
  6. 40
      src/js/editormd.js

40
dist/js/editormd.js

@ -56,8 +56,9 @@
width : "100%",
height : "100%",
path : "./lib/",
watch : true,
watch : true,
onload : function() {},
onchange : function() {},
toc : true,
tocStartLevel : 2,
fontSize : "13px",
@ -928,6 +929,8 @@
});
});
}
$.proxy(settings.onchange, _this)();
});
return this;
@ -1089,7 +1092,8 @@
* @returns {editormd} 返回editormd的实例对象
*/
watch : function() {
watch : function(callback) {
callback = callback || function() {};
this.settings.watch = true;
this.preview.show();
@ -1104,6 +1108,8 @@
this.saveToTextareas().resize();
$.proxy(callback, this)();
return this;
},
@ -1112,7 +1118,8 @@
* @returns {editormd} 返回editormd的实例对象
*/
unwatch : function() {
unwatch : function(callback) {
callback = callback || function() {};
this.settings.watch = false;
this.preview.hide();
@ -1128,27 +1135,40 @@
this.resize();
$.proxy(callback, this)();
return this;
},
/**
* 显示编辑器
* @returns {editormd} 返回editormd的实例对象
* @param {Function} [callback=function()] 回调函数
* @returns {editormd} 返回editormd的实例对象
*/
show : function() {
this.editor.show();
show : function(callback) {
callback = callback || function() {};
var _this = this;
this.editor.show(function(){
$.proxy(callback, _this)();
});
return this;
},
/**
* 隐藏编辑器
* @returns {editormd} 返回editormd的实例对象
* @param {Function} [callback=function()] 回调函数
* @returns {editormd} 返回editormd的实例对象
*/
hide : function() {
this.editor.hide();
hide : function(callback) {
callback = callback || function() {};
var _this = this;
this.editor.hide(function(){
$.proxy(callback, _this)();
});
return this;
},

2
dist/js/editormd.min.js

File diff suppressed because one or more lines are too long

6
examples/index.html

@ -31,6 +31,12 @@
<li>
<a href="./toc.html">toc.html</a>
</li>
<li>
<a href="./onload.html">onload.html</a>
</li>
<li>
<a href="./onchange.html">onchange.html</a>
</li>
<li>
<a href="./mathjax.html">mathjax.html</a>
</li>

33
examples/onchange.html

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>Onchange - Editor.md examples</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="layout">
<header>
<h1>Onchange event</h1>
</header>
<div class="editormd" id="test-editormd">
<script type="text/markdown">###Hello world!</script>
</div>
</div>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../dist/css/editormd.css" />
<script src="../src/js/editormd.js"></script>
<script type="text/javascript">
$(function() {
var testEditor = editormd("test-editormd", {
width : "90%",
height : 720,
path : '../lib/',
onchange : function() {
console.log("onchange =>", this, this.id, this.settings);
}
});
});
</script>
</body>
</html>

33
examples/onload.html

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>Onload - Editor.md examples</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="layout">
<header>
<h1>Onload event</h1>
</header>
<div class="editormd" id="test-editormd">
<script type="text/markdown">###Hello world!</script>
</div>
</div>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../dist/css/editormd.css" />
<script src="../src/js/editormd.js"></script>
<script type="text/javascript">
$(function() {
var testEditor = editormd("test-editormd", {
width : "90%",
height : 720,
path : '../lib/',
onload : function() {
console.log("onload =>", this, this.id, this.settings);
}
});
});
</script>
</body>
</html>

40
src/js/editormd.js

@ -45,8 +45,9 @@
width : "100%",
height : "100%",
path : "./lib/",
watch : true,
watch : true,
onload : function() {},
onchange : function() {},
toc : true,
tocStartLevel : 2,
fontSize : "13px",
@ -917,6 +918,8 @@
});
});
}
$.proxy(settings.onchange, _this)();
});
return this;
@ -1078,7 +1081,8 @@
* @returns {editormd} 返回editormd的实例对象
*/
watch : function() {
watch : function(callback) {
callback = callback || function() {};
this.settings.watch = true;
this.preview.show();
@ -1093,6 +1097,8 @@
this.saveToTextareas().resize();
$.proxy(callback, this)();
return this;
},
@ -1101,7 +1107,8 @@
* @returns {editormd} 返回editormd的实例对象
*/
unwatch : function() {
unwatch : function(callback) {
callback = callback || function() {};
this.settings.watch = false;
this.preview.hide();
@ -1117,27 +1124,40 @@
this.resize();
$.proxy(callback, this)();
return this;
},
/**
* 显示编辑器
* @returns {editormd} 返回editormd的实例对象
* @param {Function} [callback=function()] 回调函数
* @returns {editormd} 返回editormd的实例对象
*/
show : function() {
this.editor.show();
show : function(callback) {
callback = callback || function() {};
var _this = this;
this.editor.show(function(){
$.proxy(callback, _this)();
});
return this;
},
/**
* 隐藏编辑器
* @returns {editormd} 返回editormd的实例对象
* @param {Function} [callback=function()] 回调函数
* @returns {editormd} 返回editormd的实例对象
*/
hide : function() {
this.editor.hide();
hide : function(callback) {
callback = callback || function() {};
var _this = this;
this.editor.hide(function(){
$.proxy(callback, _this)();
});
return this;
},

Loading…
Cancel
Save