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