toggle writing mode bookmark

This commit is contained in:
life
2014-06-05 19:04:39 +08:00
parent 7bb05bd9e7
commit 8af64c7b74
4 changed files with 44 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -810,18 +810,54 @@ function reIsOk(re) {
// marker
// 下拉扩展工具栏用, 点击文档导航用
LEA.bookmark = null;
LEA.hasBookmark = false;
function saveBookmark() {
try {
bookmark = tinymce.activeEditor.selection.getBookmark(); // 光标, 为了处理后重新定位到那个位置
LEA.bookmark = tinymce.activeEditor.selection.getBookmark(); // 光标, 为了处理后重新定位到那个位置
// 如果之前没有focus, 则会在文档开头设置bookmark, 添加一行, 不行.
// $p不是<p>, 很诡异
// 6-5
if(LEA.bookmark && LEA.bookmark.id) {
var $ic = $($("#editorContent_ifr").contents());
var $body = $ic.find("body");
var $p = $body.children().eq(0);
// 找到
if($p.is("span")) {
var $children = $p;
var $c = $children.eq(0);
if($c.attr("id") == LEA.bookmark.id + "_start") {
LEA.hasBookmark = false;
$c.remove();
} else {
LEA.hasBookmark = true;
}
} else if($p.is("p")) {
var $children = $p.children();
if($children.length == 1 && $.trim($p.text()) == "") {
var $c = $children.eq(0);
if($c.attr("id") == LEA.bookmark.id + "_start") {
LEA.hasBookmark = false;
$p.remove();
} else {
LEA.hasBookmark = true;
}
} else {
LEA.hasBookmark = true;
}
}
}
} catch(e) {
}
}
function restoreBookmark() {
try {
if(LEA.hasBookmark) {
// 必须要focus()!!!
var editor = tinymce.activeEditor;
editor.focus();
editor.selection.moveToBookmark(LEA.bookmark);
}
} catch(e) {
}
}