提交 76b4487e 编写于 作者: C Catouse

* add query section by url dramas.

上级 482ccfbd
...@@ -68,6 +68,13 @@ ...@@ -68,6 +68,13 @@
return str; return str;
}; };
var getQueryString = function(name)
{
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
};
var checkScrollbar = function() var checkScrollbar = function()
{ {
if (document.body.clientWidth >= window.innerWidth) return; if (document.body.clientWidth >= window.innerWidth) return;
...@@ -380,7 +387,10 @@ ...@@ -380,7 +387,10 @@
}; };
var query = function(keyString) { var query = function(keyString) {
if(!$sections) return; if(!$sections) {
if(debug) console.log('Query failed, $sections is empty. key:', keyString);
return;
}
if($queryInput.data('queryString') !== keyString) { if($queryInput.data('queryString') !== keyString) {
$queryInput.data('queryString', keyString).val(keyString); $queryInput.data('queryString', keyString).val(keyString);
...@@ -827,15 +837,26 @@ ...@@ -827,15 +837,26 @@
// Load index.json // Load index.json
loadData(INDEX_JSON, function(data){ loadData(INDEX_JSON, function(data){
var firstLoad = !sectionsShowed;
displaySection(data); displaySection(data);
var hash = window.location.hash
if(hash) { if(!firstLoad) {
hash = hash.substr(1); var q = getQueryString('q');
setTimeout(function(){ if(q) {
openSection(hash.split('-')); setTimeout(function(){
}, 300); query(q);
} else { }, 300);
$queryInput.focus(); }
var hash = window.location.hash
if(hash) {
hash = hash.substr(1);
setTimeout(function(){
openSection(hash.split('-'));
}, 600);
} else {
$queryInput.focus();
}
} }
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册