hashchange: Extract hashchanged_overlay().

This is mostly extracting the code within the `if`
block, as well as setting `base`, which wasn't used
elsewhere.

Also, the `else` no longer calls `is_overlay_hash`,
which was a redundant check.
This commit is contained in:
Steve Howell 2018-12-01 00:08:48 +00:00 committed by Tim Abbott
parent 20bbc375a5
commit cee29483cf
1 changed files with 35 additions and 31 deletions

View File

@ -222,6 +222,39 @@ function is_overlay_hash(hash) {
return overlay_list.indexOf(main_hash) > -1;
}
function hashchanged_overlay(old_hash) {
var base = get_main_hash(window.location.hash);
// if the old has was a standard non-ignore hash OR the ignore hash
// base has changed, something needs to run again.
if (!is_overlay_hash(old_hash || "#") || ignore.group !== get_hash_group(base)) {
if (ignore.group !== get_hash_group(base)) {
overlays.close_for_hash_change();
}
// now only if the previous one should not have been ignored.
if (!is_overlay_hash(old_hash || "#")) {
ignore.hash_before_overlay = old_hash;
}
if (base === "streams") {
subs.launch(get_hash_components());
} else if (base === "drafts") {
drafts.launch();
} else if (/settings|organization/.test(base)) {
settings.setup_page();
admin.setup_page();
} else if (base === "invite") {
invite.launch();
}
ignore.group = get_hash_group(base);
} else {
subs.change_state(get_hash_components());
}
}
function hashchanged(from_reload, e) {
var old_hash;
if (e) {
@ -229,38 +262,9 @@ function hashchanged(from_reload, e) {
ignore.old_hash = window.location.hash;
}
var base = get_main_hash(window.location.hash);
if (is_overlay_hash(window.location.hash)) {
// if the old has was a standard non-ignore hash OR the ignore hash
// base has changed, something needs to run again.
if (!is_overlay_hash(old_hash || "#") || ignore.group !== get_hash_group(base)) {
if (ignore.group !== get_hash_group(base)) {
overlays.close_for_hash_change();
}
// now only if the previous one should not have been ignored.
if (!is_overlay_hash(old_hash || "#")) {
ignore.hash_before_overlay = old_hash;
}
if (base === "streams") {
subs.launch(get_hash_components());
} else if (base === "drafts") {
drafts.launch();
} else if (/settings|organization/.test(base)) {
settings.setup_page();
admin.setup_page();
} else if (base === "invite") {
invite.launch();
}
ignore.group = get_hash_group(base);
} else {
subs.change_state(get_hash_components());
}
} else if (!is_overlay_hash(window.location.hash) && !ignore.flag) {
hashchanged_overlay(old_hash);
} else if (!ignore.flag) {
overlays.close_for_hash_change();
changing_hash = true;
var ret = do_hashchange(from_reload);