mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
static/js/common: Extract function adjust_mac_shortcuts.
This commit is contained in:
committed by
Tim Abbott
parent
251ed94bfc
commit
fed64cc59d
@@ -104,6 +104,33 @@ exports.has_mac_keyboard = function () {
|
||||
return /Mac/i.test(navigator.platform);
|
||||
};
|
||||
|
||||
exports.adjust_mac_shortcuts = function (key_elem_class) {
|
||||
if (!exports.has_mac_keyboard()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var keys_map = new Map([
|
||||
['Backspace', 'Delete'],
|
||||
['Enter', 'Return'],
|
||||
['Home', 'Fn + ←'],
|
||||
['End', 'Fn + →'],
|
||||
['PgUp', 'Fn + ↑'],
|
||||
['PgDn', 'Fn + ↓'],
|
||||
]);
|
||||
|
||||
$(key_elem_class).each(function () {
|
||||
var key_text = $(this).text();
|
||||
var keys = key_text.match(/[^\s\+]+/g);
|
||||
|
||||
_.each(keys, function (key) {
|
||||
if (keys_map.get(key)) {
|
||||
key_text = key_text.replace(key, keys_map.get(key));
|
||||
}
|
||||
});
|
||||
$(this).text(key_text);
|
||||
});
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
}());
|
||||
|
||||
@@ -2,25 +2,6 @@ var info_overlay = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
function adjust_mac_shortcuts() {
|
||||
var keys_map = [
|
||||
['Backspace', 'Delete'],
|
||||
['Enter', 'Return'],
|
||||
['Home', 'Fn + Left'],
|
||||
['End', 'Fn + Right'],
|
||||
['PgUp', 'Fn + Up'],
|
||||
['PgDn', 'Fn + Down'],
|
||||
];
|
||||
|
||||
$(".hotkeys_table").each(function () {
|
||||
var html = $(this).html();
|
||||
keys_map.forEach(function (pair) {
|
||||
html = html.replace(new RegExp(pair[0]), pair[1]);
|
||||
});
|
||||
$(this).html(html);
|
||||
});
|
||||
}
|
||||
|
||||
// Make it explicit that our toggler is undefined until
|
||||
// set_up_toggler is called.
|
||||
exports.toggler = undefined;
|
||||
@@ -63,9 +44,7 @@ exports.set_up_toggler = function () {
|
||||
|
||||
$(".informational-overlays .overlay-tabs").append(elem);
|
||||
|
||||
if (common.has_mac_keyboard()) {
|
||||
adjust_mac_shortcuts();
|
||||
}
|
||||
common.adjust_mac_shortcuts(".hotkeys_table .hotkey kbd");
|
||||
|
||||
exports.toggler = toggler;
|
||||
};
|
||||
|
||||
@@ -38,34 +38,6 @@ function highlight_current_article() {
|
||||
article.addClass('highlighted');
|
||||
}
|
||||
|
||||
function adjust_mac_shortcuts() {
|
||||
var keys_map = new Map([
|
||||
['Backspace', 'Delete'],
|
||||
['Enter', 'Return'],
|
||||
['Home', 'Fn + ←'],
|
||||
['End', 'Fn + →'],
|
||||
['PgUp', 'Fn + ↑'],
|
||||
['PgDn', 'Fn + ↓'],
|
||||
]);
|
||||
|
||||
$(".markdown .content code").each(function () {
|
||||
var text = $(this).text();
|
||||
|
||||
if (!keys_map.has(text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var key_string = keys_map.get(text);
|
||||
var keys = key_string.match(/[^\s\+]+/g);
|
||||
|
||||
_.each(keys, function (key) {
|
||||
key_string = key_string.replace(key, '<code>' + key + '</code>');
|
||||
});
|
||||
|
||||
$(this).replaceWith(key_string);
|
||||
});
|
||||
}
|
||||
|
||||
function render_code_sections() {
|
||||
$(".code-section").each(function () {
|
||||
activate_correct_tab($(this));
|
||||
@@ -74,9 +46,7 @@ function render_code_sections() {
|
||||
|
||||
highlight_current_article();
|
||||
|
||||
if (common.has_mac_keyboard()) {
|
||||
adjust_mac_shortcuts();
|
||||
}
|
||||
common.adjust_mac_shortcuts(".markdown .content code");
|
||||
|
||||
$("table").each(function () {
|
||||
$(this).addClass("table table-striped");
|
||||
|
||||
Reference in New Issue
Block a user