mirror of https://github.com/mindoc-org/mindoc.git
feat:将定位文档功能限定到当前会话
parent
bb7d1c1503
commit
fede48cf51
|
@ -12,7 +12,7 @@ function openLastSelectedNode() {
|
|||
}
|
||||
var $isSelected = false;
|
||||
if(window.localStorage){
|
||||
var $selectedNodeId = window.localStorage.getItem("MinDoc::LastLoadDocument:" + window.book.identify);
|
||||
var $selectedNodeId = window.sessionStorage.getItem("MinDoc::LastLoadDocument:" + window.book.identify);
|
||||
try{
|
||||
if($selectedNodeId){
|
||||
//遍历文档树判断是否存在节点
|
||||
|
@ -51,10 +51,10 @@ function openLastSelectedNode() {
|
|||
function setLastSelectNode($node) {
|
||||
if(window.localStorage) {
|
||||
if (typeof $node === "undefined" || !$node) {
|
||||
window.localStorage.removeItem("MinDoc::LastLoadDocument:" + window.book.identify);
|
||||
window.sessionStorage.removeItem("MinDoc::LastLoadDocument:" + window.book.identify);
|
||||
} else {
|
||||
var nodeId = $node.id ? $node.id : $node.node.id;
|
||||
window.localStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, nodeId);
|
||||
window.sessionStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, nodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
var events = function () {
|
||||
var articleOpen = function (event, $param) {
|
||||
//当打开文档时,将文档ID加入到本地缓存。
|
||||
window.localStorage && window.localStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, $param.$id);
|
||||
window.sessionStorage && window.sessionStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, $param.$id);
|
||||
var prevState = window.history.state || {};
|
||||
if ('pushState' in history) {
|
||||
|
||||
|
@ -24,6 +24,7 @@ var events = function () {
|
|||
if(window.sessionStorage){
|
||||
return {
|
||||
data: function ($key, $value) {
|
||||
$key = "MinDoc::Document:" + $key;
|
||||
if(typeof $value === "undefined"){
|
||||
var data = window.sessionStorage.getItem($key);
|
||||
return JSON.parse(data);
|
||||
|
@ -39,6 +40,7 @@ var events = function () {
|
|||
}else{
|
||||
return {
|
||||
data : function ($key, $value) {
|
||||
$key = "MinDoc::Document:" + $key;
|
||||
if(typeof $value === "undefined"){
|
||||
return $("body").data($key);
|
||||
}else{
|
||||
|
@ -67,7 +69,7 @@ function loadDocument($url, $id, $callback) {
|
|||
url : $url,
|
||||
type : "GET",
|
||||
beforeSend : function (xhr) {
|
||||
var data = events.data("document_" + $id);
|
||||
var data = events.data($id);
|
||||
if(data) {
|
||||
if (typeof $callback === "function") {
|
||||
data.body = $callback(data.body);
|
||||
|
@ -103,7 +105,7 @@ function loadDocument($url, $id, $callback) {
|
|||
$("#article-title").text(doc_title);
|
||||
$("#article-info").text(doc_info);
|
||||
|
||||
events.data('document_' + $id, res.data);
|
||||
events.data($id, res.data);
|
||||
|
||||
events.trigger('article.open', { $url : $url, $id : $id });
|
||||
} else if (res.errcode === 6000) {
|
||||
|
|
Loading…
Reference in New Issue