init
This commit is contained in:
62
public/tinymce/plugins/leanote_nav/plugin.js
Normal file
62
public/tinymce/plugins/leanote_nav/plugin.js
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* leanote nav
|
||||
*
|
||||
*/
|
||||
tinymce.PluginManager.add('leanote_nav', function(editor) {
|
||||
var self = this;
|
||||
var preBody = "";
|
||||
function genNav() {
|
||||
var body = editor.getBody();
|
||||
var $con = $(body);
|
||||
var html = $con.html();
|
||||
if(preBody == html) {
|
||||
return;
|
||||
}
|
||||
preBody = html;
|
||||
// 构造一棵树
|
||||
// {"h1-title":{h2-title:{}}}
|
||||
var tree = [];//[{title: "xx", children:[{}]}, {title:"xx2"}];
|
||||
var hs = $con.find("h1,h2,h3,h4,h5,h6").toArray();
|
||||
var titles = '<ul>';
|
||||
for(var i = 0; i < hs.length; ++i) {
|
||||
var text = $(hs[i]).text();
|
||||
var tagName = hs[i].tagName.toLowerCase();
|
||||
// scrollTo在page.js中定义
|
||||
titles += '<li class="nav-' + tagName + '"><a data-a="' + tagName + '-' + encodeURI(text)+'" onclick="scrollTo(this, \'' + tagName + '\', \'' + text + '\')">' + text + '</a></li>';
|
||||
}
|
||||
titles += "</ul>";
|
||||
$("#leanoteNavContent").html(titles).height("auto"); // auto
|
||||
if(!hs.length) {
|
||||
$("#leanoteNavContent").html(" 无");
|
||||
}
|
||||
|
||||
// 这里, resize Height
|
||||
var curH = $("#leanoteNavContent").height();
|
||||
var pH = $("#editorContent_ifr").height()-29;
|
||||
if(curH > pH) {
|
||||
$("#leanoteNavContent").height(pH);
|
||||
}
|
||||
}
|
||||
|
||||
var lastResizeTime = null;
|
||||
editor.on('init', function() {
|
||||
window.setTimeout(function() {
|
||||
// 最开始时加载
|
||||
genNav();
|
||||
editor.on('setcontent beforeadd undo paste', genNav);
|
||||
|
||||
// 这里, 以前是keydown, 太频繁
|
||||
editor.on('ExecCommand', function(e) {
|
||||
genNav();
|
||||
});
|
||||
|
||||
// 为了把下拉菜单关闭
|
||||
editor.on("click", function(e) {
|
||||
genNav();
|
||||
$("body").trigger("click");
|
||||
});
|
||||
|
||||
}, 0);
|
||||
|
||||
});
|
||||
});
|
1
public/tinymce/plugins/leanote_nav/plugin.min.js
vendored
Normal file
1
public/tinymce/plugins/leanote_nav/plugin.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
tinymce.PluginManager.add("leanote_nav",function(t){function n(){var n=t.getBody(),o=$(n),a=o.html();if(e!=a){e=a;for(var i=o.find("h1,h2,h3,h4,h5,h6").toArray(),l="<ul>",h=0;h<i.length;++h){var c=$(i[h]).text(),r=i[h].tagName.toLowerCase();l+='<li class="nav-'+r+'"><a data-a="'+r+"-"+encodeURI(c)+'" onclick="scrollTo(this, \''+r+"', '"+c+"')\">"+c+"</a></li>"}l+="</ul>",$("#leanoteNavContent").html(l).height("auto"),i.length||$("#leanoteNavContent").html(" 无");var d=$("#leanoteNavContent").height(),g=$("#editorContent_ifr").height()-29;d>g&&$("#leanoteNavContent").height(g)}}var e="";t.on("init",function(){window.setTimeout(function(){n(),t.on("setcontent beforeadd undo paste",n),t.on("ExecCommand",function(){n()}),t.on("click",function(){n(),$("body").trigger("click")})},0)})});
|
Reference in New Issue
Block a user