store active feed id in url hash and restore on reload

This commit is contained in:
Andrew Dolgov 2013-02-28 13:06:54 +04:00
parent 271edfa6f9
commit 1b04a298ef
3 changed files with 29 additions and 17 deletions

View File

@ -204,11 +204,11 @@ function feedlist_init() {
document.onkeydown = hotkey_handler; document.onkeydown = hotkey_handler;
setTimeout("hotkey_prefix_timeout()", 5*1000); setTimeout("hotkey_prefix_timeout()", 5*1000);
if (!getActiveFeedId()) if (!getActiveFeedId()) {
viewfeed(-3); viewfeed(-3);
} else {
console.log("T:" + viewfeed(getActiveFeedId(), '', activeFeedIsCat());
getInitParam("cdm_auto_catchup") + " " + getFeedUnread(-3)); }
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);

View File

@ -1,6 +1,4 @@
var global_unread = -1; var global_unread = -1;
var _active_feed_id = undefined;
var _active_feed_is_cat = false;
var hotkey_prefix = false; var hotkey_prefix = false;
var hotkey_prefix_pressed = false; var hotkey_prefix_pressed = false;
var _widescreen_mode = false; var _widescreen_mode = false;
@ -16,13 +14,12 @@ function get_seq() {
} }
function activeFeedIsCat() { function activeFeedIsCat() {
return _active_feed_is_cat; return hash_get('c') == "1";
} }
function getActiveFeedId() { function getActiveFeedId() {
try { try {
//console.log("gAFID: " + _active_feed_id); return hash_get('f');
return _active_feed_id;
} catch (e) { } catch (e) {
exception_error("getActiveFeedId", e); exception_error("getActiveFeedId", e);
} }
@ -30,11 +27,8 @@ function getActiveFeedId() {
function setActiveFeedId(id, is_cat) { function setActiveFeedId(id, is_cat) {
try { try {
_active_feed_id = id; hash_set('f', id);
hash_set('c', is_cat ? 1 : 0);
if (is_cat != undefined) {
_active_feed_is_cat = is_cat;
}
selectFeed(id, is_cat); selectFeed(id, is_cat);
} catch (e) { } catch (e) {
@ -948,3 +942,21 @@ function update_random_feed() {
exception_error("update_random_feed", e); exception_error("update_random_feed", e);
} }
} }
function hash_get(key) {
try {
kv = window.location.hash.substring(1).toQueryParams();
return kv[key];
} catch (e) {
exception_error("hash_set", e);
}
}
function hash_set(key, value) {
try {
kv = window.location.hash.substring(1).toQueryParams();
kv[key] = value;
window.location.hash = $H(kv).toQueryString();
} catch (e) {
exception_error("hash_set", e);
}
}

View File

@ -59,7 +59,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
is_cat || feed_id <= 0); is_cat || feed_id <= 0);
try { try {
if (offset == 0 && infscroll_req == false) { if (infscroll_req == false) {
$("headlines-frame").scrollTop = 0; $("headlines-frame").scrollTop = 0;
} }
} catch (e) { }; } catch (e) { };
@ -78,7 +78,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
var articles = reply['articles']; var articles = reply['articles'];
//var runtime_info = reply['runtime-info']; //var runtime_info = reply['runtime-info'];
if (offset == 0 && infscroll_req == false) { if (infscroll_req == false) {
loaded_article_ids = []; loaded_article_ids = [];
dijit.byId("headlines-frame").attr('content', dijit.byId("headlines-frame").attr('content',