Rename hashchange.should_ignore to is_overlay_hash.

This commit is contained in:
Steve Howell
2018-11-30 23:34:05 +00:00
committed by Tim Abbott
parent 07adda84da
commit 682235af80
2 changed files with 11 additions and 11 deletions

View File

@@ -58,7 +58,7 @@ Here's some notes on how we handle these cases:
* `hashchange.hashchanged` is the function used to handle the hash, * `hashchange.hashchanged` is the function used to handle the hash,
when it's changed by the browser (e.g. by clicking on a link to when it's changed by the browser (e.g. by clicking on a link to
a hash or using the back button). a hash or using the back button).
* `hashchange.should_ignore` is the function `hashchange.hashchanged` * `hashchange.is_overlay_hash` is the function `hashchange.hashchanged`
calls to make it possible for clicking on links within a given calls to make it possible for clicking on links within a given
overlay to just be managed by code within that overlay, without overlay to just be managed by code within that overlay, without
reloading the overlay. It primarily checks whether the "main hash" reloading the overlay. It primarily checks whether the "main hash"
@@ -67,7 +67,7 @@ Here's some notes on how we handle these cases:
browser. If the hash is nonempty, it ensures the relevant overlay browser. If the hash is nonempty, it ensures the relevant overlay
is opened or the user is narrowed as part of the page load process. is opened or the user is narrowed as part of the page load process.
It is also is called by `hashchange.hashchanged` when the hash It is also is called by `hashchange.hashchanged` when the hash
changes outside the `should_ignore` boundaries, since the logic for changes outside the `is_overlay_hash` boundaries, since the logic for
that case is identical. that case is identical.
* `reload.preserve_state` is called when a server-initiated browser * `reload.preserve_state` is called when a server-initiated browser
reload happens, and encodes a bunch of data like the current scroll reload happens, and encodes a bunch of data like the current scroll

View File

@@ -160,7 +160,7 @@ function do_hashchange(from_reload) {
// -- -- -- -- -- -- READ THIS BEFORE TOUCHING ANYTHING BELOW -- -- -- -- -- -- // // -- -- -- -- -- -- READ THIS BEFORE TOUCHING ANYTHING BELOW -- -- -- -- -- -- //
// HOW THE HASH CHANGE MECHANISM WORKS: // HOW THE HASH CHANGE MECHANISM WORKS:
// When going from a normal view (eg. `narrow/is/private`) to a settings panel // When going from a normal view (eg. `narrow/is/private`) to a settings panel
// (eg. `settings/your-bots`) it should trigger the `should_ignore` function and // (eg. `settings/your-bots`) it should trigger the `is_overlay_hash` function and
// return `true` for the current state -- we want to ignore hash changes from // return `true` for the current state -- we want to ignore hash changes from
// within the settings page. The previous hash however should return `false` as it // within the settings page. The previous hash however should return `false` as it
// was outside of the scope of settings. // was outside of the scope of settings.
@@ -214,12 +214,12 @@ var get_hash_group = (function () {
}; };
}()); }());
function should_ignore(hash) { function is_overlay_hash(hash) {
// Hash changes within this list are overlays and should not unnarrow (etc.) // Hash changes within this list are overlays and should not unnarrow (etc.)
var ignore_list = ["streams", "drafts", "settings", "organization", "invite"]; var overlay_list = ["streams", "drafts", "settings", "organization", "invite"];
var main_hash = get_main_hash(hash); var main_hash = get_main_hash(hash);
return ignore_list.indexOf(main_hash) > -1; return overlay_list.indexOf(main_hash) > -1;
} }
function hashchanged(from_reload, e) { function hashchanged(from_reload, e) {
@@ -232,17 +232,17 @@ function hashchanged(from_reload, e) {
var base = get_main_hash(window.location.hash); var base = get_main_hash(window.location.hash);
if (should_ignore(window.location.hash)) { if (is_overlay_hash(window.location.hash)) {
// if the old has was a standard non-ignore hash OR the ignore hash // if the old has was a standard non-ignore hash OR the ignore hash
// base has changed, something needs to run again. // base has changed, something needs to run again.
if (!should_ignore(old_hash || "#") || ignore.group !== get_hash_group(base)) { if (!is_overlay_hash(old_hash || "#") || ignore.group !== get_hash_group(base)) {
if (ignore.group !== get_hash_group(base)) { if (ignore.group !== get_hash_group(base)) {
overlays.close_for_hash_change(); overlays.close_for_hash_change();
} }
// now only if the previous one should not have been ignored. // now only if the previous one should not have been ignored.
if (!should_ignore(old_hash || "#")) { if (!is_overlay_hash(old_hash || "#")) {
ignore.prev = old_hash; ignore.prev = old_hash;
} }
@@ -261,7 +261,7 @@ function hashchanged(from_reload, e) {
} else { } else {
subs.change_state(get_hash_components()); subs.change_state(get_hash_components());
} }
} else if (!should_ignore(window.location.hash) && !ignore.flag) { } else if (!is_overlay_hash(window.location.hash) && !ignore.flag) {
overlays.close_for_hash_change(); overlays.close_for_hash_change();
changing_hash = true; changing_hash = true;
var ret = do_hashchange(from_reload); var ret = do_hashchange(from_reload);
@@ -286,7 +286,7 @@ exports.initialize = function () {
}; };
exports.exit_overlay = function (callback) { exports.exit_overlay = function (callback) {
if (should_ignore(window.location.hash)) { if (is_overlay_hash(window.location.hash)) {
ui_util.blur_active_element(); ui_util.blur_active_element();
ignore.flag = true; ignore.flag = true;
window.location.hash = ignore.prev || "#"; window.location.hash = ignore.prev || "#";