diff --git a/frontend_tests/node_tests/ui.js b/frontend_tests/node_tests/deprecated_feature_notice.js similarity index 77% rename from frontend_tests/node_tests/ui.js rename to frontend_tests/node_tests/deprecated_feature_notice.js index ebdbfccf77..8a7413786a 100644 --- a/frontend_tests/node_tests/ui.js +++ b/frontend_tests/node_tests/deprecated_feature_notice.js @@ -9,12 +9,12 @@ set_global("navigator", { userAgent: "", }); -const ui = zrequire("ui"); +const deprecated_feature_notice = zrequire("deprecated_feature_notice"); run_test("get_hotkey_deprecation_notice", () => { const expected = 'translated: We\'ve replaced the "*" hotkey with "Ctrl + s" to make this common shortcut easier to trigger.'; - const actual = ui.get_hotkey_deprecation_notice("*", "Ctrl + s"); + const actual = deprecated_feature_notice.get_hotkey_deprecation_notice("*", "Ctrl + s"); assert.equal(actual, expected); }); @@ -23,7 +23,7 @@ run_test("get_hotkey_deprecation_notice_mac", () => { "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36"; const expected = 'translated: We\'ve replaced the "*" hotkey with "Cmd + s" to make this common shortcut easier to trigger.'; - const actual = ui.get_hotkey_deprecation_notice("*", "Cmd + s"); + const actual = deprecated_feature_notice.get_hotkey_deprecation_notice("*", "Cmd + s"); assert.equal(actual, expected); // Reset userAgent navigator.userAgent = ""; diff --git a/static/js/deprecated_feature_notice.js b/static/js/deprecated_feature_notice.js new file mode 100644 index 0000000000..f4359e80d9 --- /dev/null +++ b/static/js/deprecated_feature_notice.js @@ -0,0 +1,56 @@ +import $ from "jquery"; + +import * as blueslip from "./blueslip"; +import * as common from "./common"; +import {$t} from "./i18n"; +import {localstorage} from "./localstorage"; +import * as overlays from "./overlays"; + +export function get_hotkey_deprecation_notice(originalHotkey, replacementHotkey) { + return $t( + { + defaultMessage: + 'We\'ve replaced the "{originalHotkey}" hotkey with "{replacementHotkey}" to make this common shortcut easier to trigger.', + }, + {originalHotkey, replacementHotkey}, + ); +} + +let shown_deprecation_notices = []; + +export function maybe_show_deprecation_notice(key) { + let message; + const isCmdOrCtrl = common.has_mac_keyboard() ? "Cmd" : "Ctrl"; + if (key === "C") { + message = get_hotkey_deprecation_notice("C", "x"); + } else if (key === "*") { + message = get_hotkey_deprecation_notice("*", isCmdOrCtrl + " + s"); + } else { + blueslip.error("Unexpected deprecation notice for hotkey:", key); + return; + } + + // Here we handle the tracking for showing deprecation notices, + // whether or not local storage is available. + if (localstorage.supported()) { + const notices_from_storage = JSON.parse(localStorage.getItem("shown_deprecation_notices")); + if (notices_from_storage !== null) { + shown_deprecation_notices = notices_from_storage; + } else { + shown_deprecation_notices = []; + } + } + + if (!shown_deprecation_notices.includes(key)) { + overlays.open_modal("#deprecation-notice-modal"); + $("#deprecation-notice-message").text(message); + $("#close-deprecation-notice").trigger("focus"); + shown_deprecation_notices.push(key); + if (localstorage.supported()) { + localStorage.setItem( + "shown_deprecation_notices", + JSON.stringify(shown_deprecation_notices), + ); + } + } +} diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 574394341c..8275ed8044 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -10,6 +10,7 @@ import * as compose_actions from "./compose_actions"; import * as compose_state from "./compose_state"; import * as condense from "./condense"; import * as copy_and_paste from "./copy_and_paste"; +import * as deprecated_feature_notice from "./deprecated_feature_notice"; import * as drafts from "./drafts"; import * as emoji_picker from "./emoji_picker"; import * as feedback_widget from "./feedback_widget"; @@ -808,10 +809,10 @@ export function process_hotkey(e, hotkey) { browser_history.go_to_location("drafts"); return true; case "C_deprecated": - ui.maybe_show_deprecation_notice("C"); + deprecated_feature_notice.maybe_show_deprecation_notice("C"); return true; case "star_deprecated": - ui.maybe_show_deprecation_notice("*"); + deprecated_feature_notice.maybe_show_deprecation_notice("*"); return true; } diff --git a/static/js/ui.js b/static/js/ui.js index f20d645ac9..3f63395b59 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -1,13 +1,9 @@ import $ from "jquery"; import SimpleBar from "simplebar"; -import * as blueslip from "./blueslip"; -import * as common from "./common"; import {$t} from "./i18n"; -import {localstorage} from "./localstorage"; import * as message_list from "./message_list"; import * as message_lists from "./message_lists"; -import * as overlays from "./overlays"; // What, if anything, obscures the home tab? @@ -109,55 +105,6 @@ export function show_failed_message_success(message_id) { }); } -export function get_hotkey_deprecation_notice(originalHotkey, replacementHotkey) { - return $t( - { - defaultMessage: - 'We\'ve replaced the "{originalHotkey}" hotkey with "{replacementHotkey}" to make this common shortcut easier to trigger.', - }, - {originalHotkey, replacementHotkey}, - ); -} - -let shown_deprecation_notices = []; - -export function maybe_show_deprecation_notice(key) { - let message; - const isCmdOrCtrl = common.has_mac_keyboard() ? "Cmd" : "Ctrl"; - if (key === "C") { - message = get_hotkey_deprecation_notice("C", "x"); - } else if (key === "*") { - message = get_hotkey_deprecation_notice("*", isCmdOrCtrl + " + s"); - } else { - blueslip.error("Unexpected deprecation notice for hotkey:", key); - return; - } - - // Here we handle the tracking for showing deprecation notices, - // whether or not local storage is available. - if (localstorage.supported()) { - const notices_from_storage = JSON.parse(localStorage.getItem("shown_deprecation_notices")); - if (notices_from_storage !== null) { - shown_deprecation_notices = notices_from_storage; - } else { - shown_deprecation_notices = []; - } - } - - if (!shown_deprecation_notices.includes(key)) { - overlays.open_modal("#deprecation-notice-modal"); - $("#deprecation-notice-message").text(message); - $("#close-deprecation-notice").trigger("focus"); - shown_deprecation_notices.push(key); - if (localstorage.supported()) { - localStorage.setItem( - "shown_deprecation_notices", - JSON.stringify(shown_deprecation_notices), - ); - } - } -} - // Save the compose content cursor position and restore when we // shift-tab back in (see hotkey.js). let saved_compose_cursor = 0;