Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

点击cls*="back"的按钮时,加上是否ignoreCache的判断;同时添加ignoreCache全局配置项,用于全局加载页面的缓存控制 #625

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions dist/js/sm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
autoInit: false, //自动初始化页面
showPageLoadingIndicator: true, //push.js加载页面的时候显示一个加载提示
router: true, //默认使用router
//点击超链接时是否使用缓存的全局标识,其中,单个链接通过[data-no-cache]来判断,
//同时修改ignoreCache.forward或ignoreCache.back的值。
//对于全部链接,则忽略[data-no-cache],通过全局覆盖。
ignoreCache: {
forward: false,
back: false,
allForward: false,
allBack: false
},
swipePanel: "left", //滑动打开侧栏
swipePanelOnlyClose: true //只允许滑动关闭,不允许滑动打开侧栏
};
Expand Down Expand Up @@ -7646,7 +7655,24 @@ Device/OS Detection
}
} else {
this._saveDocumentIntoCache($(document), fromState.url.full);
this._switchToDocument(state.url.full, false, false, DIRECTION.leftToRight);
/**
* 1. 如果是全局都忽略返回缓存,则每次返回都从服务器获取
* 2. 如果是当前带有[data-no-cache="true"]的返回按钮,则只有改指定超链接地址
* 从服务器获取,并在之后将$.smConfig.ignoreCache.back重置为false
*
* Edit by JSoon
*/
if ($.smConfig.ignoreCache.allBack) {
this._switchToDocument(state.url.full, true, false, DIRECTION.leftToRight);
this._saveAsCurrentState(state);
return;
}
if (!$.smConfig.ignoreCache.back) {
this._switchToDocument(state.url.full, false, false, DIRECTION.leftToRight);
} else {
this._switchToDocument(state.url.full, true, false, DIRECTION.leftToRight);
$.smConfig.ignoreCache.back = false;
}
this._saveAsCurrentState(state);
}
};
Expand All @@ -7670,6 +7696,19 @@ Device/OS Detection
}
} else {
this._saveDocumentIntoCache($(document), fromState.url.full);
/**
* 如果是全局都忽略返回缓存,则每次返回都从服务器获取
*
* 由于存在单独的load方法,故对于[data-no-cache="true"]超链接的逻辑处理交给
* load方法来处理
*
* Edit by JSoon
*/
if ($.smConfig.ignoreCache.allForward) {
this._switchToDocument(state.url.full, true, false, DIRECTION.rightToLeft);
this._saveAsCurrentState(state);
return;
}
this._switchToDocument(state.url.full, false, false, DIRECTION.rightToLeft);
this._saveAsCurrentState(state);
}
Expand Down Expand Up @@ -7835,6 +7874,7 @@ Device/OS Detection

$(document).on('click', 'a', function(e) {
var $target = $(e.currentTarget);
var ignoreCache = $target.attr('data-no-cache') === 'true';

var filterResult = customClickFilter($target);
if (!filterResult) {
Expand All @@ -7848,15 +7888,21 @@ Device/OS Detection
e.preventDefault();

if ($target.hasClass('back')) {
/**
* 如果[cls*="back"]按钮[data-no-cache="true"],则改指定超链接地址从服务器获取
*
* Edit by JSoon
*/
if (ignoreCache) {
$.smConfig.ignoreCache.back = true;
}
router.back();
} else {
var url = $target.attr('href');
if (!url || url === '#') {
return;
}

var ignoreCache = $target.attr('data-no-cache') === 'true';

router.load(url, ignoreCache);
}
});
Expand Down
8 changes: 4 additions & 4 deletions dist/js/sm.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions js/intro.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
autoInit: false, //自动初始化页面
showPageLoadingIndicator: true, //push.js加载页面的时候显示一个加载提示
router: true, //默认使用router
//点击超链接时是否使用缓存的全局标识,其中,单个链接通过[data-no-cache]来判断,
//同时修改ignoreCache.forward或ignoreCache.back的值。
//对于全部链接,则忽略[data-no-cache],通过全局覆盖。
ignoreCache: {
forward: false,
back: false,
allForward: false,
allBack: false
},
swipePanel: "left", //滑动打开侧栏
swipePanelOnlyClose: true //只允许滑动关闭,不允许滑动打开侧栏
};
Expand Down
43 changes: 40 additions & 3 deletions js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,24 @@
}
} else {
this._saveDocumentIntoCache($(document), fromState.url.full);
this._switchToDocument(state.url.full, false, false, DIRECTION.leftToRight);
/**
* 1. 如果是全局都忽略返回缓存,则每次返回都从服务器获取
* 2. 如果是当前带有[data-no-cache="true"]的返回按钮,则只有改指定超链接地址
* 从服务器获取,并在之后将$.smConfig.ignoreCache.back重置为false
*
* Edit by JSoon
*/
if ($.smConfig.ignoreCache.allBack) {
this._switchToDocument(state.url.full, true, false, DIRECTION.leftToRight);
this._saveAsCurrentState(state);
return;
}
if (!$.smConfig.ignoreCache.back) {
this._switchToDocument(state.url.full, false, false, DIRECTION.leftToRight);
} else {
this._switchToDocument(state.url.full, true, false, DIRECTION.leftToRight);
$.smConfig.ignoreCache.back = false;
}
this._saveAsCurrentState(state);
}
};
Expand All @@ -754,6 +771,19 @@
}
} else {
this._saveDocumentIntoCache($(document), fromState.url.full);
/**
* 如果是全局都忽略返回缓存,则每次返回都从服务器获取
*
* 由于存在单独的load方法,故对于[data-no-cache="true"]超链接的逻辑处理交给
* load方法来处理
*
* Edit by JSoon
*/
if ($.smConfig.ignoreCache.allForward) {
this._switchToDocument(state.url.full, true, false, DIRECTION.rightToLeft);
this._saveAsCurrentState(state);
return;
}
this._switchToDocument(state.url.full, false, false, DIRECTION.rightToLeft);
this._saveAsCurrentState(state);
}
Expand Down Expand Up @@ -919,6 +949,7 @@

$(document).on('click', 'a', function(e) {
var $target = $(e.currentTarget);
var ignoreCache = $target.attr('data-no-cache') === 'true';

var filterResult = customClickFilter($target);
if (!filterResult) {
Expand All @@ -932,15 +963,21 @@
e.preventDefault();

if ($target.hasClass('back')) {
/**
* 如果[cls*="back"]按钮[data-no-cache="true"],则改指定超链接地址从服务器获取
*
* Edit by JSoon
*/
if (ignoreCache) {
$.smConfig.ignoreCache.back = true;
}
router.back();
} else {
var url = $target.attr('href');
if (!url || url === '#') {
return;
}

var ignoreCache = $target.attr('data-no-cache') === 'true';

router.load(url, ignoreCache);
}
});
Expand Down