mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 03:53:50 +00:00 
			
		
		
		
	page load: Make initializations more explicit.
We now initialize most modules in ui_init.js, which
isn't the perfect place to do it, but at least now
we have a mostly consolidated entry point.
All the new foo.initialize() methods introduced in
this module run the same order relative to each
other as before this commit. (I did some console
logging with a hacked version of the program to
get the order right.)  They happen a bit later than
before, though.
A couple modules still have the `$(function() {`
idiom for miscellaneous reasons:
       archive - is a different bundle
       common - used elsewhere
       list_render - non-standard code style
       scroll_bar - no exports
       setup - probably special?
       socket - $(function () is nested!
       transmit - coupled to socket
       translations - i18n is a bigger problem
       ui_init - this bootstraps everything
			
			
This commit is contained in:
		| @@ -25,6 +25,8 @@ | |||||||
|         "page_params": false, |         "page_params": false, | ||||||
|         "attachments_ui": false, |         "attachments_ui": false, | ||||||
|         "csrf_token": false, |         "csrf_token": false, | ||||||
|  |         "copy_and_paste": false, | ||||||
|  |         "click_handlers": false, | ||||||
|         "typeahead_helper": false, |         "typeahead_helper": false, | ||||||
|         "pygments_data": false, |         "pygments_data": false, | ||||||
|         "popovers": false, |         "popovers": false, | ||||||
|   | |||||||
| @@ -18,6 +18,8 @@ zrequire('scroll_util'); | |||||||
| zrequire('list_cursor'); | zrequire('list_cursor'); | ||||||
| zrequire('stream_list'); | zrequire('stream_list'); | ||||||
|  |  | ||||||
|  | stream_color.initialize(); | ||||||
|  |  | ||||||
| var noop = function () {}; | var noop = function () {}; | ||||||
| var return_false = function () { return false; }; | var return_false = function () { return false; }; | ||||||
| var return_true = function () { return true; }; | var return_true = function () { return true; }; | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ var exports = {}; | |||||||
|  |  | ||||||
| // You won't find every click handler here, but it's a good place to start! | // You won't find every click handler here, but it's a good place to start! | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|  |  | ||||||
|     // MOUSE MOVING VS DRAGGING FOR SELECTION DATA TRACKING |     // MOUSE MOVING VS DRAGGING FOR SELECTION DATA TRACKING | ||||||
|  |  | ||||||
| @@ -752,7 +752,7 @@ $(function () { | |||||||
|  |  | ||||||
|         $(".settings-section" + sel + ", .settings-wrapper" + sel).addClass("show"); |         $(".settings-section" + sel + ", .settings-wrapper" + sel).addClass("show"); | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -184,7 +184,7 @@ exports.condense_and_collapse = function (elems) { | |||||||
|     }); |     }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $("#home").on("click", ".message_expander", function () { |     $("#home").on("click", ".message_expander", function () { | ||||||
|         // Expanding a message can mean either uncollapsing or |         // Expanding a message can mean either uncollapsing or | ||||||
|         // uncondensing it. |         // uncondensing it. | ||||||
| @@ -208,7 +208,7 @@ $(function () { | |||||||
|         current_msg_list.get(rows.id(row)).condensed = true; |         current_msg_list.get(rows.id(row)).condensed = true; | ||||||
|         condense_row(row); |         condense_row(row); | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -234,10 +234,10 @@ exports.paste_handler = function (event) { | |||||||
|     } |     } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $(document).on('copy', copy_handler); |     $(document).on('copy', copy_handler); | ||||||
|     $("#compose-textarea").bind('paste', exports.paste_handler); |     $("#compose-textarea").bind('paste', exports.paste_handler); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -279,7 +279,7 @@ function abort_message(message) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     function on_failed_action(action, callback) { |     function on_failed_action(action, callback) { | ||||||
|         $("#main_div").on("click", "." + action + "-failed-message", function (e) { |         $("#main_div").on("click", "." + action + "-failed-message", function (e) { | ||||||
|             e.stopPropagation(); |             e.stopPropagation(); | ||||||
| @@ -299,7 +299,7 @@ $(function () { | |||||||
|  |  | ||||||
|     on_failed_action('remove', abort_message); |     on_failed_action('remove', abort_message); | ||||||
|     on_failed_action('refresh', resend_message); |     on_failed_action('refresh', resend_message); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -123,7 +123,7 @@ exports.launch = function () { | |||||||
|     }); |     }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $(document).on('click', '.invite_check_all_button', function (e) { |     $(document).on('click', '.invite_check_all_button', function (e) { | ||||||
|         $('#streams_to_add :checkbox').prop('checked', true); |         $('#streams_to_add :checkbox').prop('checked', true); | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
| @@ -133,7 +133,7 @@ $(function () { | |||||||
|         $('#streams_to_add :checkbox').prop('checked', false); |         $('#streams_to_add :checkbox').prop('checked', false); | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -209,7 +209,7 @@ exports.next = function () { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| // this is a block of events that are required for the lightbox to work. | // this is a block of events that are required for the lightbox to work. | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $("#main_div").on("click", ".message_inline_image a", function (e) { |     $("#main_div").on("click", ".message_inline_image a", function (e) { | ||||||
|         var $img = $(this).find("img"); |         var $img = $(this).find("img"); | ||||||
|  |  | ||||||
| @@ -292,7 +292,7 @@ $(function () { | |||||||
|             overlays.close_overlay("lightbox"); |             overlays.close_overlay("lightbox"); | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -391,7 +391,7 @@ exports.keep_pointer_in_view = function () { | |||||||
|     current_msg_list.select_id(rows.id(next_row), {from_scroll: true}); |     current_msg_list.select_id(rows.id(next_row), {from_scroll: true}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     jwindow = $(window); |     jwindow = $(window); | ||||||
|     exports.message_pane = $(".app"); |     exports.message_pane = $(".app"); | ||||||
|     // This handler must be placed before all resize handlers in our application |     // This handler must be placed before all resize handlers in our application | ||||||
| @@ -405,7 +405,7 @@ $(function () { | |||||||
|     $(document).on('compose_started compose_canceled compose_finished', function () { |     $(document).on('compose_started compose_canceled compose_finished', function () { | ||||||
|         bottom_of_feed.reset(); |         bottom_of_feed.reset(); | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -184,9 +184,9 @@ exports.toggle_mute = function (msg) { | |||||||
|     } |     } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     exports.update_muted_topics(page_params.muted_topics); |     exports.update_muted_topics(page_params.muted_topics); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
| }()); | }()); | ||||||
|   | |||||||
| @@ -189,7 +189,7 @@ exports.open_settings = function () { | |||||||
|     }); |     }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $("body").on("click", ".overlay, .overlay .exit", function (e) { |     $("body").on("click", ".overlay, .overlay .exit", function (e) { | ||||||
|         var $target = $(e.target); |         var $target = $(e.target); | ||||||
|  |  | ||||||
| @@ -209,7 +209,7 @@ $(function () { | |||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
|         e.stopPropagation(); |         e.stopPropagation(); | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -137,7 +137,7 @@ exports.sidebar_popover_colorpicker_options_full = { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| var lightness_threshold; | var lightness_threshold; | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     // sRGB color component for dark label text. |     // sRGB color component for dark label text. | ||||||
|     // 0x33 to match the color #333333 set by Bootstrap. |     // 0x33 to match the color #333333 set by Bootstrap. | ||||||
|     var label_color = 0x33; |     var label_color = 0x33; | ||||||
| @@ -146,7 +146,7 @@ $(function () { | |||||||
|  |  | ||||||
|     // Compute midpoint lightness between that and white (100). |     // Compute midpoint lightness between that and white (100). | ||||||
|     lightness_threshold = (lightness + 100) / 2; |     lightness_threshold = (lightness + 100) / 2; | ||||||
| }); | }; | ||||||
|  |  | ||||||
| // From a background color (in format "#fff" or "#ffffff") | // From a background color (in format "#fff" or "#ffffff") | ||||||
| // pick a CSS class (or empty string) to determine the | // pick a CSS class (or empty string) to determine the | ||||||
|   | |||||||
| @@ -471,7 +471,7 @@ exports.delete_stream = function (stream_id, alert_element, stream_row) { | |||||||
|     }); |     }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $("#zfilt").on("click", ".stream_sub_unsub_button", function (e) { |     $("#zfilt").on("click", ".stream_sub_unsub_button", function (e) { | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
|         e.stopPropagation(); |         e.stopPropagation(); | ||||||
| @@ -658,7 +658,7 @@ $(function () { | |||||||
|         subs.rerender_subscriptions_settings(sub); |         subs.rerender_subscriptions_settings(sub); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -763,7 +763,7 @@ exports.sub_or_unsub = function (sub) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     stream_data.initialize_from_page_params(); |     stream_data.initialize_from_page_params(); | ||||||
|     stream_list.create_initial_sidebar_rows(); |     stream_list.create_initial_sidebar_rows(); | ||||||
|  |  | ||||||
| @@ -850,7 +850,7 @@ $(function () { | |||||||
|         sub_arrow.removeClass('icon-vector-chevron-up'); |         sub_arrow.removeClass('icon-vector-chevron-up'); | ||||||
|         sub_arrow.addClass('icon-vector-chevron-down'); |         sub_arrow.addClass('icon-vector-chevron-down'); | ||||||
|     }); |     }); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| function focus_on_narrowed_stream() { | function focus_on_narrowed_stream() { | ||||||
|     var stream_name = narrow_state.stream(); |     var stream_name = narrow_state.stream(); | ||||||
|   | |||||||
| @@ -165,7 +165,7 @@ function build_tab_bar() { | |||||||
|     tab_bar.removeClass('notdisplayed'); |     tab_bar.removeClass('notdisplayed'); | ||||||
| } | } | ||||||
|  |  | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     $(document).on('narrow_activated.zulip', function () { |     $(document).on('narrow_activated.zulip', function () { | ||||||
|         build_tab_bar(); |         build_tab_bar(); | ||||||
|     }); |     }); | ||||||
| @@ -174,7 +174,7 @@ $(function () { | |||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     build_tab_bar(); |     build_tab_bar(); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| return exports; | return exports; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -105,9 +105,9 @@ var update_list = []; | |||||||
| // The time at the beginning of the next day, when the timestamps are updated. | // The time at the beginning of the next day, when the timestamps are updated. | ||||||
| // Represented as an XDate with hour, minute, second, millisecond 0. | // Represented as an XDate with hour, minute, second, millisecond 0. | ||||||
| var next_update; | var next_update; | ||||||
| $(function () { | exports.initialize = function () { | ||||||
|     next_update = set_to_start_of_day(new XDate()).addDays(1); |     next_update = set_to_start_of_day(new XDate()).addDays(1); | ||||||
| }); | }; | ||||||
|  |  | ||||||
| // time_above is an optional argument, to support dates that look like: | // time_above is an optional argument, to support dates that look like: | ||||||
| // --- ▲ Yesterday ▲ ------ ▼ Today ▼ --- | // --- ▲ Yesterday ▲ ------ ▼ Today ▼ --- | ||||||
|   | |||||||
| @@ -48,7 +48,13 @@ function message_hover(message_row) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| $(function () { | function initialize_kitchen_sink_stuff() { | ||||||
|  |     // TODO: | ||||||
|  |     //      This function is a historical dumping ground | ||||||
|  |     //      for lots of miscellaneous setup.  Almost all of | ||||||
|  |     //      the code here can probably be moved to more | ||||||
|  |     //      specific-purpose modules like message_viewport.js. | ||||||
|  |  | ||||||
|     var throttled_mousewheelhandler = $.throttle(50, function (e, delta) { |     var throttled_mousewheelhandler = $.throttle(50, function (e, delta) { | ||||||
|         // Most of the mouse wheel's work will be handled by the |         // Most of the mouse wheel's work will be handled by the | ||||||
|         // scroll handler, but when we're at the top or bottom of the |         // scroll handler, but when we're at the top or bottom of the | ||||||
| @@ -251,8 +257,25 @@ $(function () { | |||||||
|     if (feature_flags.full_width) { |     if (feature_flags.full_width) { | ||||||
|         ui.switchToFullWidth(); |         ui.switchToFullWidth(); | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | $(function () { | ||||||
|     // initialize other stuff |     // initialize other stuff | ||||||
|  |     muting_ui.initialize(); | ||||||
|  |     message_viewport.initialize(); | ||||||
|  |     initialize_kitchen_sink_stuff(); | ||||||
|  |     echo.initialize(); | ||||||
|  |     stream_color.initialize(); | ||||||
|  |     stream_edit.initialize(); | ||||||
|  |     subs.initialize(); | ||||||
|  |     condense.initialize(); | ||||||
|  |     lightbox.initialize(); | ||||||
|  |     click_handlers.initialize(); | ||||||
|  |     copy_and_paste.initialize(); | ||||||
|  |     overlays.initialize(); | ||||||
|  |     invite.initialize(); | ||||||
|  |     timerender.initialize(); | ||||||
|  |     tab_bar.initialize(); | ||||||
|     server_events.initialize(); |     server_events.initialize(); | ||||||
|     people.initialize(); |     people.initialize(); | ||||||
|     compose_pm_pill.initialize(); |     compose_pm_pill.initialize(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user