mirror of https://github.com/zulip/zulip.git
Extract js/ui_util.js.
This commit is contained in:
parent
099f401b9b
commit
d026344b37
|
@ -27,6 +27,7 @@
|
|||
"ui": false,
|
||||
"ui_state": false,
|
||||
"ui_report": false,
|
||||
"ui_util": false,
|
||||
"lightbox": false,
|
||||
"stream_color": false,
|
||||
"people": false,
|
||||
|
|
|
@ -102,7 +102,7 @@ $(function () {
|
|||
|
||||
$('body').on('click', '.notification', function () {
|
||||
var payload = $(this).data("narrow");
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
narrow.activate(payload.raw_operators, payload.opts_notif);
|
||||
});
|
||||
|
||||
|
@ -153,7 +153,7 @@ $(function () {
|
|||
});
|
||||
$("body").on("click", "a", function () {
|
||||
if (document.activeElement === this) {
|
||||
ui.blur_active_element();
|
||||
ui_util.blur_active_element();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -263,7 +263,7 @@ $(function () {
|
|||
|
||||
// Capture both the left-sidebar Home click and the tab breadcrumb Home
|
||||
$(document).on('click', ".home-link[data-name='home']", function (e) {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
narrow.deactivate();
|
||||
// We need to maybe scroll to the selected message
|
||||
// once we have the proper viewport set up
|
||||
|
@ -273,7 +273,7 @@ $(function () {
|
|||
|
||||
$(".brand").on('click', function (e) {
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
} else {
|
||||
narrow.restore_home_state();
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ exports.start = function (msg_type, opts) {
|
|||
compose.message_content(opts.content);
|
||||
}
|
||||
|
||||
ui.change_tab_to("#home");
|
||||
ui_util.change_tab_to("#home");
|
||||
|
||||
is_composing_message = msg_type;
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ function handle_keydown(e) {
|
|||
// takes the typeaheads a little time to open after the user finishes typing, which
|
||||
// can lead to the focus moving without the autocomplete having a chance to happen.
|
||||
if (nextFocus) {
|
||||
ui.focus_on(nextFocus);
|
||||
ui_util.focus_on(nextFocus);
|
||||
nextFocus = false;
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ function handle_keyup(e) {
|
|||
var code = e.keyCode || e.which;
|
||||
if (code === 13 || (code === 9 && !e.shiftKey)) { // Enter key or tab key
|
||||
if (nextFocus) {
|
||||
ui.focus_on(nextFocus);
|
||||
ui_util.focus_on(nextFocus);
|
||||
nextFocus = false;
|
||||
}
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ exports.initialize = function () {
|
|||
previous_recipients += ", ";
|
||||
}
|
||||
if (event && event.type === 'click') {
|
||||
ui.focus_on('private_message_recipient');
|
||||
ui_util.focus_on('private_message_recipient');
|
||||
}
|
||||
return previous_recipients + item.email + ", ";
|
||||
},
|
||||
|
|
|
@ -91,7 +91,7 @@ exports.parse_narrow = function (hash) {
|
|||
};
|
||||
|
||||
function activate_home_tab() {
|
||||
ui.change_tab_to("#home");
|
||||
ui_util.change_tab_to("#home");
|
||||
narrow.deactivate();
|
||||
floating_recipient_bar.update();
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ function do_hashchange(from_reload) {
|
|||
var hash = window.location.hash.split("/");
|
||||
switch (hash[0]) {
|
||||
case "#narrow":
|
||||
ui.change_tab_to("#home");
|
||||
ui_util.change_tab_to("#home");
|
||||
var operators = exports.parse_narrow(hash);
|
||||
if (operators === undefined) {
|
||||
// If the narrow URL didn't parse, clear
|
||||
|
@ -146,16 +146,16 @@ function do_hashchange(from_reload) {
|
|||
activate_home_tab();
|
||||
break;
|
||||
case "#streams":
|
||||
ui.change_tab_to("#streams");
|
||||
ui_util.change_tab_to("#streams");
|
||||
break;
|
||||
case "#drafts":
|
||||
ui.change_tab_to("#drafts");
|
||||
ui_util.change_tab_to("#drafts");
|
||||
break;
|
||||
case "#administration":
|
||||
ui.change_tab_to("#administration");
|
||||
ui_util.change_tab_to("#administration");
|
||||
break;
|
||||
case "#settings":
|
||||
ui.change_tab_to("#settings");
|
||||
ui_util.change_tab_to("#settings");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
|
@ -295,7 +295,7 @@ exports.close_modals = function () {
|
|||
|
||||
exports.exit_modal = function (callback) {
|
||||
if (should_ignore(window.location.hash)) {
|
||||
ui.blur_active_element();
|
||||
ui_util.blur_active_element();
|
||||
ignore.flag = true;
|
||||
window.location.hash = ignore.prev || "#";
|
||||
if (typeof callback === "function") {
|
||||
|
|
|
@ -374,9 +374,9 @@ exports.edit_last_sent_message = function () {
|
|||
message_edit.start(msg_row, function () {
|
||||
var editability_type = message_edit.get_editability(msg, 5);
|
||||
if (editability_type === message_edit.editability_types.TOPIC_ONLY) {
|
||||
ui.focus_on('message_edit_topic');
|
||||
ui_util.focus_on('message_edit_topic');
|
||||
} else {
|
||||
ui.focus_on('message_edit_content');
|
||||
ui_util.focus_on('message_edit_content');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -275,7 +275,7 @@ exports.activate = function (raw_operators, opts) {
|
|||
$("#zfilt").addClass("focused_table");
|
||||
$("#zhome").removeClass("focused_table");
|
||||
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
message_list.narrowed = msg_list;
|
||||
current_msg_list = message_list.narrowed;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ exports.fast_forward_pointer = function () {
|
|||
unread_ops.mark_all_as_read(function () {
|
||||
pointer.furthest_read = data.max_message_id;
|
||||
unconditionally_send_pointer_update().then(function () {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
reload.initiate({immediate: true,
|
||||
save_pointer: false,
|
||||
save_narrow: false,
|
||||
|
|
|
@ -4,7 +4,7 @@ var exports = {};
|
|||
|
||||
function narrow_or_search_for_term(search_string) {
|
||||
var search_query_box = $("#search_query");
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
var operators = Filter.parse(search_string);
|
||||
narrow.activate(operators, {trigger: 'search'});
|
||||
|
||||
|
|
|
@ -474,7 +474,7 @@ $(function () {
|
|||
return;
|
||||
}
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
var stream = $(e.target).parents('li').attr('data-name');
|
||||
popovers.hide_all();
|
||||
|
@ -535,7 +535,7 @@ function maybe_select_stream(e) {
|
|||
if (topStream !== undefined) {
|
||||
// undefined if there are no results
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
exports.clear_and_hide_search();
|
||||
narrow.by('stream', topStream, {select_first_unread: true, trigger: 'sidebar enter key'});
|
||||
|
|
|
@ -1394,7 +1394,7 @@ function focus_on_narrowed_stream() {
|
|||
|
||||
exports.show_and_focus_on_narrow = function () {
|
||||
$(document).one('subs_page_loaded.zulip', focus_on_narrowed_stream);
|
||||
ui.change_tab_to("#streams");
|
||||
ui_util.change_tab_to("#streams");
|
||||
};
|
||||
|
||||
// *Synchronously* check if a stream exists.
|
||||
|
|
|
@ -211,7 +211,7 @@ exports.set_click_handlers = function (callbacks) {
|
|||
// In a more componentized world, we would delegate some
|
||||
// of this stuff back up to our parents.
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
|
||||
var stream = $(e.target).parents('ul').attr('data-stream');
|
||||
|
|
|
@ -505,7 +505,7 @@ function welcome() {
|
|||
|
||||
exports.start = function () {
|
||||
if (ui_state.home_tab_obscured()) {
|
||||
ui.change_tab_to('#home');
|
||||
ui_util.change_tab_to('#home');
|
||||
}
|
||||
narrow.deactivate();
|
||||
|
||||
|
|
|
@ -19,25 +19,6 @@ exports.home_tab_obscured = function () {
|
|||
return false;
|
||||
};
|
||||
|
||||
exports.change_tab_to = function (tabname) {
|
||||
$('#gear-menu a[href="' + tabname + '"]').tab('show');
|
||||
};
|
||||
|
||||
exports.focus_on = function (field_id) {
|
||||
// Call after autocompleting on a field, to advance the focus to
|
||||
// the next input field.
|
||||
|
||||
// Bootstrap's typeahead does not expose a callback for when an
|
||||
// autocomplete selection has been made, so we have to do this
|
||||
// manually.
|
||||
$("#" + field_id).focus();
|
||||
};
|
||||
|
||||
exports.blur_active_element = function () {
|
||||
// this blurs anything that may perhaps be actively focused on.
|
||||
document.activeElement.blur();
|
||||
};
|
||||
|
||||
function amount_to_paginate() {
|
||||
// Some day we might have separate versions of this function
|
||||
// for Page Up vs. Page Down, but for now it's the same
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
var ui_util = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
// Add functions to this that have no non-trivial
|
||||
// dependencies other than jQuery.
|
||||
|
||||
exports.change_tab_to = function (tabname) {
|
||||
$('#gear-menu a[href="' + tabname + '"]').tab('show');
|
||||
};
|
||||
|
||||
exports.focus_on = function (field_id) {
|
||||
// Call after autocompleting on a field, to advance the focus to
|
||||
// the next input field.
|
||||
|
||||
// Bootstrap's typeahead does not expose a callback for when an
|
||||
// autocomplete selection has been made, so we have to do this
|
||||
// manually.
|
||||
$("#" + field_id).focus();
|
||||
};
|
||||
|
||||
exports.blur_active_element = function () {
|
||||
// this blurs anything that may perhaps be actively focused on.
|
||||
document.activeElement.blur();
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = ui_util;
|
||||
}
|
|
@ -852,6 +852,7 @@ JS_SPECS = {
|
|||
'js/floating_recipient_bar.js',
|
||||
'js/lightbox.js',
|
||||
'js/ui.js',
|
||||
'js/ui_util.js',
|
||||
'js/pointer.js',
|
||||
'js/click_handlers.js',
|
||||
'js/scroll_bar.js',
|
||||
|
|
Loading…
Reference in New Issue