From d17b577d0caf3d86fcb1ebb788cfee34b949761d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 25 Oct 2019 00:45:13 -0700 Subject: [PATCH] js: Purge useless IIFEs. With webpack, variables declared in each file are already file-local (Global variables need to be explicitly exported), so these IIFEs are no longer needed. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - docs/subsystems/html-css.md | 18 ++-- frontend_tests/casper_lib/common.js | 14 --- .../casper_tests/00-realm-creation.js | 2 +- frontend_tests/casper_tests/01-login.js | 2 +- frontend_tests/casper_tests/02-site.js | 2 +- frontend_tests/casper_tests/03-narrow.js | 2 +- frontend_tests/casper_tests/04-compose.js | 2 +- .../casper_tests/05-subscriptions.js | 2 +- frontend_tests/casper_tests/06-settings.js | 2 +- frontend_tests/casper_tests/07-stars.js | 2 +- frontend_tests/casper_tests/08-edit.js | 2 +- frontend_tests/casper_tests/09-navigation.js | 2 +- frontend_tests/casper_tests/10-admin.js | 2 +- frontend_tests/casper_tests/11-mention.js | 2 +- .../casper_tests/12-toggle-message-editing.js | 2 +- .../casper_tests/13-user-deactivation.js | 2 +- frontend_tests/casper_tests/14-drafts.js | 2 +- .../casper_tests/15-delete-message.js | 2 +- .../casper_tests/16-copy-and-paste.js | 2 +- frontend_tests/zjsunit/finder.js | 9 -- frontend_tests/zjsunit/handlebars.js | 4 +- frontend_tests/zjsunit/i18n.js | 6 +- frontend_tests/zjsunit/namespace.js | 9 -- frontend_tests/zjsunit/stub.js | 7 -- frontend_tests/zjsunit/zblueslip.js | 4 - frontend_tests/zjsunit/zjquery.js | 4 - static/js/activity.js | 11 +-- static/js/admin.js | 13 +-- static/js/alert_words.js | 12 +-- static/js/alert_words_ui.js | 12 +-- static/js/archive.js | 20 +--- static/js/attachments_ui.js | 14 +-- static/js/avatar.js | 13 +-- static/js/billing/billing.js | 14 +-- static/js/billing/helpers.js | 12 +-- static/js/billing/upgrade.js | 14 +-- static/js/blueslip.js | 12 +-- static/js/bot_data.js | 10 +- static/js/buddy_data.js | 12 +-- static/js/buddy_list.js | 11 +-- static/js/channel.js | 12 +-- static/js/click_handlers.js | 14 +-- static/js/color_data.js | 12 +-- static/js/colorspace.js | 12 +-- static/js/common.js | 13 +-- static/js/components.js | 12 +-- static/js/compose.js | 25 ++--- static/js/compose_actions.js | 14 +-- static/js/compose_fade.js | 13 +-- static/js/compose_pm_pill.js | 12 +-- static/js/compose_state.js | 12 +-- static/js/compose_ui.js | 12 +-- static/js/composebox_typeahead.js | 12 +-- static/js/condense.js | 16 +--- static/js/confirm_dialog.js | 12 +-- static/js/copy_and_paste.js | 12 +-- static/js/drafts.js | 16 +--- static/js/echo.js | 11 +-- static/js/emoji.js | 13 +-- static/js/emoji_picker.js | 27 ++---- static/js/favicon.js | 11 +-- static/js/feature_flags.js | 13 +-- static/js/feedback_widget.js | 12 +-- static/js/fenced_code.js | 12 +-- static/js/fetch_status.js | 4 +- static/js/filter.js | 9 +- static/js/floating_recipient_bar.js | 13 +-- static/js/gear_menu.js | 12 +-- static/js/hash_util.js | 12 +-- static/js/hashchange.js | 12 +-- static/js/hotkey.js | 13 +-- static/js/hotspots.js | 11 +-- static/js/info_overlay.js | 12 +-- static/js/input_pill.js | 13 +-- static/js/integration_bot_widget.js | 13 +-- static/js/invite.js | 13 +-- static/js/keydown_util.js | 12 +-- static/js/lightbox.js | 15 +-- static/js/lightbox_canvas.js | 12 +-- static/js/list_cursor.js | 4 +- static/js/list_render.js | 15 +-- static/js/list_util.js | 13 +-- static/js/loading.js | 11 +-- static/js/local_message.js | 13 +-- static/js/localstorage.js | 13 +-- static/js/markdown.js | 11 +-- static/js/message_edit.js | 24 ++--- static/js/message_events.js | 12 +-- static/js/message_fetch.js | 14 +-- static/js/message_flags.js | 12 +-- static/js/message_list.js | 12 +-- static/js/message_list_data.js | 4 +- static/js/message_list_view.js | 8 +- static/js/message_live_update.js | 13 +-- static/js/message_scroll.js | 12 +-- static/js/message_store.js | 11 +-- static/js/message_util.js | 12 +-- static/js/message_viewport.js | 19 +--- static/js/muting.js | 11 +-- static/js/muting_ui.js | 12 +-- static/js/narrow.js | 12 +-- static/js/narrow_state.js | 12 +-- static/js/navigate.js | 13 +-- static/js/night_mode.js | 12 +-- static/js/notifications.js | 17 +--- static/js/overlays.js | 15 +-- static/js/padded_widget.js | 12 +-- static/js/panels.js | 17 +--- static/js/people.js | 42 ++++----- static/js/pm_conversations.js | 12 +-- static/js/pm_list.js | 14 +-- static/js/pointer.js | 33 +++---- static/js/poll_widget.js | 13 +-- static/js/popovers.js | 92 +++++++++---------- static/js/portico/help.js | 2 - static/js/portico/integrations_dev_panel.js | 3 - static/js/portico/tabbed-instructions.js | 2 - static/js/presence.js | 11 +-- static/js/reactions.js | 11 +-- static/js/realm_icon.js | 12 +-- static/js/realm_logo.js | 11 +-- static/js/recent_senders.js | 12 +-- static/js/reload.js | 12 +-- static/js/reload_state.js | 12 +-- static/js/reminder.js | 14 +-- static/js/resize.js | 12 +-- static/js/rows.js | 13 +-- static/js/rtl.js | 12 +-- static/js/schema.js | 13 +-- static/js/scroll_bar.js | 12 +-- static/js/scroll_util.js | 11 +-- static/js/search.js | 12 +-- static/js/search_pill.js | 12 +-- static/js/search_pill_widget.js | 13 +-- static/js/search_suggestion.js | 11 +-- static/js/search_util.js | 12 +-- static/js/sent_messages.js | 12 +-- static/js/server_events.js | 11 +-- static/js/server_events_dispatch.js | 12 +-- static/js/settings.js | 14 +-- static/js/settings_account.js | 12 +-- static/js/settings_bots.js | 14 +-- static/js/settings_display.js | 12 +-- static/js/settings_emoji.js | 12 +-- static/js/settings_exports.js | 11 +-- static/js/settings_invites.js | 12 +-- static/js/settings_linkifiers.js | 12 +-- static/js/settings_muting.js | 12 +-- static/js/settings_notifications.js | 12 +-- static/js/settings_org.js | 12 +-- static/js/settings_panel_menu.js | 14 +-- static/js/settings_profile_fields.js | 12 +-- static/js/settings_sections.js | 12 +-- static/js/settings_streams.js | 12 +-- static/js/settings_toggle.js | 13 +-- static/js/settings_ui.js | 14 +-- static/js/settings_user_groups.js | 16 +--- static/js/settings_users.js | 12 +-- static/js/socket.js | 9 +- static/js/starred_messages.js | 14 +-- static/js/stream_color.js | 12 +-- static/js/stream_create.js | 12 +-- static/js/stream_data.js | 18 +--- static/js/stream_edit.js | 14 +-- static/js/stream_events.js | 12 +-- static/js/stream_list.js | 21 ++--- static/js/stream_muting.js | 13 +-- static/js/stream_popover.js | 12 +-- static/js/stream_sort.js | 11 +-- static/js/stream_ui_updates.js | 12 +-- static/js/submessage.js | 13 +-- static/js/subs.js | 14 +-- static/js/tab_bar.js | 13 +-- static/js/templates.js | 11 +-- static/js/tictactoe_widget.js | 13 +-- static/js/timerender.js | 12 +-- static/js/todo_widget.js | 13 +-- static/js/top_left_corner.js | 11 +-- static/js/topic_data.js | 12 +-- static/js/topic_generator.js | 12 +-- static/js/topic_list.js | 11 +-- static/js/topic_zoom.js | 11 +-- static/js/transmit.js | 16 +--- static/js/tutorial.js | 11 +-- static/js/typeahead_helper.js | 18 +--- static/js/typing.js | 11 +-- static/js/typing_data.js | 11 +-- static/js/typing_events.js | 11 +-- static/js/ui.js | 12 +-- static/js/ui_init.js | 5 - static/js/ui_report.js | 12 +-- static/js/ui_util.js | 12 +-- static/js/unread.js | 11 +-- static/js/unread_ops.js | 11 +-- static/js/unread_ui.js | 13 +-- static/js/upload.js | 12 +-- static/js/upload_widget.js | 13 +-- static/js/user_events.js | 12 +-- static/js/user_groups.js | 12 +-- static/js/user_pill.js | 12 +-- static/js/user_search.js | 4 +- static/js/user_status.js | 12 +-- static/js/user_status_ui.js | 12 +-- static/js/util.js | 12 +-- static/js/widgetize.js | 13 +-- static/js/zcommand.js | 13 +-- static/js/zform.js | 13 +-- static/js/zulip.js | 7 +- 209 files changed, 345 insertions(+), 2140 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index d19483cc42..1070441267 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -251,7 +251,6 @@ "guard-for-in": "error", "indent": ["error", 4, { "ArrayExpression": "first", - "outerIIFEBody": 0, "ObjectExpression": "first", "SwitchCase": 0, "CallExpression": {"arguments": "first"}, diff --git a/docs/subsystems/html-css.md b/docs/subsystems/html-css.md index f79a408da8..edc12c2779 100644 --- a/docs/subsystems/html-css.md +++ b/docs/subsystems/html-css.md @@ -146,16 +146,14 @@ relevant background as well. ### Primary build process -Most of the existing JS in Zulip is written in -[IIFE](https://www.google.com/#q=iife)-wrapped modules, one per file -in the `static/js` directory. We will over time migrate these to -Typescript modules. Stylesheets are written in the Sass extension of -CSS (with the scss syntax), they are converted from plain CSS and we -have yet to take full advantage of the features Sass offers. We use -Webpack to transpile and build JS and CSS bundles that the browser can -understand, one for each entry points specifed in -`tools/webpack.assets.json`; source maps are generated in the process -for better debugging experience. +Zulip's frontend is primarily JavaScript in the `static/js` directory; +we are working on migrating these to Typescript modules. Stylesheets +are written in the Sass extension of CSS (with the scss syntax), they +are converted from plain CSS and we have yet to take full advantage of +the features Sass offers. We use Webpack to transpile and build JS +and CSS bundles that the browser can understand, one for each entry +points specifed in `tools/webpack.assets.json`; source maps are +generated in the process for better debugging experience. In development mode, bundles are built and served on the fly using webpack-dev-server with live reloading. In production mode (and when creating a diff --git a/frontend_tests/casper_lib/common.js b/frontend_tests/casper_lib/common.js index db8f4e4416..b1dd8d1d50 100644 --- a/frontend_tests/casper_lib/common.js +++ b/frontend_tests/casper_lib/common.js @@ -1,7 +1,4 @@ var util = require("util"); -var common = (function () { - -var exports = {}; var test_credentials = require('../../var/casper/test_credentials.js').test_credentials; @@ -382,14 +379,3 @@ exports.un_narrow = function () { } common.keypress(27); // Esc }; - -return exports; - -}()); - -// For inclusion with CasperJS -try { - exports.common = common; -} catch (e) { - // continue regardless of error -} diff --git a/frontend_tests/casper_tests/00-realm-creation.js b/frontend_tests/casper_tests/00-realm-creation.js index 0aa2ac6d20..f7d013ba84 100644 --- a/frontend_tests/casper_tests/00-realm-creation.js +++ b/frontend_tests/casper_tests/00-realm-creation.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); var email = 'alice@test.example.com'; var subdomain = 'testsubdomain'; diff --git a/frontend_tests/casper_tests/01-login.js b/frontend_tests/casper_tests/01-login.js index 0baaebc35d..e718104b36 100644 --- a/frontend_tests/casper_tests/01-login.js +++ b/frontend_tests/casper_tests/01-login.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); var realm_url = "http://zulip.zulipdev.com:9981/"; // Start of test script. diff --git a/frontend_tests/casper_tests/02-site.js b/frontend_tests/casper_tests/02-site.js index 8cd498e8c6..4f60e51efc 100644 --- a/frontend_tests/casper_tests/02-site.js +++ b/frontend_tests/casper_tests/02-site.js @@ -8,7 +8,7 @@ // Provides a few utility functions. // See http://casperjs.org/api.html#utils // For example, utils.dump() prints an Object with nice formatting. -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/03-narrow.js b/frontend_tests/casper_tests/03-narrow.js index 33c5ffa318..eea40480f7 100644 --- a/frontend_tests/casper_tests/03-narrow.js +++ b/frontend_tests/casper_tests/03-narrow.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/04-compose.js b/frontend_tests/casper_tests/04-compose.js index f8bcecc17b..a4b73e36d5 100644 --- a/frontend_tests/casper_tests/04-compose.js +++ b/frontend_tests/casper_tests/04-compose.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/05-subscriptions.js b/frontend_tests/casper_tests/05-subscriptions.js index ae2e43d628..79545cf754 100644 --- a/frontend_tests/casper_tests/05-subscriptions.js +++ b/frontend_tests/casper_tests/05-subscriptions.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/06-settings.js b/frontend_tests/casper_tests/06-settings.js index dd0a4fcd9a..2d82ad2b6b 100644 --- a/frontend_tests/casper_tests/06-settings.js +++ b/frontend_tests/casper_tests/06-settings.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); var test_credentials = require('../../var/casper/test_credentials.js').test_credentials; var OUTGOING_WEBHOOK_BOT_TYPE = '3'; var GENERIC_BOT_TYPE = '1'; diff --git a/frontend_tests/casper_tests/07-stars.js b/frontend_tests/casper_tests/07-stars.js index a2ed33f999..b907683f9d 100644 --- a/frontend_tests/casper_tests/07-stars.js +++ b/frontend_tests/casper_tests/07-stars.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); function star_count() { return casper.evaluate(function () { diff --git a/frontend_tests/casper_tests/08-edit.js b/frontend_tests/casper_tests/08-edit.js index 039948735f..438d3c412c 100644 --- a/frontend_tests/casper_tests/08-edit.js +++ b/frontend_tests/casper_tests/08-edit.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/09-navigation.js b/frontend_tests/casper_tests/09-navigation.js index 48262eb1de..8117344f17 100644 --- a/frontend_tests/casper_tests/09-navigation.js +++ b/frontend_tests/casper_tests/09-navigation.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); // Test basic tab navigation. diff --git a/frontend_tests/casper_tests/10-admin.js b/frontend_tests/casper_tests/10-admin.js index 43226bac8a..c22311e758 100644 --- a/frontend_tests/casper_tests/10-admin.js +++ b/frontend_tests/casper_tests/10-admin.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/11-mention.js b/frontend_tests/casper_tests/11-mention.js index 8c1734be62..30b9759b3a 100644 --- a/frontend_tests/casper_tests/11-mention.js +++ b/frontend_tests/casper_tests/11-mention.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/12-toggle-message-editing.js b/frontend_tests/casper_tests/12-toggle-message-editing.js index 07ac8d85d3..b0ab169714 100644 --- a/frontend_tests/casper_tests/12-toggle-message-editing.js +++ b/frontend_tests/casper_tests/12-toggle-message-editing.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); function heading(heading_str) { casper.then(function () { diff --git a/frontend_tests/casper_tests/13-user-deactivation.js b/frontend_tests/casper_tests/13-user-deactivation.js index feed270a64..8d1f15bd59 100644 --- a/frontend_tests/casper_tests/13-user-deactivation.js +++ b/frontend_tests/casper_tests/13-user-deactivation.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/14-drafts.js b/frontend_tests/casper_tests/14-drafts.js index 6317f33e27..68d5690619 100644 --- a/frontend_tests/casper_tests/14-drafts.js +++ b/frontend_tests/casper_tests/14-drafts.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); function waitWhileDraftsVisible(then) { casper.waitFor(function () { diff --git a/frontend_tests/casper_tests/15-delete-message.js b/frontend_tests/casper_tests/15-delete-message.js index 74f50dc35f..b508f3e33b 100644 --- a/frontend_tests/casper_tests/15-delete-message.js +++ b/frontend_tests/casper_tests/15-delete-message.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/casper_tests/16-copy-and-paste.js b/frontend_tests/casper_tests/16-copy-and-paste.js index 9dae336fa2..8294865a79 100644 --- a/frontend_tests/casper_tests/16-copy-and-paste.js +++ b/frontend_tests/casper_tests/16-copy-and-paste.js @@ -1,4 +1,4 @@ -var common = require('../casper_lib/common.js').common; +var common = require('../casper_lib/common.js'); common.start_and_log_in(); diff --git a/frontend_tests/zjsunit/finder.js b/frontend_tests/zjsunit/finder.js index 93ca5eb24b..fd8128d828 100644 --- a/frontend_tests/zjsunit/finder.js +++ b/frontend_tests/zjsunit/finder.js @@ -1,7 +1,3 @@ -var finder = (function () { - -var exports = {}; - var _ = require('underscore/underscore.js'); var fs = require('fs'); var path = require('path'); @@ -47,8 +43,3 @@ exports.find_files_to_run = function () { return files; }; - - -return exports; -}()); -module.exports = finder; diff --git a/frontend_tests/zjsunit/handlebars.js b/frontend_tests/zjsunit/handlebars.js index 3cceafbbbb..75ea98ef6b 100644 --- a/frontend_tests/zjsunit/handlebars.js +++ b/frontend_tests/zjsunit/handlebars.js @@ -4,7 +4,7 @@ const path = require("path"); const templates_path = path.resolve(__dirname, "../../static/templates"); let render; -module.exports.make_handlebars = () => { +exports.make_handlebars = () => { // Create a new Handlebars instance. const Handlebars = require("handlebars/dist/cjs/handlebars.js"); const hb = Handlebars.create(); @@ -40,7 +40,7 @@ module.exports.make_handlebars = () => { return hb; }; -module.exports.stub_templates = stub => { +exports.stub_templates = stub => { render = (filename, ...args) => { const name = path.relative(templates_path, filename).slice(0, -".hbs".length); return stub(name, ...args); diff --git a/frontend_tests/zjsunit/i18n.js b/frontend_tests/zjsunit/i18n.js index 89f7bea6da..a97e0e89e6 100644 --- a/frontend_tests/zjsunit/i18n.js +++ b/frontend_tests/zjsunit/i18n.js @@ -1,6 +1,4 @@ -var i18n = {}; - -i18n.t = function (str, context) { +exports.t = function (str, context) { // We are currently assuming that we will receive context in form of a Dict // of key value pairs and string will be having substitution for keywords // like these "__keyword__". @@ -28,5 +26,3 @@ i18n.t = function (str, context) { }); return 'translated: ' + str; }; - -module.exports = i18n; diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 4bd1573289..ebc35b5996 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -1,7 +1,4 @@ -var namespace = (function () { - var _ = require('underscore/underscore.js'); -var exports = {}; var dependencies = []; var requires = []; @@ -91,9 +88,3 @@ exports.with_overrides = function (test_function) { f(); }); }; - - - -return exports; -}()); -module.exports = namespace; diff --git a/frontend_tests/zjsunit/stub.js b/frontend_tests/zjsunit/stub.js index 80aced50f4..74a854baad 100644 --- a/frontend_tests/zjsunit/stub.js +++ b/frontend_tests/zjsunit/stub.js @@ -1,7 +1,4 @@ -var stub = (function () { - var _ = require('underscore/underscore.js'); -var exports = {}; // Stubs don't do any magical modifications to your namespace. They // just provide you a function that records what arguments get passed @@ -46,7 +43,3 @@ exports.with_stub = function (f) { assert.equal(args.n, 42); }); }()); - -return exports; -}()); -module.exports = stub; diff --git a/frontend_tests/zjsunit/zblueslip.js b/frontend_tests/zjsunit/zblueslip.js index 7acdebddb6..f872a9c3a1 100644 --- a/frontend_tests/zjsunit/zblueslip.js +++ b/frontend_tests/zjsunit/zblueslip.js @@ -1,5 +1,3 @@ -var exports = {}; - exports.make_zblueslip = function (opts) { var lib = {}; @@ -83,5 +81,3 @@ exports.make_zblueslip = function (opts) { return lib; }; - -module.exports = exports; diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 9e1efaf950..e43736c45f 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -1,7 +1,5 @@ var noop = function () {}; -var exports = {}; - exports.make_event_store = (selector) => { /* @@ -550,5 +548,3 @@ exports.make_zjquery = function (opts) { return zjquery; }; - -module.exports = exports; diff --git a/static/js/activity.js b/static/js/activity.js index 22aa7fc8cf..b563f04faf 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -1,9 +1,6 @@ var render_group_pms = require('../templates/group_pms.hbs'); var Dict = require('./dict').Dict; -var activity = (function () { -var exports = {}; - /* Helpers for detecting user activity and managing user idle states */ @@ -495,10 +492,4 @@ exports.get_filter_text = function () { return exports.user_filter.text(); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = activity; -} -window.activity = activity; +window.activity = exports; diff --git a/static/js/admin.js b/static/js/admin.js index da96440514..d815abc83c 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -1,9 +1,5 @@ var render_admin_tab = require('../templates/admin_tab.hbs'); -var admin = (function () { - -var exports = {}; - var admin_settings_label = { // Organization settings realm_allow_community_topic_editing: i18n.t("Users can edit the topic of any message"), @@ -112,11 +108,4 @@ exports.launch = function (section) { settings_toggle.highlight_toggle('organization'); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = admin; -} -window.admin = admin; +window.admin = exports; diff --git a/static/js/alert_words.js b/static/js/alert_words.js index 4b135828ad..cfb3eb3ce5 100644 --- a/static/js/alert_words.js +++ b/static/js/alert_words.js @@ -1,7 +1,3 @@ -var alert_words = (function () { - -var exports = {}; - exports.words = page_params.alert_words; exports.set_words = function (value) { exports.words = value; @@ -59,10 +55,4 @@ exports.notifies = function (message) { return !people.is_current_user(message.sender_email) && message.alerted; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = alert_words; -} -window.alert_words = alert_words; +window.alert_words = exports; diff --git a/static/js/alert_words_ui.js b/static/js/alert_words_ui.js index d80af92248..23a31d8bc1 100644 --- a/static/js/alert_words_ui.js +++ b/static/js/alert_words_ui.js @@ -1,9 +1,5 @@ var render_alert_word_settings_item = require('../templates/alert_word_settings_item.hbs'); -var alert_words_ui = (function () { - -var exports = {}; - exports.render_alert_words_ui = function () { var words = alert_words.words; var word_list = $('#alert_words_list'); @@ -109,10 +105,4 @@ exports.set_up_alert_words = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = alert_words_ui; -} -window.alert_words_ui = alert_words_ui; +window.alert_words_ui = exports; diff --git a/static/js/archive.js b/static/js/archive.js index 38a921a559..241d47b4e4 100644 --- a/static/js/archive.js +++ b/static/js/archive.js @@ -1,9 +1,5 @@ var render_archive_message_group = require('../templates/archive_message_group.hbs'); -var archive = (function () { - -var exports = {}; - function should_separate_into_groups(current_msg_time, next_msg_time) { var current_time = new XDate(current_msg_time * 1000); var next_time = new XDate(next_msg_time * 1000); @@ -98,16 +94,12 @@ exports.initialize = function () { all_message_timestamps_to_human_readable(); }; -return exports; - -}()); - -var current_msg_list = { +exports.current_msg_list = { selected_row: function () { return $('.message_row').last(); }, }; -var rows = { +exports.rows = { get_message_recipient_row: function (message_row) { return $(message_row).parent('.recipient_row'); }, @@ -119,12 +111,6 @@ var rows = { }, }; -if (typeof module !== 'undefined') { - module.exports.current_msg_list = current_msg_list; - module.exports.rows = rows; - module.exports = archive; -} - var scroll_timer; function scroll_finish() { clearTimeout(scroll_timer); @@ -141,5 +127,5 @@ $(function () { $('.app').scroll(_.throttle(function () { scroll_finish(); }, 50)); - archive.initialize(); + exports.initialize(); }); diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js index 999c37f624..354e294188 100644 --- a/static/js/attachments_ui.js +++ b/static/js/attachments_ui.js @@ -1,10 +1,6 @@ var render_settings_upload_space_stats = require("../templates/settings/upload_space_stats.hbs"); var render_uploaded_files_list = require("../templates/uploaded_files_list.hbs"); -var attachments_ui = (function () { - -var exports = {}; - var attachments; var upload_space_used; @@ -39,7 +35,7 @@ function set_upload_space_stats() { var args = { show_upgrade_message: page_params.realm_plan_type === 2, percent_used: exports.percentage_used_space(upload_space_used), - upload_quota: attachments_ui.bytes_to_size(page_params.realm_upload_quota, true), + upload_quota: exports.bytes_to_size(page_params.realm_upload_quota, true), }; var rendered_upload_stats_html = render_settings_upload_space_stats(args); $("#attachment-stats-holder").html(rendered_upload_stats_html); @@ -158,10 +154,4 @@ exports.set_up_attachments = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = attachments_ui; -} -window.attachments_ui = attachments_ui; +window.attachments_ui = exports; diff --git a/static/js/avatar.js b/static/js/avatar.js index a4d0207fc4..6673a65a90 100644 --- a/static/js/avatar.js +++ b/static/js/avatar.js @@ -1,7 +1,3 @@ -var avatar = (function () { - -var exports = {}; - exports.build_bot_create_widget = function () { // We have to do strange gyrations with the file input to clear it, @@ -81,11 +77,4 @@ exports.build_user_avatar_widget = function (upload_function) { ); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = avatar; -} -window.avatar = avatar; +window.avatar = exports; diff --git a/static/js/billing/billing.js b/static/js/billing/billing.js index 51b367adc2..f224b808ee 100644 --- a/static/js/billing/billing.js +++ b/static/js/billing/billing.js @@ -1,6 +1,3 @@ -var billing = (function () { -var exports = {}; - exports.initialize = function () { helpers.set_tab("billing"); @@ -29,15 +26,8 @@ exports.initialize = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = billing; -} - -window.billing = billing; +window.billing = exports; $(function () { - billing.initialize(); + exports.initialize(); }); diff --git a/static/js/billing/helpers.js b/static/js/billing/helpers.js index f1034269b8..bd61ccaa15 100644 --- a/static/js/billing/helpers.js +++ b/static/js/billing/helpers.js @@ -1,6 +1,3 @@ -var helpers = (function () { -var exports = {}; - exports.create_ajax_request = function (url, form_name, stripe_token = null) { var form = $("#" + form_name + "-form"); var form_loading_indicator = "#" + form_name + "_loading_indicator"; @@ -107,11 +104,4 @@ exports.is_valid_input = function (elem) { return elem[0].checkValidity(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = helpers; -} - -window.helpers = helpers; +window.helpers = exports; diff --git a/static/js/billing/upgrade.js b/static/js/billing/upgrade.js index b92156a3ad..21e2a45541 100644 --- a/static/js/billing/upgrade.js +++ b/static/js/billing/upgrade.js @@ -1,6 +1,3 @@ -var upgrade = (function () { -var exports = {}; - exports.initialize = () => { helpers.set_tab("upgrade"); @@ -61,15 +58,8 @@ exports.initialize = () => { helpers.update_charged_amount(prices, $('input[type=radio][name=schedule]:checked').val()); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = upgrade; -} - -window.upgrade = upgrade; +window.upgrade = exports; $(function () { - upgrade.initialize(); + exports.initialize(); }); diff --git a/static/js/blueslip.js b/static/js/blueslip.js index 8bc68ab9ec..affa18d761 100644 --- a/static/js/blueslip.js +++ b/static/js/blueslip.js @@ -4,10 +4,6 @@ // in order to be able to report exceptions that occur during their // execution. -var blueslip = (function () { - -var exports = {}; - if (Error.stackTraceLimit !== undefined) { Error.stackTraceLimit = 100000; } @@ -305,10 +301,4 @@ exports.preview_node = function (node) { return node_preview; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = blueslip; -} -window.blueslip = blueslip; +window.blueslip = exports; diff --git a/static/js/bot_data.js b/static/js/bot_data.js index 17dcae06bf..cc8afa1b4f 100644 --- a/static/js/bot_data.js +++ b/static/js/bot_data.js @@ -1,6 +1,3 @@ -var bot_data = (function () { -var exports = {}; - var bots = {}; var bot_fields = ['api_key', 'avatar_url', 'default_all_public_streams', 'default_events_register_stream', 'default_sending_stream', @@ -90,9 +87,4 @@ exports.initialize = function () { delete page_params.realm_bots; }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = bot_data; -} -window.bot_data = bot_data; +window.bot_data = exports; diff --git a/static/js/buddy_data.js b/static/js/buddy_data.js index b917f31db1..54621fae85 100644 --- a/static/js/buddy_data.js +++ b/static/js/buddy_data.js @@ -1,7 +1,3 @@ -var buddy_data = (function () { - -var exports = {}; - /* This is the main model code for building the buddy list. @@ -307,10 +303,4 @@ exports.huddle_fraction_present = function (huddle) { return false; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = buddy_data; -} -window.buddy_data = buddy_data; +window.buddy_data = exports; diff --git a/static/js/buddy_list.js b/static/js/buddy_list.js index 67fa702057..2a9afcd7d9 100644 --- a/static/js/buddy_list.js +++ b/static/js/buddy_list.js @@ -1,8 +1,6 @@ var render_user_presence_row = require('../templates/user_presence_row.hbs'); var render_user_presence_rows = require('../templates/user_presence_rows.hbs'); -var buddy_list = (function () { - function buddy_list_conf() { var conf = {}; @@ -339,13 +337,8 @@ function buddy_list_create() { return self; } -var exports = buddy_list_create(); +var buddy_list = buddy_list_create(); -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = buddy_list; -} +module.exports = buddy_list; window.buddy_list = buddy_list; diff --git a/static/js/channel.js b/static/js/channel.js index 5eb41dc81e..9f940e3af8 100644 --- a/static/js/channel.js +++ b/static/js/channel.js @@ -1,6 +1,3 @@ -var channel = (function () { - -var exports = {}; var pending_requests = []; function add_pending_request(jqXHR) { @@ -112,11 +109,4 @@ exports.xhr_error_message = function (message, xhr) { return message; }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = channel; -} -window.channel = channel; +window.channel = exports; diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js index 9fef491f79..21337a1e2b 100644 --- a/static/js/click_handlers.js +++ b/static/js/click_handlers.js @@ -1,8 +1,3 @@ -var click_handlers = (function () { - -// We don't actually export anything yet; this is just for consistency. -var exports = {}; - // You won't find every click handler here, but it's a good place to start! exports.initialize = function () { @@ -889,11 +884,4 @@ exports.initialize = function () { }); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = click_handlers; -} -window.click_handlers = click_handlers; +window.click_handlers = exports; diff --git a/static/js/color_data.js b/static/js/color_data.js index 7efef8d5c3..83358ca69e 100644 --- a/static/js/color_data.js +++ b/static/js/color_data.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var color_data = (function () { - -var exports = {}; - // These colors are used now for streams. var stream_colors = [ "#76ce90", "#fae589", "#a6c7e5", "#e79ab5", @@ -60,10 +56,4 @@ exports.pick_color = function () { return color; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = color_data; -} -window.color_data = color_data; +window.color_data = exports; diff --git a/static/js/colorspace.js b/static/js/colorspace.js index 06f71d052e..679d2bf6a5 100644 --- a/static/js/colorspace.js +++ b/static/js/colorspace.js @@ -1,7 +1,3 @@ -var colorspace = (function () { - -var exports = {}; - // Convert an sRGB value in [0, 255] to a linear intensity // value in [0, 1]. // @@ -53,10 +49,4 @@ exports.getHexColor = function (rgb) { parseInt(rgb.b, 10).toString(16); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = colorspace; -} -window.colorspace = colorspace; +window.colorspace = exports; diff --git a/static/js/common.js b/static/js/common.js index 7876f1e1c9..1e12a6d4ba 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -3,10 +3,6 @@ if (module.hot) { module.hot.accept(); } -var common = (function () { - -var exports = {}; - exports.status_classes = 'alert-error alert-success alert-info alert-warning'; exports.autofocus = function (selector) { @@ -135,11 +131,4 @@ exports.adjust_mac_shortcuts = function (key_elem_class, require_cmd_style) { }); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = common; -} -window.common = common; +window.common = exports; diff --git a/static/js/components.js b/static/js/components.js index 64e9a3d340..2364bfc0ae 100644 --- a/static/js/components.js +++ b/static/js/components.js @@ -1,7 +1,3 @@ -var components = (function () { - -var exports = {}; - /* USAGE: Toggle x = components.toggle({ selected: Integer selected_index, @@ -137,10 +133,4 @@ exports.toggle = function (opts) { return prototype; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = components; -} -window.components = components; +window.components = exports; diff --git a/static/js/compose.js b/static/js/compose.js index d3028da69c..a1342a52fd 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -4,11 +4,8 @@ var render_compose_invite_users = require("../templates/compose_invite_users.hbs var render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs"); var render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs"); -var compose = (function () { // Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html -var exports = {}; - /* Track the state of the @all warning. The user must acknowledge that they are spamming the entire stream before the warning will go away. If they try to send before explicitly dismissing the warning, they will get an error message too. @@ -162,7 +159,7 @@ function create_message_object() { // Topics are optional, and we provide a placeholder if one isn't given. var topic = compose_state.topic(); if (topic === "") { - topic = compose.empty_topic_placeholder(); + topic = exports.empty_topic_placeholder(); } var content = make_uploads_relative(compose_state.message_content()); @@ -354,7 +351,7 @@ exports.finish = function () { return; } - if (!compose.validate()) { + if (!exports.validate()) { return false; } @@ -434,7 +431,7 @@ function validate_stream_message_mentions(stream_name) { // check if @all or @everyone is in the message if (util.is_all_or_everyone_mentioned(compose_state.message_content()) && - stream_count > compose.all_everyone_warn_threshold) { + stream_count > exports.all_everyone_warn_threshold) { if (user_acknowledged_all_everyone === undefined || user_acknowledged_all_everyone === false) { // user has not seen a warning message yet if undefined @@ -458,7 +455,7 @@ function validate_stream_message_announce(stream_name) { var stream_count = stream_data.get_subscriber_count(stream_name) || 0; if (stream_name === "announce" && - stream_count > compose.announce_warn_threshold) { + stream_count > exports.announce_warn_threshold) { if (user_acknowledged_announce === undefined || user_acknowledged_announce === false) { // user has not seen a warning message yet if undefined @@ -797,7 +794,7 @@ exports.initialize = function () { $("#compose form").on("submit", function (e) { e.preventDefault(); - compose.finish(); + exports.finish(); }); resize.watch_manual_resize("#compose-textarea"); @@ -861,7 +858,7 @@ exports.initialize = function () { $(event.target).parents('.compose-all-everyone').remove(); user_acknowledged_all_everyone = true; exports.clear_all_everyone_warnings(); - compose.finish(); + exports.finish(); }); $("#compose-announce").on('click', '.compose-announce-confirm', function (event) { @@ -870,7 +867,7 @@ exports.initialize = function () { $(event.target).parents('.compose-announce').remove(); user_acknowledged_announce = true; exports.clear_announce_warnings(); - compose.finish(); + exports.finish(); }); $("#compose-send-status").on('click', '.sub_unsub_button', function (event) { @@ -1093,10 +1090,4 @@ exports.initialize = function () { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = compose; -} -window.compose = compose; +window.compose = exports; diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js index 123340110f..7edaeff227 100644 --- a/static/js/compose_actions.js +++ b/static/js/compose_actions.js @@ -1,9 +1,5 @@ var autosize = require('autosize'); -var compose_actions = (function () { - -var exports = {}; - function update_lock_icon_for_stream(stream_name) { var icon = $("#compose-lock-icon"); var streamfield = $("#stream_message_recipient_stream"); @@ -109,7 +105,7 @@ function clear_box() { exports.autosize_message_content = function () { autosize($("#compose-textarea"), { callback: function () { - compose_actions.maybe_scroll_up_selected_message(); + exports.maybe_scroll_up_selected_message(); }, }); }; @@ -491,10 +487,4 @@ exports.on_narrow = function (opts) { exports.cancel(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = compose_actions; -} -window.compose_actions = compose_actions; +window.compose_actions = exports; diff --git a/static/js/compose_fade.js b/static/js/compose_fade.js index d340d53f96..72a471fc61 100644 --- a/static/js/compose_fade.js +++ b/static/js/compose_fade.js @@ -1,7 +1,3 @@ -var compose_fade = (function () { - -var exports = {}; - var focused_recipient; var normal_display = false; @@ -254,11 +250,4 @@ exports.initialize = function () { }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = compose_fade; -} -window.compose_fade = compose_fade; +window.compose_fade = exports; diff --git a/static/js/compose_pm_pill.js b/static/js/compose_pm_pill.js index b8d266f021..f542b3a4e8 100644 --- a/static/js/compose_pm_pill.js +++ b/static/js/compose_pm_pill.js @@ -1,7 +1,3 @@ -var compose_pm_pill = (function () { - -var exports = {}; - exports.initialize_pill = function () { var pill; var container = $("#private_message_recipient").parent(); @@ -65,10 +61,4 @@ exports.get_typeahead_items = function () { return user_pill.typeahead_source(exports.widget); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = compose_pm_pill; -} -window.compose_pm_pill = compose_pm_pill; +window.compose_pm_pill = exports; diff --git a/static/js/compose_state.js b/static/js/compose_state.js index a2d896ad39..fa0bce57ac 100644 --- a/static/js/compose_state.js +++ b/static/js/compose_state.js @@ -1,7 +1,3 @@ -var compose_state = (function () { - -var exports = {}; - var message_type = false; // 'stream', 'private', or false-y exports.set_message_type = function (msg_type) { @@ -57,10 +53,4 @@ exports.has_message_content = function () { return exports.message_content() !== ""; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = compose_state; -} -window.compose_state = compose_state; +window.compose_state = exports; diff --git a/static/js/compose_ui.js b/static/js/compose_ui.js index 8337d046ee..ca45b8e069 100644 --- a/static/js/compose_ui.js +++ b/static/js/compose_ui.js @@ -1,9 +1,5 @@ var autosize = require('autosize'); -var compose_ui = (function () { - -var exports = {}; - exports.autosize_textarea = function () { autosize.update($("#compose-textarea")); }; @@ -116,10 +112,4 @@ exports.compute_placeholder_text = function (opts) { return i18n.t("Compose your message here"); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = compose_ui; -} -window.compose_ui = compose_ui; +window.compose_ui = exports; diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index a9e350f417..45b4022ef2 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -1,7 +1,5 @@ var autosize = require('autosize'); -var composebox_typeahead = (function () { - //************************************ // AN IMPORTANT NOTE ABOUT TYPEAHEADS //************************************ @@ -13,8 +11,6 @@ var composebox_typeahead = (function () { // highlighter that escapes (i.e. one that calls // typeahead_helper.highlight_with_escaping). -var exports = {}; - exports.emoji_collection = []; exports.update_emoji_data = function () { @@ -917,10 +913,4 @@ exports.initialize = function () { }); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = composebox_typeahead; -} -window.composebox_typeahead = composebox_typeahead; +window.composebox_typeahead = exports; diff --git a/static/js/condense.js b/static/js/condense.js index 5c93d82685..34a75347b7 100644 --- a/static/js/condense.js +++ b/static/js/condense.js @@ -12,10 +12,6 @@ This library implements two related, similar concepts: var Dict = require('./dict').Dict; -var condense = (function () { - -var exports = {}; - var _message_content_height_cache = new Dict(); function show_more_link(row) { @@ -134,7 +130,7 @@ exports.toggle_collapse = function (message) { exports.show_message_expander(row); row.find(".message_condenser").hide(); } - condense.uncollapse(row); + exports.uncollapse(row); } else { if (is_condensed) { message.condensed = false; @@ -142,7 +138,7 @@ exports.toggle_collapse = function (message) { exports.hide_message_expander(row); row.find(".message_condenser").show(); } else { - condense.collapse(row); + exports.collapse(row); } } }; @@ -246,10 +242,4 @@ exports.initialize = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = condense; -} -window.condense = condense; +window.condense = exports; diff --git a/static/js/confirm_dialog.js b/static/js/confirm_dialog.js index 6f3ebe15a9..f01a376dc4 100644 --- a/static/js/confirm_dialog.js +++ b/static/js/confirm_dialog.js @@ -1,9 +1,5 @@ var render_confirm_dialog = require("../templates/confirm_dialog.hbs"); -var confirm_dialog = (function () { - -var exports = {}; - /* Look for confirm_dialog in settings_user_groups to see an example of how to use this widget. It's @@ -79,10 +75,4 @@ exports.launch = function (conf) { overlays.open_modal('confirm_dialog_modal'); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = confirm_dialog; -} -window.confirm_dialog = confirm_dialog; +window.confirm_dialog = exports; diff --git a/static/js/copy_and_paste.js b/static/js/copy_and_paste.js index e3adfb1ea5..b44444bc98 100644 --- a/static/js/copy_and_paste.js +++ b/static/js/copy_and_paste.js @@ -1,7 +1,3 @@ -var copy_and_paste = (function () { - -var exports = {}; - function find_boundary_tr(initial_tr, iterate_row) { var j; var skip_same_td_check = false; @@ -349,10 +345,4 @@ exports.initialize = function () { $('body').on('paste', '#message_edit_form', exports.paste_handler); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = copy_and_paste; -} -window.copy_and_paste = copy_and_paste; +window.copy_and_paste = exports; diff --git a/static/js/drafts.js b/static/js/drafts.js index 376e07c4bb..716e267ad5 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -1,9 +1,5 @@ var render_draft_table_body = require('../templates/draft_table_body.hbs'); -var drafts = (function () { - -var exports = {}; - var draft_model = (function () { var exports = {}; @@ -120,7 +116,7 @@ function draft_notify() { } exports.update_draft = function () { - var draft = drafts.snapshot_message(); + var draft = exports.snapshot_message(); var draft_id = $("#compose-textarea").data("draft-id"); if (draft_id !== undefined) { @@ -288,7 +284,7 @@ function remove_draft(draft_row) { // Deletes the draft and removes it from the list var draft_id = draft_row.data("draft-id"); - drafts.draft_model.deleteDraft(draft_id); + exports.draft_model.deleteDraft(draft_id); draft_row.remove(); @@ -508,10 +504,4 @@ exports.initialize = function () { }); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = drafts; -} -window.drafts = drafts; +window.drafts = exports; diff --git a/static/js/echo.js b/static/js/echo.js index d84a1da12f..8dacae4853 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -1,8 +1,5 @@ -var echo = (function () { // Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html -var exports = {}; - var waiting_for_id = {}; var waiting_for_ack = {}; @@ -290,10 +287,4 @@ exports.initialize = function () { on_failed_action('refresh', resend_message); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = echo; -} -window.echo = echo; +window.echo = exports; diff --git a/static/js/emoji.js b/static/js/emoji.js index 02032a346e..64e7e3833f 100644 --- a/static/js/emoji.js +++ b/static/js/emoji.js @@ -1,7 +1,3 @@ -var emoji = (function () { - -var exports = {}; - // `emojis_by_name` is the central data source that is supposed to be // used by every widget in the webapp for gathering data for displaying // emojis. Emoji picker uses this data to derive data for its own use. @@ -111,7 +107,7 @@ exports.build_emoji_data = function (realm_emojis) { emoji_dict = { name: emoji_name, display_name: emoji_name, - aliases: emoji.default_emoji_aliases[codepoint], + aliases: exports.default_emoji_aliases[codepoint], is_realm_emoji: false, emoji_code: codepoint, has_reacted: false, @@ -194,9 +190,4 @@ exports.translate_emoticons_to_names = function translate_emoticons_to_names(tex return translated; }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = emoji; -} -window.emoji = emoji; +window.emoji = exports; diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index adeae51880..aa0cd5f248 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -3,10 +3,6 @@ var render_emoji_popover_content = require('../templates/emoji_popover_content.h var render_emoji_popover_search_results = require('../templates/emoji_popover_search_results.hbs'); var render_emoji_showcase = require("../templates/emoji_showcase.hbs"); -var emoji_picker = (function () { - -var exports = {}; - // Emoji picker is of fixed width and height. Update these // whenever these values are changed in `reactions.css`. var APPROX_HEIGHT = 375; @@ -281,7 +277,7 @@ function maybe_select_emoji(e) { e.preventDefault(); var first_emoji = get_rendered_emoji(0, 0); if (first_emoji) { - if (emoji_picker.is_composition(first_emoji)) { + if (exports.is_composition(first_emoji)) { first_emoji.click(); } else { toggle_reaction(first_emoji.data("emoji-name")); @@ -553,7 +549,7 @@ function register_popover_events(popover) { var $emoji_map = popover.find('.emoji-popover-emoji-map'); ui.get_scroll_element($emoji_map).on("scroll", function () { - emoji_picker.emoji_select_tab(ui.get_scroll_element($emoji_map)); + exports.emoji_select_tab(ui.get_scroll_element($emoji_map)); }); $('.emoji-popover-filter').on('input', filter_emojis); @@ -637,7 +633,7 @@ exports.toggle_emoji_popover = function (element, id) { if (elt.data('popover') === undefined) { // Keep the element over which the popover is based off visible. elt.addClass("reaction_button_visible"); - emoji_picker.render_emoji_popover(elt, id); + exports.render_emoji_popover(elt, id); } reset_emoji_showcase(); }; @@ -668,7 +664,7 @@ exports.register_click_handlers = function () { compose_ui.insert_syntax_and_focus(emoji_text); } e.stopPropagation(); - emoji_picker.hide_emoji_popover(); + exports.hide_emoji_popover(); }); $("body").on("click", "#emoji_map", function (e) { @@ -684,14 +680,14 @@ exports.register_click_handlers = function () { } else { edit_message_id = null; } - emoji_picker.toggle_emoji_popover(this); + exports.toggle_emoji_popover(this); }); $("#main_div").on("click", ".reaction_button", function (e) { e.stopPropagation(); var message_id = rows.get_message_id(this); - emoji_picker.toggle_emoji_popover(this, message_id); + exports.toggle_emoji_popover(this, message_id); }); $("#main_div").on("mouseenter", ".reaction_button", function (e) { @@ -724,7 +720,7 @@ exports.register_click_handlers = function () { // element is not present, we use the message's // .fa-chevron-down element as the base for the popover. var elem = $(".selected_message .actions_hover")[0]; - emoji_picker.toggle_emoji_popover(elem, message_id); + exports.toggle_emoji_popover(elem, message_id); }); $("body").on("click", ".emoji-popover-tab-item", function (e) { @@ -759,11 +755,4 @@ exports.initialize = function () { exports.generate_emoji_picker_data(emoji.active_realm_emojis); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = emoji_picker; -} -window.emoji_picker = emoji_picker; +window.emoji_picker = exports; diff --git a/static/js/favicon.js b/static/js/favicon.js index c48040bd68..f5f8490a3d 100644 --- a/static/js/favicon.js +++ b/static/js/favicon.js @@ -1,7 +1,3 @@ -var favicon = (function () { - -var exports = {}; - var favicon_selector = 'link[rel="shortcut icon"]'; // We need to reset the favicon after changing the @@ -28,9 +24,4 @@ exports.set = function (url) { }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = favicon; -} -window.favicon = favicon; +window.favicon = exports; diff --git a/static/js/feature_flags.js b/static/js/feature_flags.js index 1e65414652..643e5af97a 100644 --- a/static/js/feature_flags.js +++ b/static/js/feature_flags.js @@ -1,18 +1,7 @@ -var feature_flags = (function () { - -var exports = {}; - // The features below have all settled into their final states and can // be removed when we get a chance exports.propagate_topic_edits = true; exports.clicking_notification_causes_narrow = true; exports.reminders_in_message_action_menu = false; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = feature_flags; -} -window.feature_flags = feature_flags; +window.feature_flags = exports; diff --git a/static/js/feedback_widget.js b/static/js/feedback_widget.js index 041eed57b4..6f321c62c3 100644 --- a/static/js/feedback_widget.js +++ b/static/js/feedback_widget.js @@ -1,9 +1,5 @@ var render_feedback_container = require('../templates/feedback_container.hbs'); -var feedback_widget = (function () { - -var exports = {}; - /* This code lets you show something like this: @@ -140,10 +136,4 @@ exports.show = function (opts) { animate.fadeIn(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = feedback_widget; -} -window.feedback_widget = feedback_widget; +window.feedback_widget = exports; diff --git a/static/js/fenced_code.js b/static/js/fenced_code.js index 446109fefa..0b2f81653f 100644 --- a/static/js/fenced_code.js +++ b/static/js/fenced_code.js @@ -1,7 +1,3 @@ -var fenced_code = (function () { - -var exports = {}; - // Parsing routine that can be dropped in to message parsing // and formats code blocks // @@ -189,10 +185,4 @@ exports.process_fenced_code = function (content) { return output.join('\n'); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = fenced_code; -} -window.fenced_code = fenced_code; +window.fenced_code = exports; diff --git a/static/js/fetch_status.js b/static/js/fetch_status.js index 7546c25740..6b319f5f96 100644 --- a/static/js/fetch_status.js +++ b/static/js/fetch_status.js @@ -46,7 +46,5 @@ var FetchStatus = function () { return self; }; -if (typeof module !== 'undefined') { - module.exports = FetchStatus; -} +module.exports = FetchStatus; window.FetchStatus = FetchStatus; diff --git a/static/js/filter.js b/static/js/filter.js index fc9fced423..c8f950e42c 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -1,5 +1,3 @@ -var Filter = (function () { - function zephyr_stream_name_match(message, operand) { // Zephyr users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/ // (unsocial, ununsocial, social.d, etc) @@ -715,11 +713,6 @@ Filter.describe = function (operators) { return Handlebars.Utils.escapeExpression(describe_unescaped(operators)); }; -return Filter; - -}()); -if (typeof module !== 'undefined') { - module.exports = Filter; -} +module.exports = Filter; window.Filter = Filter; diff --git a/static/js/floating_recipient_bar.js b/static/js/floating_recipient_bar.js index a4ff02aaa0..c181890079 100644 --- a/static/js/floating_recipient_bar.js +++ b/static/js/floating_recipient_bar.js @@ -1,8 +1,3 @@ -var floating_recipient_bar = (function () { - -var exports = {}; - - var is_floating_recipient_bar_showing = false; function top_offset(elem) { @@ -332,10 +327,4 @@ exports.update = function () { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = floating_recipient_bar; -} -window.floating_recipient_bar = floating_recipient_bar; +window.floating_recipient_bar = exports; diff --git a/static/js/gear_menu.js b/static/js/gear_menu.js index 4435045812..077553a711 100644 --- a/static/js/gear_menu.js +++ b/static/js/gear_menu.js @@ -1,7 +1,3 @@ -var gear_menu = (function () { - -var exports = {}; - /* For various historical reasons there isn't one single chunk of code that really makes our gear @@ -140,10 +136,4 @@ exports.close = function () { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = gear_menu; -} -window.gear_menu = gear_menu; +window.gear_menu = exports; diff --git a/static/js/hash_util.js b/static/js/hash_util.js index ff25a2a333..f9394d0469 100644 --- a/static/js/hash_util.js +++ b/static/js/hash_util.js @@ -1,7 +1,3 @@ -var hash_util = (function () { - -var exports = {}; - exports.get_hash_category = function (hash) { // given "#streams/subscribed", returns "streams" return hash ? hash.replace(/^#/, "").split(/\//)[0] : ""; @@ -181,10 +177,4 @@ exports.parse_narrow = function (hash) { return operators; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = hash_util; -} -window.hash_util = hash_util; +window.hash_util = exports; diff --git a/static/js/hashchange.js b/static/js/hashchange.js index 0d30b4fc8f..f724e2d403 100644 --- a/static/js/hashchange.js +++ b/static/js/hashchange.js @@ -1,9 +1,5 @@ // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html // or locally: docs/subsystems/hashchange-system.md -var hashchange = (function () { - -var exports = {}; - var changing_hash = false; function get_full_url(hash) { @@ -313,10 +309,4 @@ exports.exit_overlay = function (callback) { } }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = hashchange; -} -window.hashchange = hashchange; +window.hashchange = exports; diff --git a/static/js/hotkey.js b/static/js/hotkey.js index b72173d222..446ae81a24 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -1,7 +1,3 @@ -var hotkeys = (function () { - -var exports = {}; - function do_narrow_action(action) { action(current_msg_list.selected_id(), {trigger: 'hotkey'}); return true; @@ -819,11 +815,4 @@ $(document).keypress(function (e) { } }); -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = hotkeys; -} -window.hotkey = hotkeys; +window.hotkey = exports; diff --git a/static/js/hotspots.js b/static/js/hotspots.js index 83ccc50f61..6758cc9ea7 100644 --- a/static/js/hotspots.js +++ b/static/js/hotspots.js @@ -1,10 +1,6 @@ var render_hotspot_overlay = require('../templates/hotspot_overlay.hbs'); var render_intro_reply_hotspot = require('../templates/intro_reply_hotspot.hbs'); -var hotspots = (function () { - -var exports = {}; - // popover orientations var TOP = 'top'; var LEFT = 'left'; @@ -257,9 +253,4 @@ exports.initialize = function () { exports.load_new(page_params.hotspots); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = hotspots; -} -window.hotspots = hotspots; +window.hotspots = exports; diff --git a/static/js/info_overlay.js b/static/js/info_overlay.js index bda7823b0c..60d83dcd23 100644 --- a/static/js/info_overlay.js +++ b/static/js/info_overlay.js @@ -1,7 +1,3 @@ -var info_overlay = (function () { - -var exports = {}; - // Make it explicit that our toggler is undefined until // set_up_toggler is called. exports.toggler = undefined; @@ -80,10 +76,4 @@ exports.maybe_show_keyboard_shortcuts = function () { exports.show("keyboard-shortcuts"); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = info_overlay; -} -window.info_overlay = info_overlay; +window.info_overlay = exports; diff --git a/static/js/input_pill.js b/static/js/input_pill.js index a0a65afdcd..9c1c24fe82 100644 --- a/static/js/input_pill.js +++ b/static/js/input_pill.js @@ -1,10 +1,6 @@ var render_input_pill = require('../templates/input_pill.hbs'); // See https://zulip.readthedocs.io/en/latest/subsystems/input-pills.html -var input_pill = (function () { - -var exports = {}; - exports.random_id = function () { return Math.random().toString(16); }; @@ -389,11 +385,4 @@ exports.create = function (opts) { return prototype; }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = input_pill; -} -window.input_pill = input_pill; +window.input_pill = exports; diff --git a/static/js/integration_bot_widget.js b/static/js/integration_bot_widget.js index 429350f578..ead05cd0b5 100644 --- a/static/js/integration_bot_widget.js +++ b/static/js/integration_bot_widget.js @@ -1,7 +1,3 @@ -var integration_bot_widget = (function () { - -var exports = {}; - // This function subscribes the newly created bot to the stream specified by the user. function subscribe_to_stream(bot_email, stream_name) { var bot_user_id = people.get_user_id(bot_email); @@ -74,11 +70,4 @@ exports.set_integration_bot_url = function ( stream_name, api_url, integration_url, on_create_bot_success); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = integration_bot_widget; -} -window.integration_bot_widget = integration_bot_widget; +window.integration_bot_widget = exports; diff --git a/static/js/invite.js b/static/js/invite.js index b1c6a8e8d0..9c2fc77523 100644 --- a/static/js/invite.js +++ b/static/js/invite.js @@ -4,10 +4,6 @@ var render_settings_dev_env_email_access = require('../templates/settings/dev_en var autosize = require('autosize'); -var invite = (function () { - -var exports = {}; - function reset_error_messages() { $('#invite_status').hide().text('').removeClass(common.status_classes); $('#multiuse_invite_status').hide().text('').removeClass(common.status_classes); @@ -197,11 +193,4 @@ exports.initialize = function () { }); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = invite; -} -window.invite = invite; +window.invite = exports; diff --git a/static/js/keydown_util.js b/static/js/keydown_util.js index 17ecf4260c..b97e62f873 100644 --- a/static/js/keydown_util.js +++ b/static/js/keydown_util.js @@ -1,7 +1,3 @@ -var keydown_util = (function () { - -var exports = {}; - /* See hotkey.js for handlers that are more app-wide. */ @@ -41,10 +37,4 @@ exports.handle = function (opts) { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = keydown_util; -} -window.keydown_util = keydown_util; +window.keydown_util = exports; diff --git a/static/js/lightbox.js b/static/js/lightbox.js index f38cccc111..b8099136dd 100644 --- a/static/js/lightbox.js +++ b/static/js/lightbox.js @@ -1,6 +1,3 @@ -var lightbox = (function () { -var exports = {}; - var is_open = false; // the asset map is a map of all retrieved images and YouTube videos that are // memoized instead of being looked up multiple times. @@ -276,9 +273,9 @@ exports.initialize = function () { var direction = $(this).attr("data-direction"); if (direction === 'next') { - lightbox.next(); + exports.next(); } else if (direction === 'prev') { - lightbox.prev(); + exports.prev(); } }); @@ -316,10 +313,4 @@ exports.initialize = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = lightbox; -} -window.lightbox = lightbox; +window.lightbox = exports; diff --git a/static/js/lightbox_canvas.js b/static/js/lightbox_canvas.js index c2a03fec28..ea7998d7ad 100644 --- a/static/js/lightbox_canvas.js +++ b/static/js/lightbox_canvas.js @@ -1,4 +1,3 @@ -var LightboxCanvas = (function () { var events = { documentMouseup: [], windowResize: [], @@ -259,7 +258,7 @@ var funcs = { }; // a class w/ prototype to create a new `LightboxCanvas` instance. -var __LightboxCanvas = function (el) { +var LightboxCanvas = function (el) { var self = this; this.meta = { @@ -302,7 +301,7 @@ var __LightboxCanvas = function (el) { funcs.attachEvents(this.canvas, this.context, self.meta); }; -__LightboxCanvas.prototype = { +LightboxCanvas.prototype = { // set the speed at which scrolling zooms in on a photo. speed: function (speed) { this.meta.speed = speed; @@ -327,10 +326,5 @@ __LightboxCanvas.prototype = { }, }; -return __LightboxCanvas; -}()); - -if (typeof module !== 'undefined') { - module.exports = LightboxCanvas; -} +module.exports = LightboxCanvas; window.LightboxCanvas = LightboxCanvas; diff --git a/static/js/list_cursor.js b/static/js/list_cursor.js index 9acb5a05de..758d79493d 100644 --- a/static/js/list_cursor.js +++ b/static/js/list_cursor.js @@ -139,7 +139,5 @@ var list_cursor = function (opts) { return self; }; -if (typeof module !== 'undefined') { - module.exports = list_cursor; -} +module.exports = list_cursor; window.list_cursor = list_cursor; diff --git a/static/js/list_render.js b/static/js/list_render.js index 5f45846904..ca0cf78525 100644 --- a/static/js/list_render.js +++ b/static/js/list_render.js @@ -1,7 +1,3 @@ -var list_render = (function () { - -var exports = {}; - var DEFAULTS = { INITIAL_RENDER_COUNT: 80, LOAD_COUNT: 20, @@ -361,7 +357,7 @@ exports.handle_sort = function () { var prop_name = $this.data("sort-prop"); var list_name = $this.closest(".progressive-table-wrapper").data("list-render"); - var list = list_render.get(list_name); + var list = exports.get(list_name); if (!list) { blueslip.error("Error. This `.progressive-table-wrapper` has no `data-list-render` attribute."); @@ -388,11 +384,4 @@ exports.handle_sort = function () { $this.addClass("active"); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = list_render; -} - -window.list_render = list_render; +window.list_render = exports; diff --git a/static/js/list_util.js b/static/js/list_util.js index 83266407f8..9e33a78a3c 100644 --- a/static/js/list_util.js +++ b/static/js/list_util.js @@ -1,7 +1,3 @@ -var list_util = (function () { - -var exports = {}; - var list_selectors = ["#group-pm-list", "#stream_filters", "#global_filters", "#user_presences"]; exports.inside_list = function (e) { @@ -20,11 +16,4 @@ exports.go_up = function (e) { $target.closest("li").prev().find("a").focus(); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = list_util; -} -window.list_util = list_util; +window.list_util = exports; diff --git a/static/js/loading.js b/static/js/loading.js index 6e4a4d16c3..91237bb10d 100644 --- a/static/js/loading.js +++ b/static/js/loading.js @@ -1,9 +1,5 @@ var render_loader = require("../templates/loader.hbs"); -var loading = (function () { - -var exports = {}; - exports.make_indicator = function (outer_container, opts) { opts = opts || {}; var container = outer_container; @@ -69,9 +65,4 @@ exports.destroy_indicator = function (container) { }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = loading; -} -window.loading = loading; +window.loading = exports; diff --git a/static/js/local_message.js b/static/js/local_message.js index 423e732bfa..10b65917e2 100644 --- a/static/js/local_message.js +++ b/static/js/local_message.js @@ -1,7 +1,3 @@ -var local_message = (function () { - -var exports = {}; - function truncate_precision(float) { return parseFloat(float.toFixed(3)); } @@ -57,11 +53,4 @@ exports.get_next_id = (function () { }; }()); -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = local_message; -} - -window.local_message = local_message; +window.local_message = exports; diff --git a/static/js/localstorage.js b/static/js/localstorage.js index 662944543e..e69f74aa09 100644 --- a/static/js/localstorage.js +++ b/static/js/localstorage.js @@ -1,5 +1,3 @@ -var localstorage = (function () { - var ls = { // parse JSON without throwing an error. parseJSON: function (str) { @@ -89,7 +87,7 @@ var ls = { }; // return a new function instance that has instance-scoped variables. -var exports = function () { +var localstorage = function () { var _data = { VERSION: 1, expires: Infinity, @@ -164,7 +162,7 @@ var exports = function () { var warned_of_localstorage = false; -exports.supported = function supports_localstorage() { +localstorage.supported = function supports_localstorage() { try { return window.hasOwnProperty('localStorage') && window.localStorage !== null; } catch (e) { @@ -176,10 +174,5 @@ exports.supported = function supports_localstorage() { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = localstorage; -} +module.exports = localstorage; window.localstorage = localstorage; diff --git a/static/js/markdown.js b/static/js/markdown.js index e2c5fd9050..3ff91cfc6e 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -4,11 +4,8 @@ // static/third/marked/lib/marked.js, which we have significantly // modified from the original implementation. -var markdown = (function () { // Docs: https://zulip.readthedocs.io/en/latest/subsystems/markdown.html -var exports = {}; - var realm_filter_map = {}; var realm_filter_list = []; @@ -442,10 +439,4 @@ exports.initialize = function () { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = markdown; -} -window.markdown = markdown; +window.markdown = exports; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 6a512243a8..0035fb95ae 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -2,8 +2,6 @@ var render_message_edit_form = require('../templates/message_edit_form.hbs'); var render_message_edit_history = require('../templates/message_edit_history.hbs'); var render_topic_edit_form = require('../templates/topic_edit_form.hbs'); -var message_edit = (function () { -var exports = {}; var currently_editing_messages = {}; var currently_deleting_messages = []; @@ -157,7 +155,7 @@ exports.save = function (row, from_topic_edited_only) { echo.edit_locally(message, new_content, topic_changed ? new_topic : undefined); row = current_msg_list.get_row(message_id); } - message_edit.end(row); + exports.end(row); return; } @@ -177,7 +175,7 @@ exports.save = function (row, from_topic_edited_only) { } if (!changed) { // If they didn't change anything, just cancel it. - message_edit.end(row); + exports.end(row); return; } channel.patch({ @@ -245,7 +243,7 @@ function handle_edit_keydown(from_topic_edited_only, e) { } e.stopPropagation(); e.preventDefault(); - message_edit.save(row, from_topic_edited_only); + exports.save(row, from_topic_edited_only); } function timer_text(seconds_left) { @@ -277,8 +275,8 @@ function edit_message(row, raw_content) { // zerver.views.messages.update_message_backend var seconds_left_buffer = 5; var editability = get_editability(message, seconds_left_buffer); - var is_editable = editability === message_edit.editability_types.TOPIC_ONLY || - editability === message_edit.editability_types.FULL; + var is_editable = editability === exports.editability_types.TOPIC_ONLY || + editability === exports.editability_types.FULL; var max_file_upload_size = page_params.max_file_upload_size; var file_upload_enabled = false; @@ -290,7 +288,7 @@ function edit_message(row, raw_content) { is_stream: message.type === 'stream', message_id: message.id, is_editable: is_editable, - is_content_editable: editability === message_edit.editability_types.FULL, + is_content_editable: editability === exports.editability_types.FULL, has_been_editable: editability !== editability_types.NO, topic: util.get_message_topic(message), content: raw_content, @@ -560,7 +558,7 @@ exports.edit_last_sent_message = function () { // Finally do the real work! compose_actions.cancel(); - message_edit.start(msg_row, function () { + exports.start(msg_row, function () { $('#message_edit_content').focus(); }); }; @@ -693,10 +691,4 @@ exports.handle_narrow_deactivated = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = message_edit; -} -window.message_edit = message_edit; +window.message_edit = exports; diff --git a/static/js/message_events.js b/static/js/message_events.js index bc1fddcbb4..b47073a172 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -1,7 +1,3 @@ -var message_events = (function () { - -var exports = {}; - function maybe_add_narrowed_messages(messages, msg_list) { var ids = []; _.each(messages, function (elem) { @@ -282,10 +278,4 @@ exports.update_messages = function update_messages(events) { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_events; -} -window.message_events = message_events; +window.message_events = exports; diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index e627927bd5..07766c77ba 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -1,7 +1,3 @@ -var message_fetch = (function () { - -var exports = {}; - var consts = { backfill_idle_time: 10 * 1000, error_retry_time: 5000, @@ -220,7 +216,7 @@ exports.load_messages = function (opts) { exports.load_messages_for_narrow = function (opts) { var msg_list = message_list.narrowed; - message_fetch.load_messages({ + exports.load_messages({ anchor: opts.then_select_id.toFixed(), num_before: consts.narrow_before, num_after: consts.narrow_after, @@ -381,10 +377,4 @@ exports.initialize = function () { } }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_fetch; -} -window.message_fetch = message_fetch; +window.message_fetch = exports; diff --git a/static/js/message_flags.js b/static/js/message_flags.js index 8ba01d6776..9227a98815 100644 --- a/static/js/message_flags.js +++ b/static/js/message_flags.js @@ -1,5 +1,3 @@ -var message_flags = (function () { -var exports = {}; function send_flag_update(message, flag, op) { channel.post({ url: '/json/messages/flags', @@ -30,7 +28,7 @@ exports.send_read = (function () { return; } - var real_msg_ids_batch = real_msg_ids.slice(0, message_flags._unread_batch_size); + var real_msg_ids_batch = real_msg_ids.slice(0, exports._unread_batch_size); // We have some real IDs. If there are any left in the queue when this // call finishes, they will be handled in the success callback. @@ -130,10 +128,4 @@ exports.unstar_all_messages = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = message_flags; -} -window.message_flags = message_flags; +window.message_flags = exports; diff --git a/static/js/message_list.js b/static/js/message_list.js index 7ba74a6eea..d5a1ce05d4 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -1,9 +1,5 @@ var autosize = require('autosize'); -var message_list = (function () { - -var exports = {}; - exports.narrowed = undefined; exports.set_narrowed = function (value) { exports.narrowed = value; @@ -449,10 +445,4 @@ $(document).on('message_selected.zulip wheel', function () { message_viewport.stop_auto_scrolling(); }); -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_list; -} -window.message_list = message_list; +window.message_list = exports; diff --git a/static/js/message_list_data.js b/static/js/message_list_data.js index 9c07d1ee60..b64d9e6cb2 100644 --- a/static/js/message_list_data.js +++ b/static/js/message_list_data.js @@ -570,8 +570,6 @@ MessageListData.prototype = { }, }; -if (typeof module !== 'undefined') { - module.exports = MessageListData; -} +module.exports = MessageListData; window.MessageListData = MessageListData; diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 68607aa377..325415a95e 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -19,8 +19,6 @@ function MessageListView(list, table_name, collapse_messages) { this._render_win_end = 0; } -(function () { - function get_user_id_for_mention_button(elem) { var user_id = $(elem).attr('data-user-id'); // Handle legacy markdown that was rendered before we cut @@ -1357,9 +1355,5 @@ MessageListView.prototype = { }, }; -}()); - -if (typeof module !== 'undefined') { - module.exports = MessageListView; -} +module.exports = MessageListView; window.MessageListView = MessageListView; diff --git a/static/js/message_live_update.js b/static/js/message_live_update.js index 69c1e2cf9d..e47a85e96c 100644 --- a/static/js/message_live_update.js +++ b/static/js/message_live_update.js @@ -1,7 +1,3 @@ -var message_live_update = (function () { - -var exports = {}; - exports.update_stream_name = function (stream_id, new_name) { _.each([home_msg_list, message_list.narrowed, message_list.all], function (list) { if (list === undefined) { @@ -32,11 +28,4 @@ exports.update_avatar = function (user_id, avatar_url) { }); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_live_update; -} - -window.message_live_update = message_live_update; +window.message_live_update = exports; diff --git a/static/js/message_scroll.js b/static/js/message_scroll.js index 7bc11abaec..07839bc2b4 100644 --- a/static/js/message_scroll.js +++ b/static/js/message_scroll.js @@ -1,7 +1,3 @@ -var message_scroll = (function () { - -var exports = {}; - var actively_scrolling = false; var loading_more_messages_indicator_showing = false; @@ -80,10 +76,4 @@ exports.initialize = function () { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_scroll; -} -window.message_scroll = message_scroll; +window.message_scroll = exports; diff --git a/static/js/message_store.js b/static/js/message_store.js index ed3300cec7..a99b87658d 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -1,6 +1,3 @@ -var message_store = (function () { - -var exports = {}; var stored_messages = {}; exports.get = function get(message_id) { @@ -194,10 +191,4 @@ exports.reify_message_id = function (opts) { }); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_store; -} -window.message_store = message_store; +window.message_store = exports; diff --git a/static/js/message_util.js b/static/js/message_util.js index 5822b73eec..584f0be6b7 100644 --- a/static/js/message_util.js +++ b/static/js/message_util.js @@ -1,7 +1,3 @@ -var message_util = (function () { - -var exports = {}; - exports.do_unread_count_updates = function do_unread_count_updates(messages) { unread.process_loaded_messages(messages); unread_ui.update_unread_counts(); @@ -29,10 +25,4 @@ exports.add_new_messages = function (messages, msg_list) { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = message_util; -} -window.message_util = message_util; +window.message_util = exports; diff --git a/static/js/message_viewport.js b/static/js/message_viewport.js index f154d51fa2..af39832553 100644 --- a/static/js/message_viewport.js +++ b/static/js/message_viewport.js @@ -1,6 +1,3 @@ -var message_viewport = (function () { -var exports = {}; - var jwindow; var dimensions = {}; var in_stoppable_autoscroll = false; @@ -226,7 +223,7 @@ exports.scrollTop = function viewport_scrollTop(target_scrollTop) { } var ret = exports.message_pane.scrollTop(target_scrollTop); var new_scrollTop = exports.message_pane.scrollTop(); - var space_to_scroll = $("#bottom_whitespace").offset().top - message_viewport.height(); + var space_to_scroll = $("#bottom_whitespace").offset().top - exports.height(); // Check whether our scrollTop didn't move even though one could have scrolled down if (space_to_scroll > 0 && target_scrollTop > 0 && @@ -359,12 +356,12 @@ exports.keep_pointer_in_view = function () { return; } - var info = message_viewport.message_viewport_info(); + var info = exports.message_viewport_info(); var top_threshold = info.visible_top + 1 / 10 * info.visible_height; var bottom_threshold = info.visible_top + 9 / 10 * info.visible_height; function message_is_far_enough_down() { - if (message_viewport.at_top()) { + if (exports.at_top()) { return true; } @@ -390,7 +387,7 @@ exports.keep_pointer_in_view = function () { } function message_is_far_enough_up() { - return message_viewport.at_bottom() || + return exports.at_bottom() || next_row.offset().top <= bottom_threshold; } @@ -433,10 +430,4 @@ exports.initialize = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = message_viewport; -} -window.message_viewport = message_viewport; +window.message_viewport = exports; diff --git a/static/js/muting.js b/static/js/muting.js index 0aa37bcbc4..9b35d0a97f 100644 --- a/static/js/muting.js +++ b/static/js/muting.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var muting = (function () { - -var exports = {}; - var muted_topics = new Dict(); exports.add_muted_topic = function (stream_id, topic) { @@ -62,9 +58,4 @@ exports.initialize = function () { exports.set_muted_topics(page_params.muted_topics); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = muting; -} -window.muting = muting; +window.muting = exports; diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js index 4f1a554373..416642d2f1 100644 --- a/static/js/muting_ui.js +++ b/static/js/muting_ui.js @@ -1,10 +1,6 @@ var render_muted_topic_ui_row = require('../templates/muted_topic_ui_row.hbs'); var render_topic_muted = require('../templates/topic_muted.hbs'); -var muting_ui = (function () { - -var exports = {}; - function timestamp_ms() { return (new Date()).getTime(); } @@ -144,10 +140,4 @@ exports.toggle_mute = function (message) { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = muting_ui; -} -window.muting_ui = muting_ui; +window.muting_ui = exports; diff --git a/static/js/narrow.js b/static/js/narrow.js index dee3bee709..7a2a0578a1 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -1,7 +1,3 @@ -var narrow = (function () { - -var exports = {}; - var unnarrow_times; function report_narrow_time(initial_core_time, initial_free_time, network_time) { @@ -953,10 +949,4 @@ exports.hide_empty_narrow_message = function () { $("#left_bar_compose_reply_button_big").removeAttr("disabled"); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = narrow; -} -window.narrow = narrow; +window.narrow = exports; diff --git a/static/js/narrow_state.js b/static/js/narrow_state.js index 62f96b49cf..1468306c3a 100644 --- a/static/js/narrow_state.js +++ b/static/js/narrow_state.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var narrow_state = (function () { - -var exports = {}; - var current_filter; exports.reset_current_filter = function () { @@ -361,10 +357,4 @@ exports.is_for_stream_id = function (stream_id) { return stream_id === narrow_stream_id; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = narrow_state; -} -window.narrow_state = narrow_state; +window.narrow_state = exports; diff --git a/static/js/navigate.js b/static/js/navigate.js index 42425f7850..0b8801d0fc 100644 --- a/static/js/navigate.js +++ b/static/js/navigate.js @@ -1,8 +1,3 @@ -var navigate = (function () { - -var exports = {}; - - function go_to_row(msg_id) { current_msg_list.select_id(msg_id, {then_scroll: true, @@ -146,10 +141,4 @@ exports.maybe_scroll_to_selected = function () { -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = navigate; -} -window.navigate = navigate; +window.navigate = exports; diff --git a/static/js/night_mode.js b/static/js/night_mode.js index d4daa33c15..2dec1fd6ba 100644 --- a/static/js/night_mode.js +++ b/static/js/night_mode.js @@ -1,7 +1,3 @@ -var night_mode = (function () { - -var exports = {}; - exports.enable = function () { $("body").addClass("night-mode"); }; @@ -10,10 +6,4 @@ exports.disable = function () { $("body").removeClass("night-mode"); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = night_mode; -} -window.night_mode = night_mode; +window.night_mode = exports; diff --git a/static/js/notifications.js b/static/js/notifications.js index 23e77c2c1c..202561a36b 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -1,10 +1,6 @@ var render_compose_notification = require('../templates/compose_notification.hbs'); var render_notification = require('../templates/notification.hbs'); -var notifications = (function () { - -var exports = {}; - var notice_memory = {}; // When you start Zulip, window_has_focus should be true, but it might not be the @@ -192,9 +188,9 @@ exports.hide_or_show_history_limit_message = function (msg_list) { } if (msg_list.fetch_status.history_limited()) { - notifications.show_history_limit_message(); + exports.show_history_limit_message(); } else { - notifications.hide_history_limit_message(); + exports.hide_history_limit_message(); } }; @@ -747,11 +743,4 @@ exports.handle_global_notification_updates = function (notification_name, settin } }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = notifications; -} -window.notifications = notifications; +window.notifications = exports; diff --git a/static/js/overlays.js b/static/js/overlays.js index ab0a319f51..f8f39b0658 100644 --- a/static/js/overlays.js +++ b/static/js/overlays.js @@ -1,7 +1,3 @@ -var overlays = (function () { - -var exports = {}; - var active_overlay; var close_handler; var open_overlay_name; @@ -186,7 +182,7 @@ exports.close_for_hash_change = function () { }; exports.open_settings = function () { - overlays.open_overlay({ + exports.open_overlay({ name: 'settings', overlay: $("#settings_overlay_container"), on_close: function () { @@ -217,11 +213,4 @@ exports.initialize = function () { }); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = overlays; -} -window.overlays = overlays; +window.overlays = exports; diff --git a/static/js/padded_widget.js b/static/js/padded_widget.js index 1896326ae9..67e92bef00 100644 --- a/static/js/padded_widget.js +++ b/static/js/padded_widget.js @@ -1,7 +1,3 @@ -var padded_widget = (function () { - -var exports = {}; - exports.update_padding = function (opts) { var content = $(opts.content_sel); var padding = $(opts.padding_sel); @@ -24,10 +20,4 @@ exports.update_padding = function (opts) { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = padded_widget; -} -window.padded_widget = padded_widget; +window.padded_widget = exports; diff --git a/static/js/panels.js b/static/js/panels.js index 2fc7f533e6..f3c12c4e0c 100644 --- a/static/js/panels.js +++ b/static/js/panels.js @@ -1,7 +1,3 @@ -var panels = (function () { - -var exports = {}; - var resize_app = function () { var panels_height = $("#panels").height(); $("body > .app").height("calc(100% - " + panels_height + "px)"); @@ -24,9 +20,9 @@ exports.initialize = function () { // if email has not been set up and the user is the admin, display a warning // to tell them to set up an email server. if (page_params.warn_no_email === true && page_params.is_admin) { - panels.open($("[data-process='email-server']")); + exports.open($("[data-process='email-server']")); } else { - panels.open($("[data-process='notifications']")); + exports.open($("[data-process='notifications']")); } }; @@ -88,11 +84,4 @@ exports.open = function ($process) { }); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = panels; -} -window.panels = panels; +window.panels = exports; diff --git a/static/js/people.js b/static/js/people.js index d2a56cefe2..460fa71d9c 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var people = (function () { - -var exports = {}; - var people_dict; var people_by_name_dict; var people_by_user_id_dict; @@ -93,7 +89,7 @@ exports.update_email = function (user_id, new_email) { }; exports.get_user_id = function (email) { - var person = people.get_by_email(email); + var person = exports.get_by_email(email); if (person === undefined) { var error_msg = 'Unknown email for get_user_id: ' + email; blueslip.error(error_msg); @@ -205,7 +201,7 @@ exports.reply_to_to_user_ids_string = function (emails_string) { var emails = emails_string.split(','); var user_ids = _.map(emails, function (email) { - var person = people.get_by_email(email); + var person = exports.get_by_email(email); if (person) { return person.user_id; } @@ -221,7 +217,7 @@ exports.reply_to_to_user_ids_string = function (emails_string) { }; exports.get_user_time_preferences = function (user_id) { - var user_timezone = people.get_person_from_user_id(user_id).timezone; + var user_timezone = exports.get_person_from_user_id(user_id).timezone; if (user_timezone) { if (page_params.twenty_four_hour_time) { return { @@ -237,7 +233,7 @@ exports.get_user_time_preferences = function (user_id) { }; exports.get_user_time = function (user_id) { - var user_pref = people.get_user_time_preferences(user_id); + var user_pref = exports.get_user_time_preferences(user_id); if (user_pref) { return moment().tz(user_pref.timezone).format(user_pref.format); } @@ -263,7 +259,7 @@ exports.emails_strings_to_user_ids_string = function (emails_string) { exports.email_list_to_user_ids_string = function (emails) { var user_ids = _.map(emails, function (email) { - var person = people.get_by_email(email); + var person = exports.get_by_email(email); if (person) { return person.user_id; } @@ -312,7 +308,7 @@ exports.get_recipients = function (user_ids_string) { }; exports.pm_reply_user_string = function (message) { - var user_ids = people.pm_with_user_ids(message); + var user_ids = exports.pm_with_user_ids(message); if (!user_ids) { return; @@ -322,7 +318,7 @@ exports.pm_reply_user_string = function (message) { }; exports.pm_reply_to = function (message) { - var user_ids = people.pm_with_user_ids(message); + var user_ids = exports.pm_with_user_ids(message); if (!user_ids) { return; @@ -349,7 +345,7 @@ function sorted_other_user_ids(user_ids) { // (i.e. you sent a message to yourself). var other_user_ids = _.filter(user_ids, function (user_id) { - return !people.is_my_user_id(user_id); + return !exports.is_my_user_id(user_id); }); if (other_user_ids.length >= 1) { @@ -422,7 +418,7 @@ exports.group_pm_with_user_ids = function (message) { return elem.user_id || elem.id; }); var is_user_present = _.some(user_ids, function (user_id) { - return people.is_my_user_id(user_id); + return exports.is_my_user_id(user_id); }); if (is_user_present) { user_ids.sort(); @@ -661,11 +657,11 @@ exports.small_avatar_url = function (message) { }; exports.is_valid_email_for_compose = function (email) { - if (people.is_cross_realm_email(email)) { + if (exports.is_cross_realm_email(email)) { return true; } - var person = people.get_by_email(email); + var person = exports.get_by_email(email); if (!person) { return false; } @@ -675,7 +671,7 @@ exports.is_valid_email_for_compose = function (email) { exports.is_valid_bulk_emails_for_compose = function (emails) { // Returns false if at least one of the emails is invalid. return _.every(emails, function (email) { - if (!people.is_valid_email_for_compose(email)) { + if (!exports.is_valid_email_for_compose(email)) { return false; } return true; @@ -683,7 +679,7 @@ exports.is_valid_bulk_emails_for_compose = function (emails) { }; exports.get_active_user_for_email = function (email) { - var person = people.get_by_email(email); + var person = exports.get_by_email(email); if (!person) { return; } @@ -731,7 +727,7 @@ exports.get_active_user_ids = function () { }; exports.is_cross_realm_email = function (email) { - var person = people.get_by_email(email); + var person = exports.get_by_email(email); if (!person) { return; } @@ -892,7 +888,7 @@ exports.get_mention_syntax = function (full_name, user_id, silent) { if (!user_id) { blueslip.warn('get_mention_syntax called without user_id.'); } - if (people.is_duplicate_full_name(full_name) && user_id) { + if (exports.is_duplicate_full_name(full_name) && user_id) { mention += '|' + user_id; } mention += '**'; @@ -1094,10 +1090,4 @@ exports.initialize = function () { delete page_params.cross_realm_bots; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = people; -} -window.people = people; +window.people = exports; diff --git a/static/js/pm_conversations.js b/static/js/pm_conversations.js index 3ab3bf0c62..852e3f7500 100644 --- a/static/js/pm_conversations.js +++ b/static/js/pm_conversations.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var pm_conversations = (function () { - -var exports = {}; - var partners = new Dict(); exports.set_partner = function (user_id) { @@ -62,10 +58,4 @@ exports.recent = (function () { return self; }()); -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = pm_conversations; -} -window.pm_conversations = pm_conversations; +window.pm_conversations = exports; diff --git a/static/js/pm_list.js b/static/js/pm_list.js index 29cfbcc3b0..35a8bf6386 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -1,9 +1,5 @@ var render_sidebar_private_message_list = require('../templates/sidebar_private_message_list.hbs'); -var pm_list = (function () { - -var exports = {}; - var private_messages_open = false; // This module manages the "Private Messages" section in the upper @@ -45,7 +41,7 @@ exports.get_li_for_user_ids_string = function (user_ids_string) { }; function set_pm_conversation_count(user_ids_string, count) { - var pm_li = pm_list.get_li_for_user_ids_string(user_ids_string); + var pm_li = exports.get_li_for_user_ids_string(user_ids_string); var count_span = pm_li.find('.private_message_count'); var value_span = count_span.find('.value'); @@ -196,10 +192,4 @@ exports.update_dom_with_unread_counts = function (counts) { exports.initialize = function () { }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = pm_list; -} - -window.pm_list = pm_list; +window.pm_list = exports; diff --git a/static/js/pointer.js b/static/js/pointer.js index 26e21ff709..9d68455037 100644 --- a/static/js/pointer.js +++ b/static/js/pointer.js @@ -1,10 +1,6 @@ // See https://zulip.readthedocs.io/en/latest/subsystems/pointer.html for notes on // how this system is designed. -var pointer = (function () { - -var exports = {}; - exports.recenter_pointer_on_display = false; exports.set_recenter_pointer_on_display = function (value) { exports.recenter_pointer_on_display = value; @@ -33,9 +29,9 @@ function update_pointer() { return channel.post({ url: '/json/users/me/pointer', idempotent: true, - data: {pointer: pointer.furthest_read}, + data: {exports: exports.furthest_read}, success: function () { - pointer.server_furthest_read = pointer.furthest_read; + exports.server_furthest_read = exports.furthest_read; pointer_update_in_flight = false; }, error: function () { @@ -50,7 +46,7 @@ function update_pointer() { exports.send_pointer_update = function () { // Only bother if you've read new messages. - if (pointer.furthest_read > pointer.server_furthest_read) { + if (exports.furthest_read > exports.server_furthest_read) { update_pointer(); } }; @@ -74,7 +70,7 @@ exports.fast_forward_pointer = function () { idempotent: true, success: function (data) { unread_ops.mark_all_as_read(function () { - pointer.furthest_read = data.max_message_id; + exports.furthest_read = data.max_message_id; unconditionally_send_pointer_update().then(function () { reload.initiate({immediate: true, save_pointer: false, @@ -87,17 +83,17 @@ exports.fast_forward_pointer = function () { }; exports.initialize = function initialize() { - pointer.server_furthest_read = page_params.pointer; + exports.server_furthest_read = page_params.pointer; if (page_params.orig_initial_pointer !== undefined && - page_params.orig_initial_pointer > pointer.server_furthest_read) { - pointer.server_furthest_read = page_params.orig_initial_pointer; + page_params.orig_initial_pointer > exports.server_furthest_read) { + exports.server_furthest_read = page_params.orig_initial_pointer; } - pointer.furthest_read = pointer.server_furthest_read; + exports.furthest_read = exports.server_furthest_read; // We only send pointer updates when the user has been idle for a // short while to avoid hammering the server $(document).idle({idle: 1000, - onIdle: pointer.send_pointer_update, + onIdle: exports.send_pointer_update, keepTracking: true}); $(document).on('message_selected.zulip', function (event) { @@ -108,10 +104,10 @@ exports.initialize = function initialize() { // Additionally, don't advance the pointer server-side // if the selected message is local-only if (event.msg_list === home_msg_list && page_params.narrow_stream === undefined) { - if (event.id > pointer.furthest_read) { + if (event.id > exports.furthest_read) { var msg = home_msg_list.get(event.id); if (!msg.locally_echoed) { - pointer.furthest_read = event.id; + exports.furthest_read = event.id; } } } @@ -131,9 +127,4 @@ exports.initialize = function initialize() { }); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = pointer; -} -window.pointer = pointer; +window.pointer = exports; diff --git a/static/js/poll_widget.js b/static/js/poll_widget.js index daacdf721a..9b2a77265a 100644 --- a/static/js/poll_widget.js +++ b/static/js/poll_widget.js @@ -1,10 +1,6 @@ var render_widgets_poll_widget = require('../templates/widgets/poll_widget.hbs'); var render_widgets_poll_widget_results = require('../templates/widgets/poll_widget_results.hbs'); -var poll_widget = (function () { - -var exports = {}; - exports.poll_data_holder = function (is_my_poll, question, options) { // This object just holds data for a poll, although it // works closely with the widget's concept of how data @@ -372,11 +368,4 @@ exports.activate = function (opts) { render_results(); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = poll_widget; -} - -window.poll_widget = poll_widget; +window.poll_widget = exports; diff --git a/static/js/popovers.js b/static/js/popovers.js index 02d5debbd0..9586d73d01 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -10,10 +10,6 @@ var render_user_info_popover_content = require('../templates/user_info_popover_c var render_user_info_popover_title = require('../templates/user_info_popover_title.hbs'); var render_user_profile_modal = require("../templates/user_profile_modal.hbs"); -var popovers = (function () { - -var exports = {}; - var current_actions_popover_elem; var current_flatpickr_instance; var current_message_info_popover_elem; @@ -232,7 +228,7 @@ exports._test_calculate_info_popover_placement = calculate_info_popover_placemen // message is the message containing it, which should be selected function show_user_info_popover(element, user, message) { var last_popover_elem = current_message_info_popover_elem; - popovers.hide_all(); + exports.hide_all(); if (last_popover_elem !== undefined && last_popover_elem.get()[0] === element) { // We want it to be the case that a user can dismiss a popover @@ -259,7 +255,7 @@ function show_user_info_popover(element, user, message) { function show_mobile_message_buttons_popover(element) { var last_popover_elem = current_mobile_message_buttons_popover_elem; - popovers.hide_all(); + exports.hide_all(); if (last_popover_elem !== undefined && last_popover_elem.get()[0] === element) { // We want it to be the case that a user can dismiss a popover @@ -294,7 +290,7 @@ exports.hide_user_profile = function () { }; exports.show_user_profile = function (user) { - popovers.hide_all(); + exports.hide_all(); var dateFormat = moment.localeData().longDateFormat('LL'); var field_types = page_params.custom_profile_field_types; @@ -373,7 +369,7 @@ function show_user_group_info_popover(element, group, message) { // hardcoded pixel height of the popover // note that the actual size varies (in group size), but this is about as big as it gets var popover_size = 390; - popovers.hide_all(); + exports.hide_all(); if (last_popover_elem !== undefined && last_popover_elem.get()[0] === element) { // We want it to be the case that a user can dismiss a popover @@ -402,7 +398,7 @@ function show_user_group_info_popover(element, group, message) { exports.toggle_actions_popover = function (element, id) { var last_popover_elem = current_actions_popover_elem; - popovers.hide_all(); + exports.hide_all(); if (last_popover_elem !== undefined && last_popover_elem.get()[0] === element) { // We want it to be the case that a user can dismiss a popover @@ -500,7 +496,7 @@ exports.toggle_actions_popover = function (element, id) { }; exports.render_actions_remind_popover = function (element, id) { - popovers.hide_all(); + exports.hide_all(); $(element).closest('.message_row').toggleClass('has_popover has_actions_popover'); current_msg_list.select_id(id); var elt = $(element); @@ -589,7 +585,7 @@ exports.open_message_menu = function (message) { } var id = message.id; - popovers.toggle_actions_popover($(".selected_message .actions_hover")[0], id); + exports.toggle_actions_popover($(".selected_message .actions_hover")[0], id); if (current_actions_popover_elem) { focus_first_action_popover_item(); } @@ -606,7 +602,7 @@ exports.actions_popped = function () { }; exports.hide_actions_popover = function () { - if (popovers.actions_popped()) { + if (exports.actions_popped()) { $('.has_popover').removeClass('has_popover has_actions_popover'); current_actions_popover_elem.popover("destroy"); current_actions_popover_elem = undefined; @@ -706,7 +702,7 @@ exports.register_click_handlers = function () { $("#main_div").on("click", ".actions_hover", function (e) { var row = $(this).closest(".message_row"); e.stopPropagation(); - popovers.toggle_actions_popover(this, rows.id(row)); + exports.toggle_actions_popover(this, rows.id(row)); }); $("#main_div").on("click", ".sender_name, .sender_name-in-status, .inline_profile_picture", function (e) { @@ -756,7 +752,7 @@ exports.register_click_handlers = function () { $('body').on('click', '.info_popover_actions .narrow_to_private_messages', function (e) { var user_id = $(e.target).parents('ul').attr('data-user-id'); var email = people.get_person_from_user_id(user_id).email; - popovers.hide_message_info_popover(); + exports.hide_message_info_popover(); narrow.by('pm-with', email, {trigger: 'user sidebar popover'}); e.stopPropagation(); e.preventDefault(); @@ -765,7 +761,7 @@ exports.register_click_handlers = function () { $('body').on('click', '.info_popover_actions .narrow_to_messages_sent', function (e) { var user_id = $(e.target).parents('ul').attr('data-user-id'); var email = people.get_person_from_user_id(user_id).email; - popovers.hide_message_info_popover(); + exports.hide_message_info_popover(); narrow.by('sender', email, {trigger: 'user sidebar popover'}); e.stopPropagation(); e.preventDefault(); @@ -779,8 +775,8 @@ exports.register_click_handlers = function () { var name = people.get_person_from_user_id(user_id).full_name; var mention = people.get_mention_syntax(name, user_id); compose_ui.insert_syntax_and_focus(mention); - popovers.hide_user_sidebar_popover(); - popovers.hide_userlist_sidebar(); + exports.hide_user_sidebar_popover(); + exports.hide_userlist_sidebar(); e.stopPropagation(); e.preventDefault(); }); @@ -793,7 +789,7 @@ exports.register_click_handlers = function () { var name = people.get_person_from_user_id(user_id).full_name; var mention = people.get_mention_syntax(name, user_id); compose_ui.insert_syntax_and_focus(mention); - popovers.hide_message_info_popover(); + exports.hide_message_info_popover(); e.stopPropagation(); e.preventDefault(); }); @@ -835,21 +831,21 @@ exports.register_click_handlers = function () { }); $('body').on('click', '.set_away_status', function (e) { - popovers.hide_all(); + exports.hide_all(); user_status.server_set_away(); e.stopPropagation(); e.preventDefault(); }); $('body').on('click', '.revoke_away_status', function (e) { - popovers.hide_all(); + exports.hide_all(); user_status.server_revoke_away(); e.stopPropagation(); e.preventDefault(); }); $('body').on('click', '.update_status_text', function (e) { - popovers.hide_all(); + exports.hide_all(); user_status_ui.open_overlay(); @@ -868,13 +864,13 @@ exports.register_click_handlers = function () { if (String(current_user_sidebar_user_id) === user_id) { // If the popover is already shown, clicking again should toggle it. // We don't want to hide the sidebars on smaller browser windows. - popovers.hide_all_except_sidebars(); + exports.hide_all_except_sidebars(); return; } - popovers.hide_all(); + exports.hide_all(); if (userlist_placement === "right") { - popovers.show_userlist_sidebar(); + exports.show_userlist_sidebar(); } else { // Maintain the same behavior when displaying with the streamlist. stream_popover.show_streamlist_sidebar(); @@ -907,14 +903,14 @@ exports.register_click_handlers = function () { // compose_actions.respond_to_message doesn't take a message // argument). compose_actions.quote_and_reply({trigger: 'popover respond'}); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); e.stopPropagation(); e.preventDefault(); }); $('body').on('click', '.reminder_button', function (e) { var message_id = $(e.currentTarget).data('message-id'); - popovers.render_actions_remind_popover($(".selected_message .actions_hover")[0], message_id); + exports.render_actions_remind_popover($(".selected_message .actions_hover")[0], message_id); e.stopPropagation(); e.preventDefault(); }); @@ -928,7 +924,7 @@ exports.register_click_handlers = function () { function reminder_click_handler(datestr, e) { var id = $(".remind.custom").data('message-id'); reminder.do_set_reminder_for_message(id, datestr); - popovers.hide_all(); + exports.hide_all(); e.stopPropagation(); e.preventDefault(); } @@ -974,7 +970,7 @@ exports.register_click_handlers = function () { compose_actions.start('private', { trigger: 'popover send private', private_message_recipient: email}); - popovers.hide_all(); + exports.hide_all(); e.stopPropagation(); e.preventDefault(); }); @@ -983,7 +979,7 @@ exports.register_click_handlers = function () { var row = current_msg_list.get_row(message_id); var message = current_msg_list.get(rows.id(row)); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); if (row) { if (message.collapsed) { @@ -999,7 +995,7 @@ exports.register_click_handlers = function () { $('body').on('click', '.popover_edit_message', function (e) { var message_id = $(e.currentTarget).data('message-id'); var row = current_msg_list.get_row(message_id); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); message_edit.start(row); e.stopPropagation(); e.preventDefault(); @@ -1010,7 +1006,7 @@ exports.register_click_handlers = function () { var message = current_msg_list.get(rows.id(row)); var message_history_cancel_btn = $('#message-history-cancel'); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); message_edit.show_history(message); message_history_cancel_btn.focus(); e.stopPropagation(); @@ -1021,7 +1017,7 @@ exports.register_click_handlers = function () { var stream_id = $(e.currentTarget).attr('data-msg-stream-id'); var topic = $(e.currentTarget).attr('data-msg-topic'); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); muting_ui.mute(stream_id, topic); e.stopPropagation(); e.preventDefault(); @@ -1031,7 +1027,7 @@ exports.register_click_handlers = function () { var stream_id = $(e.currentTarget).attr('data-msg-stream-id'); var topic = $(e.currentTarget).attr('data-msg-topic'); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); muting_ui.unmute(stream_id, topic); e.stopPropagation(); e.preventDefault(); @@ -1039,7 +1035,7 @@ exports.register_click_handlers = function () { $('body').on('click', '.delete_message', function (e) { var message_id = $(e.currentTarget).data('message-id'); - popovers.hide_actions_popover(); + exports.hide_actions_popover(); message_edit.delete_message(message_id); e.stopPropagation(); e.preventDefault(); @@ -1048,7 +1044,7 @@ exports.register_click_handlers = function () { new ClipboardJS('.copy_link'); $('body').on('click', '.copy_link', function (e) { - popovers.hide_actions_popover(); + exports.hide_actions_popover(); var id = $(this).attr("data-message-id"); var row = $("[zid='" + id + "']"); row.find(".alert-msg") @@ -1080,7 +1076,7 @@ exports.register_click_handlers = function () { // only run `popovers.hide_all()` if the last scroll was more // than 250ms ago. if (date - last_scroll > 250) { - popovers.hide_all(); + exports.hide_all(); } // update the scroll time on every event to make sure it doesn't @@ -1093,7 +1089,7 @@ exports.register_click_handlers = function () { exports.any_active = function () { // True if any popover (that this module manages) is currently shown. // Expanded sidebars on mobile view count as popovers as well. - return popovers.actions_popped() || user_sidebar_popped() || + return exports.actions_popped() || user_sidebar_popped() || stream_popover.stream_popped() || stream_popover.topic_popped() || exports.message_info_popped() || emoji_picker.reactions_popped() || $("[class^='column-'].expanded").length; @@ -1104,16 +1100,16 @@ exports.any_active = function () { // like a popover structurally). exports.hide_all_except_sidebars = function () { $('.has_popover').removeClass('has_popover has_actions_popover has_emoji_popover'); - popovers.hide_actions_popover(); - popovers.hide_message_info_popover(); + exports.hide_actions_popover(); + exports.hide_message_info_popover(); emoji_picker.hide_emoji_popover(); stream_popover.hide_stream_popover(); stream_popover.hide_topic_popover(); stream_popover.hide_all_messages_popover(); stream_popover.hide_starred_messages_popover(); - popovers.hide_user_sidebar_popover(); - popovers.hide_mobile_message_buttons_popover(); - popovers.hide_user_profile(); + exports.hide_user_sidebar_popover(); + exports.hide_mobile_message_buttons_popover(); + exports.hide_user_profile(); // look through all the popovers that have been added and removed. list_of_popovers.forEach(function ($o) { @@ -1127,9 +1123,9 @@ exports.hide_all_except_sidebars = function () { // This function will hide all the popovers, including the mobile web // or narrow window sidebars. exports.hide_all = function () { - popovers.hide_userlist_sidebar(); + exports.hide_userlist_sidebar(); stream_popover.hide_streamlist_sidebar(); - popovers.hide_all_except_sidebars(); + exports.hide_all_except_sidebars(); }; exports.set_userlist_placement = function (placement) { @@ -1179,10 +1175,4 @@ exports.compute_placement = function (elt, popover_height, popover_width, return placement; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = popovers; -} -window.popovers = popovers; +window.popovers = exports; diff --git a/static/js/portico/help.js b/static/js/portico/help.js index 52bd4e99bf..25520d1f5e 100644 --- a/static/js/portico/help.js +++ b/static/js/portico/help.js @@ -63,7 +63,6 @@ function scrollToHash(simplebar) { } } -(function () { var html_map = {}; var loading = { name: null, @@ -167,4 +166,3 @@ window.addEventListener("popstate", function () { }); $('body').addClass('noscroll'); -}()); diff --git a/static/js/portico/integrations_dev_panel.js b/static/js/portico/integrations_dev_panel.js index 4cf4a8effc..e8f327d00c 100644 --- a/static/js/portico/integrations_dev_panel.js +++ b/static/js/portico/integrations_dev_panel.js @@ -1,6 +1,5 @@ // Main JavaScript file for the Integrations development panel at // /devtools/integrations. -(function () { // Data Segment: We lazy load the requested fixtures from the backend // as and when required and then cache them here. @@ -342,5 +341,3 @@ $(function () { $("#topic_name").change(update_url); }); - -}()); diff --git a/static/js/portico/tabbed-instructions.js b/static/js/portico/tabbed-instructions.js index a965b57b8a..77681db5d6 100644 --- a/static/js/portico/tabbed-instructions.js +++ b/static/js/portico/tabbed-instructions.js @@ -56,8 +56,6 @@ export function activate_correct_tab($codeSection) { } } -(function () { $(".code-section").each(function () { activate_correct_tab($(this)); }); -}()); diff --git a/static/js/presence.js b/static/js/presence.js index 4eef9d760f..99b20216ac 100644 --- a/static/js/presence.js +++ b/static/js/presence.js @@ -1,6 +1,3 @@ -var presence = (function () { -var exports = {}; - // This module just manages data. See activity.js for // the UI of our buddy list. @@ -172,10 +169,4 @@ exports.last_active_date = function (user_id) { return date; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = presence; -} -window.presence = presence; +window.presence = exports; diff --git a/static/js/reactions.js b/static/js/reactions.js index 8052131ed4..ec89753c33 100644 --- a/static/js/reactions.js +++ b/static/js/reactions.js @@ -1,9 +1,6 @@ var render_message_reaction = require('../templates/message_reaction.hbs'); var Dict = require('./dict').Dict; -var reactions = (function () { -var exports = {}; - exports.view = {}; // function namespace exports.get_local_reaction_id = function (reaction_info) { @@ -443,10 +440,4 @@ exports.get_message_reactions = function (message) { return reactions; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = reactions; -} -window.reactions = reactions; +window.reactions = exports; diff --git a/static/js/realm_icon.js b/static/js/realm_icon.js index d7941732fe..d27f1756fb 100644 --- a/static/js/realm_icon.js +++ b/static/js/realm_icon.js @@ -1,7 +1,3 @@ -var realm_icon = (function () { - -var exports = {}; - exports.build_realm_icon_widget = function (upload_function) { var get_file_input = function () { return $('#realm_icon_file_input').expectOne(); @@ -42,10 +38,4 @@ exports.rerender = function () { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = realm_icon; -} -window.realm_icon = realm_icon; +window.realm_icon = exports; diff --git a/static/js/realm_logo.js b/static/js/realm_logo.js index 2c262524f2..faf08a64cc 100644 --- a/static/js/realm_logo.js +++ b/static/js/realm_logo.js @@ -1,6 +1,3 @@ -var realm_logo = (function () { -var exports = {}; - exports.build_realm_logo_widget = function (upload_function, is_night) { var logo_section_id = '#day-logo-section'; if (is_night) { @@ -83,10 +80,4 @@ exports.rerender = function () { night_file_input); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = realm_logo; -} -window.realm_logo = realm_logo; +window.realm_logo = exports; diff --git a/static/js/recent_senders.js b/static/js/recent_senders.js index 3187df57ac..37ba9ed801 100644 --- a/static/js/recent_senders.js +++ b/static/js/recent_senders.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var recent_senders = (function () { - -var exports = {}; - var topic_senders = new Dict(); // key is stream-id, value is Dict var stream_senders = new Dict(); // key is stream-id, value is Dict @@ -67,10 +63,4 @@ exports.compare_by_recency = function (user_a, user_b, stream_id, topic) { return 0; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = recent_senders; -} -window.recent_senders = recent_senders; +window.recent_senders = exports; diff --git a/static/js/reload.js b/static/js/reload.js index 2c5816bfaa..e36faa9cd9 100644 --- a/static/js/reload.js +++ b/static/js/reload.js @@ -1,8 +1,4 @@ // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html -var reload = (function () { - -var exports = {}; - function preserve_state(send_after_reload, save_pointer, save_narrow, save_compose) { if (!localstorage.supported()) { // If local storage is not supported by the browser, we can't @@ -310,10 +306,4 @@ window.addEventListener('beforeunload', function () { }); -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = reload; -} -window.reload = reload; +window.reload = exports; diff --git a/static/js/reload_state.js b/static/js/reload_state.js index 87a02d3b1b..ad1ab87a92 100644 --- a/static/js/reload_state.js +++ b/static/js/reload_state.js @@ -1,7 +1,3 @@ -var reload_state = (function () { - -var exports = {}; - /* We want his module to load pretty early in the process of starting the app, so that people.js can load early. @@ -34,10 +30,4 @@ exports.set_state_to_in_progress = function () { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = reload_state; -} -window.reload_state = reload_state; +window.reload_state = exports; diff --git a/static/js/reminder.js b/static/js/reminder.js index f18139017d..8ba201ecad 100644 --- a/static/js/reminder.js +++ b/static/js/reminder.js @@ -1,7 +1,3 @@ -var reminder = (function () { - -var exports = {}; - var deferred_message_types = { scheduled: { delivery_type: 'send_later', @@ -151,12 +147,4 @@ exports.do_set_reminder_for_message = function (message_id, timestamp) { transmit.send_message(reminder_message, success, error); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = reminder; -} - -window.reminder = reminder; +window.reminder = exports; diff --git a/static/js/resize.js b/static/js/resize.js index c527a4c1e4..ca0aef5d8f 100644 --- a/static/js/resize.js +++ b/static/js/resize.js @@ -1,9 +1,5 @@ var autosize = require('autosize'); -var resize = (function () { - -var exports = {}; - var narrow_window = false; function confine_to_range(lo, val, hi) { @@ -281,10 +277,4 @@ exports.handler = function () { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = resize; -} -window.resize = resize; +window.resize = exports; diff --git a/static/js/rows.js b/static/js/rows.js index 6374620bf2..2383cf1913 100644 --- a/static/js/rows.js +++ b/static/js/rows.js @@ -1,7 +1,3 @@ -var rows = (function () { - -var exports = {}; - // We don't need an andSelf() here because we already know // that our next element is *not* a message_row, so this // isn't going to end up empty unless we're at the bottom or top. @@ -107,11 +103,4 @@ exports.id_for_recipient_row = function (recipient_row) { return exports.id(msg_row); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = rows; -} -window.rows = rows; +window.rows = exports; diff --git a/static/js/rtl.js b/static/js/rtl.js index 9fb509f084..0540246695 100644 --- a/static/js/rtl.js +++ b/static/js/rtl.js @@ -1,7 +1,3 @@ -var rtl = (function () { - -var exports = {}; - // How to determine the direction of a paragraph (P1-P3): http://www.unicode.org/reports/tr9/tr9-35.html#The_Paragraph_Level // Embedding level: http://www.unicode.org/reports/tr9/tr9-35.html#BD2 // How to find the matching PDI for an isolation initiator: http://www.unicode.org/reports/tr9/tr9-35.html#BD9 @@ -146,10 +142,4 @@ exports.set_rtl_class_for_textarea = function (textarea) { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = rtl; -} -window.rtl = rtl; +window.rtl = exports; diff --git a/static/js/schema.js b/static/js/schema.js index a596b43548..1bb1c6a729 100644 --- a/static/js/schema.js +++ b/static/js/schema.js @@ -1,7 +1,3 @@ -var schema = (function () { - -var exports = {}; - /* These runtime schema validators are defensive and @@ -57,11 +53,4 @@ exports.check_array = function (var_name, val, checker) { } }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = schema; -} - -window.schema = schema; +window.schema = exports; diff --git a/static/js/scroll_bar.js b/static/js/scroll_bar.js index 00562e5d2f..85b61f659b 100644 --- a/static/js/scroll_bar.js +++ b/static/js/scroll_bar.js @@ -1,7 +1,3 @@ -var scroll_bar = (function () { - -var exports = {}; - // A few of our width properties in zulip depend on the width of the // browser scrollbar that is generated at the far right side of the // page, which unfortunately varies depending on the browser and @@ -82,10 +78,4 @@ exports.set_layout_width = function () { } }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = scroll_bar; -} - -window.scroll_bar = scroll_bar; +window.scroll_bar = exports; diff --git a/static/js/scroll_util.js b/static/js/scroll_util.js index 4f92571d29..95e821612b 100644 --- a/static/js/scroll_util.js +++ b/static/js/scroll_util.js @@ -1,7 +1,3 @@ -var scroll_util = (function () { - -var exports = {}; - exports.scroll_delta = function (opts) { var elem_top = opts.elem_top; var container_height = opts.container_height; @@ -53,9 +49,4 @@ exports.scroll_element_into_container = function (elem, container) { container.scrollTop(container.scrollTop() + delta); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = scroll_util; -} -window.scroll_util = scroll_util; +window.scroll_util = exports; diff --git a/static/js/search.js b/static/js/search.js index 12548f936b..905fc4867b 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -1,7 +1,3 @@ -var search = (function () { - -var exports = {}; - // Exported for unit testing exports.is_using_input_method = false; @@ -218,10 +214,4 @@ exports.clear_search_form = function () { $('.search_button').prop('disabled', true); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = search; -} -window.search = search; +window.search = exports; diff --git a/static/js/search_pill.js b/static/js/search_pill.js index 4bcc14b761..816e1f528c 100644 --- a/static/js/search_pill.js +++ b/static/js/search_pill.js @@ -1,6 +1,3 @@ -var search_pill = (function () { -var exports = {}; - exports.create_item_from_search_string = function (search_string) { var operator = Filter.parse(search_string); var description = Filter.describe(operator); @@ -36,11 +33,4 @@ exports.get_search_string_for_current_filter = function (pill_widget) { return search_strings.join(' '); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = search_pill; -} - -window.search_pill = search_pill; +window.search_pill = exports; diff --git a/static/js/search_pill_widget.js b/static/js/search_pill_widget.js index a65c837cfe..fcedd8ed1b 100644 --- a/static/js/search_pill_widget.js +++ b/static/js/search_pill_widget.js @@ -1,7 +1,3 @@ -var search_pill_widget = (function () { - -var exports = {}; - exports.initialize = function () { if (!page_params.search_pills_enabled) { return; @@ -16,11 +12,4 @@ exports.initialize = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = search_pill_widget; -} - -window.search_pill_widget = search_pill_widget; +window.search_pill_widget = exports; diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index a1fe09bcfe..a81d067fcc 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -1,7 +1,3 @@ -var search_suggestion = (function () { - -var exports = {}; - function stream_matches_query(stream_name, q) { return common.phrase_match(q, stream_name); } @@ -828,9 +824,4 @@ exports.get_suggestions_legacy = function (query) { }; }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = search_suggestion; -} -window.search_suggestion = search_suggestion; +window.search_suggestion = exports; diff --git a/static/js/search_util.js b/static/js/search_util.js index 8d65875af3..e3d39d3680 100644 --- a/static/js/search_util.js +++ b/static/js/search_util.js @@ -1,7 +1,3 @@ -var search_util = (function () { - -var exports = {}; - exports.get_search_terms = function (input) { var search_terms = input.toLowerCase().split(",").map(function (s) { return s.trim(); @@ -28,10 +24,4 @@ exports.vanilla_match = function (opts) { }); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = search_util; -} -window.search_util = search_util; +window.search_util = exports; diff --git a/static/js/sent_messages.js b/static/js/sent_messages.js index 020d568e3e..147c102561 100644 --- a/static/js/sent_messages.js +++ b/static/js/sent_messages.js @@ -1,7 +1,3 @@ -var sent_messages = (function () { - -var exports = {}; - exports.messages = {}; exports.reset_id_state = function () { @@ -176,10 +172,4 @@ exports.initialize = function () { exports.reset_id_state(); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = sent_messages; -} -window.sent_messages = sent_messages; +window.sent_messages = exports; diff --git a/static/js/server_events.js b/static/js/server_events.js index f7b7ba7837..28ccaf5dc8 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -1,8 +1,5 @@ -var server_events = (function () { // Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html -var exports = {}; - var waiting_on_homeview_load = true; var events_stored_while_loading = []; @@ -333,10 +330,4 @@ window.addEventListener("beforeunload", function () { // For unit testing exports._get_events_success = get_events_success; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = server_events; -} -window.server_events = server_events; +window.server_events = exports; diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 9859dc14e6..8aadcf1cb4 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -1,7 +1,3 @@ -var server_events_dispatch = (function () { - -var exports = {}; - exports.dispatch_normal_event = function dispatch_normal_event(event) { var noop = function () {}; switch (event.type) { @@ -518,10 +514,4 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = server_events_dispatch; -} -window.server_events_dispatch = server_events_dispatch; +window.server_events_dispatch = exports; diff --git a/static/js/settings.js b/static/js/settings.js index c005d0ff6c..cbb7e4f18a 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -1,9 +1,5 @@ var render_settings_tab = require('../templates/settings_tab.hbs'); -var settings = (function () { - -var exports = {}; - $("body").ready(function () { var $sidebar = $(".form-sidebar"); var $targets = $sidebar.find("[data-target]"); @@ -111,7 +107,7 @@ exports.build_page = function () { botserverrc: 'botserverrc', timezones: moment.tz.names(), can_create_new_bots: settings_bots.can_create_new_bots(), - settings_label: settings.settings_label, + settings_label: exports.settings_label, demote_inactive_streams_values: settings_display.demote_inactive_streams_values, notification_settings: settings_notifications.all_notifications.settings, desktop_icon_count_display_values: settings_notifications.desktop_icon_count_display_values, @@ -145,10 +141,4 @@ exports.set_settings_header = function (key) { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings; -} -window.settings = settings; +window.settings = exports; diff --git a/static/js/settings_account.js b/static/js/settings_account.js index f9a3114d31..15771cb29e 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -2,10 +2,6 @@ var render_settings_custom_user_profile_field = require("../templates/settings/c var render_settings_dev_env_email_access = require('../templates/settings/dev_env_email_access.hbs'); var render_settings_api_key_modal = require('../templates/settings/api_key_modal.hbs'); -var settings_account = (function () { - -var exports = {}; - exports.update_email = function (new_email) { var email_input = $('#email_value'); @@ -601,10 +597,4 @@ exports.set_up = function () { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_account; -} -window.settings_account = settings_account; +window.settings_account = exports; diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js index 19539c25ac..2c5e8dd56e 100644 --- a/static/js/settings_bots.js +++ b/static/js/settings_bots.js @@ -3,10 +3,6 @@ var render_edit_bot = require('../templates/edit_bot.hbs'); var render_settings_edit_embedded_bot_service = require("../templates/settings/edit_embedded_bot_service.hbs"); var render_settings_edit_outgoing_webhook_service = require("../templates/settings/edit_outgoing_webhook_service.hbs"); -var settings_bots = (function () { - -var exports = {}; - exports.hide_errors = function () { $('#bot_table_error').hide(); $('.bot_error').hide(); @@ -95,7 +91,7 @@ exports.render_bots = function () { user_owns_an_active_bot = user_owns_an_active_bot || elem.is_active; }); - if (settings_bots.can_create_new_bots()) { + if (exports.can_create_new_bots()) { if (!user_owns_an_active_bot) { focus_tab.add_a_new_bot_tab(); return; @@ -524,10 +520,4 @@ exports.set_up = function () { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_bots; -} -window.settings_bots = settings_bots; +window.settings_bots = exports; diff --git a/static/js/settings_display.js b/static/js/settings_display.js index 502e4fec3b..6d98fd38f3 100644 --- a/static/js/settings_display.js +++ b/static/js/settings_display.js @@ -1,7 +1,3 @@ -var settings_display = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -192,10 +188,4 @@ exports.update_page = function () { // Longer term, we'll want to automate this function }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_display; -} -window.settings_display = settings_display; +window.settings_display = exports; diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js index 9c1b1db73e..fbb2b6dea9 100644 --- a/static/js/settings_emoji.js +++ b/static/js/settings_emoji.js @@ -1,10 +1,6 @@ var render_admin_emoji_list = require('../templates/admin_emoji_list.hbs'); var render_settings_emoji_settings_tip = require("../templates/settings/emoji_settings_tip.hbs"); -var settings_emoji = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -169,10 +165,4 @@ exports.set_up = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_emoji; -} -window.settings_emoji = settings_emoji; +window.settings_emoji = exports; diff --git a/static/js/settings_exports.js b/static/js/settings_exports.js index 311728c79a..4e24824472 100644 --- a/static/js/settings_exports.js +++ b/static/js/settings_exports.js @@ -1,9 +1,5 @@ var render_admin_export_list = require('../templates/admin_export_list.hbs'); -var settings_exports = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -116,9 +112,4 @@ exports.set_up = function () { }); }; -return exports; -}()); -if (typeof modules !== 'undefined') { - module.exports = settings_exports; -} -window.settings_exports = settings_exports; +window.settings_exports = exports; diff --git a/static/js/settings_invites.js b/static/js/settings_invites.js index 828c979ae3..c64baa06a5 100644 --- a/static/js/settings_invites.js +++ b/static/js/settings_invites.js @@ -1,10 +1,6 @@ var render_admin_invites_list = require("../templates/admin_invites_list.hbs"); var render_settings_revoke_invite_modal = require("../templates/settings/revoke_invite_modal.hbs"); -var settings_invites = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -203,10 +199,4 @@ exports.on_load_success = function (invites_data, initialize_event_handlers) { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_invites; -} -window.settings_invites = settings_invites; +window.settings_invites = exports; diff --git a/static/js/settings_linkifiers.js b/static/js/settings_linkifiers.js index a9eec298e6..57512eeebd 100644 --- a/static/js/settings_linkifiers.js +++ b/static/js/settings_linkifiers.js @@ -1,9 +1,5 @@ var render_admin_filter_list = require("../templates/admin_filter_list.hbs"); -var settings_linkifiers = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -161,10 +157,4 @@ exports.build_page = function () { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_linkifiers; -} -window.settings_linkifiers = settings_linkifiers; +window.settings_linkifiers = exports; diff --git a/static/js/settings_muting.js b/static/js/settings_muting.js index cdf544d68a..c73cedcac1 100644 --- a/static/js/settings_muting.js +++ b/static/js/settings_muting.js @@ -1,7 +1,3 @@ -var settings_muting = (function () { - -var exports = {}; - exports.set_up = function () { $('body').on('click', '.settings-unmute-topic', function (e) { var $row = $(this).closest("tr"); @@ -17,10 +13,4 @@ exports.set_up = function () { muting_ui.set_up_muted_topics_ui(muting.get_muted_topics()); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_muting; -} -window.settings_muting = settings_muting; +window.settings_muting = exports; diff --git a/static/js/settings_notifications.js b/static/js/settings_notifications.js index a20ce796be..bbda8ea103 100644 --- a/static/js/settings_notifications.js +++ b/static/js/settings_notifications.js @@ -1,7 +1,3 @@ -var settings_notifications = (function () { - -var exports = {}; - var stream_notification_settings = [ "enable_stream_desktop_notifications", "enable_stream_audible_notifications", @@ -156,10 +152,4 @@ exports.update_page = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_notifications; -} -window.settings_notifications = settings_notifications; +window.settings_notifications = exports; diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 29afba1a1d..ec603bff94 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -3,10 +3,6 @@ var render_settings_admin_realm_domains_list = require("../templates/settings/ad var render_settings_admin_realm_dropdown_stream_list = require("../templates/settings/admin_realm_dropdown_stream_list.hbs"); var render_settings_organization_settings_tip = require("../templates/settings/organization_settings_tip.hbs"); -var settings_org = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -1210,10 +1206,4 @@ exports.build_page = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_org; -} -window.settings_org = settings_org; +window.settings_org = exports; diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.js index 646c43b01c..3e99d25a02 100644 --- a/static/js/settings_panel_menu.js +++ b/static/js/settings_panel_menu.js @@ -1,7 +1,3 @@ -var settings_panel_menu = (function () { - -var exports = {}; - exports.make_menu = function (opts) { var main_elem = opts.main_elem; var hash_prefix = opts.hash_prefix; @@ -133,12 +129,4 @@ exports.set_key_handlers = function (toggler) { exports.org_settings.set_key_handlers(toggler); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_panel_menu; -} - -window.settings_panel_menu = settings_panel_menu; +window.settings_panel_menu = exports; diff --git a/static/js/settings_profile_fields.js b/static/js/settings_profile_fields.js index da6fb45143..5d246879d9 100644 --- a/static/js/settings_profile_fields.js +++ b/static/js/settings_profile_fields.js @@ -1,10 +1,6 @@ var render_admin_profile_field_list = require("../templates/admin_profile_field_list.hbs"); var render_settings_profile_field_choice = require("../templates/settings/profile_field_choice.hbs"); -var settings_profile_fields = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -467,10 +463,4 @@ exports.build_page = function () { clear_form_data(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_profile_fields; -} -window.settings_profile_fields = settings_profile_fields; +window.settings_profile_fields = exports; diff --git a/static/js/settings_sections.js b/static/js/settings_sections.js index f06bb6ed54..b7dfca09e1 100644 --- a/static/js/settings_sections.js +++ b/static/js/settings_sections.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var settings_sections = (function () { - -var exports = {}; - var load_func_dict = new Dict(); // group -> function var is_loaded = new Dict(); // group -> bool @@ -83,10 +79,4 @@ exports.reset_sections = function () { settings_users.reset(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_sections; -} -window.settings_sections = settings_sections; +window.settings_sections = exports; diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js index 1b755a2f63..364389bd4f 100644 --- a/static/js/settings_streams.js +++ b/static/js/settings_streams.js @@ -1,10 +1,6 @@ var render_admin_default_streams_list = require("../templates/admin_default_streams_list.hbs"); var Dict = require('./dict').Dict; -var settings_streams = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -165,10 +161,4 @@ exports.build_page = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_streams; -} -window.settings_streams = settings_streams; +window.settings_streams = exports; diff --git a/static/js/settings_toggle.js b/static/js/settings_toggle.js index 8abf36abaa..f58fec3b83 100644 --- a/static/js/settings_toggle.js +++ b/static/js/settings_toggle.js @@ -1,7 +1,3 @@ -var settings_toggle = (function () { - -var exports = {}; - var toggler; exports.highlight_toggle = function (tab_name) { @@ -65,11 +61,4 @@ exports.toggle_org_setting_collapse = function () { } }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_toggle; -} -window.settings_toggle = settings_toggle; +window.settings_toggle = exports; diff --git a/static/js/settings_ui.js b/static/js/settings_ui.js index 99205b5746..e0ef08a467 100644 --- a/static/js/settings_ui.js +++ b/static/js/settings_ui.js @@ -1,7 +1,3 @@ -var settings_ui = (function () { - -var exports = {}; - exports.display_checkmark = function ($elem) { var check_mark = document.createElement("img"); check_mark.src = "/static/images/checkbox-green.svg"; @@ -46,7 +42,7 @@ exports.do_settings_change = function (request_method, url, data, status_element success: function (reponse_data) { setTimeout(function () { ui_report.success(success_msg, spinner, remove_after); - settings_ui.display_checkmark(spinner); + exports.display_checkmark(spinner); }, appear_after); if (success_continuation !== undefined) { if (opts !== undefined && opts.success_continuation_arg) { @@ -87,10 +83,4 @@ exports.disable_sub_setting_onchange = function (is_checked, sub_setting_id, dis } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_ui; -} -window.settings_ui = settings_ui; +window.settings_ui = exports; diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js index cd52185917..9565d889c9 100644 --- a/static/js/settings_user_groups.js +++ b/static/js/settings_user_groups.js @@ -1,10 +1,6 @@ var render_admin_user_group_list = require('../templates/admin_user_group_list.hbs'); var render_confirm_delete_user = require('../templates/confirm_delete_user.hbs'); -var settings_user_groups = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -212,7 +208,7 @@ exports.populate_user_groups = function () { } if ($(event.relatedTarget).closest('#user-groups #' + data.id) && $(event.relatedTarget).closest('.save-status.btn-danger').length) { - settings_user_groups.reload(); + exports.reload(); return; } save_name_desc(); @@ -311,7 +307,7 @@ exports.set_up = function () { }, success: function () { user_groups.remove(user_group); - settings_user_groups.reload(); + exports.reload(); }, error: function () { btn.text(i18n.t("Failed!")); @@ -342,10 +338,4 @@ exports.set_up = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_user_groups; -} -window.settings_user_groups = settings_user_groups; +window.settings_user_groups = exports; diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 04999bee93..08c9d8d8e7 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -2,10 +2,6 @@ var render_admin_user_list = require("../templates/admin_user_list.hbs"); var render_bot_owner_select = require("../templates/bot_owner_select.hbs"); var render_user_info_form_modal = require('../templates/user_info_form_modal.hbs'); -var settings_users = (function () { - -var exports = {}; - var meta = { loaded: false, }; @@ -501,10 +497,4 @@ exports.on_load_success = function (realm_people_data) { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = settings_users; -} -window.settings_users = settings_users; +window.settings_users = exports; diff --git a/static/js/socket.js b/static/js/socket.js index 24819b66b9..f829ed22ab 100644 --- a/static/js/socket.js +++ b/static/js/socket.js @@ -1,5 +1,3 @@ -var Socket = (function () { - var CLOSE_REASONS = { none_given: {code: 4000, msg: "No reason provided"}, no_heartbeat: {code: 4001, msg: "Missed too many heartbeats"}, @@ -401,10 +399,5 @@ Socket.prototype = { }, }; -return Socket; -}()); - -if (typeof module !== 'undefined') { - module.exports = Socket; -} +module.exports = Socket; window.Socket = Socket; diff --git a/static/js/starred_messages.js b/static/js/starred_messages.js index c61e1d945b..3bf6bb9b34 100644 --- a/static/js/starred_messages.js +++ b/static/js/starred_messages.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var starred_messages = (function () { - -var exports = {}; - exports.ids = new Dict(); exports.initialize = function () { @@ -49,12 +45,4 @@ exports.rerender_ui = function () { top_left_corner.update_starred_count(count); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = starred_messages; -} - -window.starred_messages = starred_messages; +window.starred_messages = exports; diff --git a/static/js/stream_color.js b/static/js/stream_color.js index f9ed60b973..49c0941580 100644 --- a/static/js/stream_color.js +++ b/static/js/stream_color.js @@ -1,7 +1,3 @@ -var stream_color = (function () { - -var exports = {}; - exports.default_color = "#c2c2c2"; // Classes which could be returned by get_color_class. @@ -163,10 +159,4 @@ exports.get_color_class = _.memoize(function (color) { return lightness < lightness_threshold ? 'dark_background' : ''; }); -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = stream_color; -} -window.stream_color = stream_color; +window.stream_color = exports; diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 3f20a72e32..1450e3d65b 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -2,10 +2,6 @@ var render_announce_stream_docs = require('../templates/announce_stream_docs.hbs var render_new_stream_users = require('../templates/new_stream_users.hbs'); var render_subscription_invites_warning_modal = require('../templates/subscription_invites_warning_modal.hbs'); -var stream_create = (function () { - -var exports = {}; - var created_stream; exports.reset_created_stream = function () { @@ -461,10 +457,4 @@ exports.set_up_handlers = function () { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = stream_create; -} -window.stream_create = stream_create; +window.stream_create = exports; diff --git a/static/js/stream_data.js b/static/js/stream_data.js index d5e8ac8656..234e0cd34c 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var stream_data = (function () { - -var exports = {}; - // The stream_info variable maps stream names to stream properties objects // Call clear_subscriptions() to initialize it. @@ -231,10 +227,10 @@ exports.get_invite_stream_data = function () { name: sub.name, stream_id: sub.stream_id, invite_only: sub.invite_only, - default_stream: stream_data.get_default_status(sub.name), + default_stream: exports.get_default_status(sub.name), }; }; - var invite_stream_data = _.map(stream_data.subscribed_subs(), filter_stream_data); + var invite_stream_data = _.map(exports.subscribed_subs(), filter_stream_data); var default_stream_data = _.map(page_params.realm_default_streams, filter_stream_data); // Since, union doesn't work on array of objects we are using filter @@ -654,7 +650,7 @@ exports.sort_for_stream_settings = function (stream_ids) { // which uses Intl.Collator() when possible. function name(stream_id) { - var sub = stream_data.get_sub_by_id(stream_id); + var sub = exports.get_sub_by_id(stream_id); if (!sub) { return ''; } @@ -736,10 +732,4 @@ exports.remove_default_stream = function (stream_id) { default_stream_ids.del(stream_id); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = stream_data; -} -window.stream_data = stream_data; +window.stream_data = exports; diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 5c4d1657d1..ae99c8780c 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -3,10 +3,6 @@ var render_stream_member_list_entry = require('../templates/stream_member_list_e var render_subscription_settings = require('../templates/subscription_settings.hbs'); var render_subscription_stream_privacy_modal = require("../templates/subscription_stream_privacy_modal.hbs"); -var stream_edit = (function () { - -var exports = {}; - function setup_subscriptions_stream_hash(sub) { var hash = hash_util.stream_edit_uri(sub); hashchange.update_browser_history(hash); @@ -83,7 +79,7 @@ exports.open_edit_panel_for_row = function (stream_row) { subs.show_subs_pane.settings(); $(stream_row).addClass("active"); setup_subscriptions_stream_hash(sub); - stream_edit.show_settings_for(stream_row); + exports.show_settings_for(stream_row); }; exports.open_edit_panel_empty = function () { @@ -666,10 +662,4 @@ exports.initialize = function () { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = stream_edit; -} -window.stream_edit = stream_edit; +window.stream_edit = exports; diff --git a/static/js/stream_events.js b/static/js/stream_events.js index 63e0a35467..6eae95f9c5 100644 --- a/static/js/stream_events.js +++ b/static/js/stream_events.js @@ -1,7 +1,3 @@ -var stream_events = (function () { - -var exports = {}; - // In theory, this group of functions should apply the account-level // defaults, however, they are only called after a manual override, so // doing so is unnecessary with the current code. Ideally, we'd do a @@ -143,10 +139,4 @@ exports.remove_deactivated_user_from_all_streams = function (user_id) { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = stream_events; -} -window.stream_events = stream_events; +window.stream_events = exports; diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 9a8f50dabd..046efa6297 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -2,10 +2,6 @@ var render_stream_privacy = require('../templates/stream_privacy.hbs'); var render_stream_sidebar_row = require('../templates/stream_sidebar_row.hbs'); var Dict = require('./dict').Dict; -var stream_list = (function () { - -var exports = {}; - var has_scrolled = false; exports.update_count_in_dom = function (unread_count_elem, count) { @@ -469,11 +465,11 @@ function actually_update_streams_for_search() { var update_streams_for_search = _.throttle(actually_update_streams_for_search, 50); exports.initialize = function () { - stream_list.create_initial_sidebar_rows(); + exports.create_initial_sidebar_rows(); // We build the stream_list now. It may get re-built again very shortly // when new messages come in, but it's fairly quick. - stream_list.build_stream_list(); + exports.build_stream_list(); exports.set_event_handlers(); }; @@ -645,9 +641,9 @@ exports.maybe_scroll_narrow_into_view = function () { return; } - var stream_li = stream_list.get_current_stream_li(); + var stream_li = exports.get_current_stream_li(); if (stream_li) { - stream_list.scroll_stream_into_view(stream_li); + exports.scroll_stream_into_view(stream_li); } }; @@ -659,7 +655,7 @@ exports.get_current_stream_li = function () { return; } - var stream_li = stream_list.get_stream_li(stream_id); + var stream_li = exports.get_stream_li(stream_id); if (!stream_li) { // This code path shouldn't ever be reached. @@ -670,9 +666,4 @@ exports.get_current_stream_li = function () { return stream_li; }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = stream_list; -} -window.stream_list = stream_list; +window.stream_list = exports; diff --git a/static/js/stream_muting.js b/static/js/stream_muting.js index 5fe09677b9..4e274f9918 100644 --- a/static/js/stream_muting.js +++ b/static/js/stream_muting.js @@ -1,7 +1,3 @@ -var stream_muting = (function () { - -var exports = {}; - exports.update_is_muted = function (sub, value) { sub.is_muted = value; @@ -52,11 +48,4 @@ exports.update_is_muted = function (sub, value) { is_muted_checkbox.prop('checked', value); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = stream_muting; -} - -window.stream_muting = stream_muting; +window.stream_muting = exports; diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js index 93eed147a9..7e14a5f374 100644 --- a/static/js/stream_popover.js +++ b/static/js/stream_popover.js @@ -5,10 +5,6 @@ var render_stream_sidebar_actions = require('../templates/stream_sidebar_actions var render_topic_sidebar_actions = require('../templates/topic_sidebar_actions.hbs'); var render_unstar_messages_modal = require("../templates/unstar_messages_modal.hbs"); -var stream_popover = (function () { - -var exports = {}; - // We handle stream popovers and topic popovers in this // module. Both are popped up from the left sidebar. var current_stream_sidebar_elem; @@ -497,10 +493,4 @@ exports.register_topic_handlers = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = stream_popover; -} -window.stream_popover = stream_popover; +window.stream_popover = exports; diff --git a/static/js/stream_sort.js b/static/js/stream_sort.js index b08d8fd8c1..148aeff14b 100644 --- a/static/js/stream_sort.js +++ b/static/js/stream_sort.js @@ -1,7 +1,3 @@ -var stream_sort = (function () { - -var exports = {}; - var previous_pinned; var previous_normal; var previous_dormant; @@ -137,9 +133,4 @@ exports.next_stream_id = function (stream_id) { return maybe_get_stream_id(i + 1); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = stream_sort; -} -window.stream_sort = stream_sort; +window.stream_sort = exports; diff --git a/static/js/stream_ui_updates.js b/static/js/stream_ui_updates.js index 1eb7c16abb..2621f51c58 100644 --- a/static/js/stream_ui_updates.js +++ b/static/js/stream_ui_updates.js @@ -2,10 +2,6 @@ var render_subscription_count = require("../templates/subscription_count.hbs"); var render_subscription_setting_icon = require('../templates/subscription_setting_icon.hbs'); var render_subscription_type = require('../templates/subscription_type.hbs'); -var stream_ui_updates = (function () { - -var exports = {}; - exports.update_check_button_for_sub = function (sub) { var button = subs.check_button_for_sub(sub); if (sub.subscribed) { @@ -212,10 +208,4 @@ exports.update_add_subscriptions_elements = function (sub) { } }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = stream_ui_updates; -} -window.stream_ui_updates = stream_ui_updates; +window.stream_ui_updates = exports; diff --git a/static/js/submessage.js b/static/js/submessage.js index 47c61a138a..a9e37d600e 100644 --- a/static/js/submessage.js +++ b/static/js/submessage.js @@ -1,7 +1,3 @@ -var submessage = (function () { - -var exports = {}; - exports.get_message_events = function (message) { if (message.locally_echoed) { return; @@ -153,11 +149,4 @@ exports.make_server_callback = function (message_id) { }; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = submessage; -} - -window.submessage = submessage; +window.submessage = exports; diff --git a/static/js/subs.js b/static/js/subs.js index 495bbdaf4f..1945b5412c 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -3,10 +3,6 @@ var render_subscription_settings = require('../templates/subscription_settings.h var render_subscription_table_body = require('../templates/subscription_table_body.hbs'); var render_subscriptions = require('../templates/subscriptions.hbs'); -var subs = (function () { - -var exports = {}; - exports.show_subs_pane = { nothing_selected: function () { $(".nothing-selected, #stream_settings_title").show(); @@ -681,7 +677,7 @@ exports.keyboard_sub = function () { var active_data = exports.get_active_data(); var row_data = get_row_data(active_data.row); if (row_data) { - subs.sub_or_unsub(row_data.object); + exports.sub_or_unsub(row_data.object); if (row_data.object.subscribed && active_data.tab.text() === 'Subscribed') { active_data.row.addClass('notdisplayed'); active_data.row.removeClass('active'); @@ -846,10 +842,4 @@ exports.initialize = function () { }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = subs; -} -window.subs = subs; +window.subs = exports; diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index 9182dc2eb1..68b2f68bdf 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -1,9 +1,5 @@ var render_tab_bar = require('../templates/tab_bar.hbs'); -var tab_bar = (function () { - -var exports = {}; - function make_tab(title, hash, data, extra_class, home) { return {active: "inactive", cls: extra_class || "", @@ -173,11 +169,4 @@ exports.initialize = function () { build_tab_bar(); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = tab_bar; -} -window.tab_bar = tab_bar; +window.tab_bar = exports; diff --git a/static/js/templates.js b/static/js/templates.js index 26192934d7..2afdafff2f 100644 --- a/static/js/templates.js +++ b/static/js/templates.js @@ -1,7 +1,3 @@ -var templates = (function () { - -var exports = {}; - // Below, we register Zulip-specific extensions to the handlebars API. // // IMPORTANT: When adding a new handlebars helper, update the @@ -77,9 +73,4 @@ Handlebars.registerHelper('tr', function (context, options) { return new Handlebars.SafeString(result); }); -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = templates; -} -window.templates = templates; +window.templates = exports; diff --git a/static/js/tictactoe_widget.js b/static/js/tictactoe_widget.js index da32e429cf..5a96e8b48b 100644 --- a/static/js/tictactoe_widget.js +++ b/static/js/tictactoe_widget.js @@ -1,9 +1,5 @@ var render_widgets_tictactoe_widget = require('../templates/widgets/tictactoe_widget.hbs'); -var tictactoe_widget = (function () { - -var exports = {}; - var tictactoe_data_holder = function () { var self = {}; @@ -151,11 +147,4 @@ exports.activate = function (opts) { render(); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = tictactoe_widget; -} - -window.tictactoe_widget = tictactoe_widget; +window.tictactoe_widget = exports; diff --git a/static/js/timerender.js b/static/js/timerender.js index f582183dce..f3e18428d3 100644 --- a/static/js/timerender.js +++ b/static/js/timerender.js @@ -1,7 +1,3 @@ -var timerender = (function () { - -var exports = {}; - var next_timerender_id = 0; var set_to_start_of_day = function (time) { @@ -288,10 +284,4 @@ exports.set_full_datetime = function timerender_set_full_datetime(message, time_ time_elem.attr('title', message.full_date_str + ' ' + message.full_time_str); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = timerender; -} -window.timerender = timerender; +window.timerender = exports; diff --git a/static/js/todo_widget.js b/static/js/todo_widget.js index ec8134954f..a4e3057b53 100644 --- a/static/js/todo_widget.js +++ b/static/js/todo_widget.js @@ -1,10 +1,6 @@ var render_widgets_todo_widget = require('../templates/widgets/todo_widget.hbs'); var render_widgets_todo_widget_tasks = require('../templates/widgets/todo_widget_tasks.hbs'); -var todo_widget = (function () { - -var exports = {}; - exports.task_data_holder = function () { var self = {}; @@ -176,11 +172,4 @@ exports.activate = function (opts) { render_results(); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = todo_widget; -} - -window.todo_widget = todo_widget; +window.todo_widget = exports; diff --git a/static/js/top_left_corner.js b/static/js/top_left_corner.js index 2b26f56efd..4678e5aed6 100644 --- a/static/js/top_left_corner.js +++ b/static/js/top_left_corner.js @@ -1,7 +1,3 @@ -var top_left_corner = (function () { - -var exports = {}; - exports.update_count_in_dom = function (unread_count_elem, count) { var count_span = unread_count_elem.find('.count'); var value_span = count_span.find('.value'); @@ -111,9 +107,4 @@ exports.handle_narrow_deactivated = function () { filter_li.addClass('active-filter'); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = top_left_corner; -} -window.top_left_corner = top_left_corner; +window.top_left_corner = exports; diff --git a/static/js/topic_data.js b/static/js/topic_data.js index e54f440dc5..c94cb6140c 100644 --- a/static/js/topic_data.js +++ b/static/js/topic_data.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var topic_data = (function () { - -var exports = {}; - var stream_dict = new Dict(); // stream_id -> array of objects exports.stream_has_topics = function (stream_id) { @@ -200,10 +196,4 @@ exports.reset = function () { stream_dict = new Dict(); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = topic_data; -} -window.topic_data = topic_data; +window.topic_data = exports; diff --git a/static/js/topic_generator.js b/static/js/topic_generator.js index f7760c053c..0f58d834b6 100644 --- a/static/js/topic_generator.js +++ b/static/js/topic_generator.js @@ -1,7 +1,3 @@ -var topic_generator = (function () { - -var exports = {}; - exports.sub_list_generator = function (lst, lower, upper) { // lower/upper has Python range semantics so if you pass // in lower=5 and upper=8, you get elements 5/6/7 @@ -267,10 +263,4 @@ exports.get_prev_stream = function (curr_stream) { return stream_gen.next(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = topic_generator; -} -window.topic_generator = topic_generator; +window.topic_generator = exports; diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 2b0da9616c..a8fe40c254 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -2,10 +2,6 @@ var render_more_topics = require('../templates/more_topics.hbs'); var render_topic_list_item = require('../templates/topic_list_item.hbs'); var Dict = require('./dict').Dict; -var topic_list = (function () { - -var exports = {}; - /* Track all active widgets with a Dict. @@ -337,9 +333,4 @@ exports.initialize = function () { }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = topic_list; -} -window.topic_list = topic_list; +window.topic_list = exports; diff --git a/static/js/topic_zoom.js b/static/js/topic_zoom.js index c05bfdf8a0..9b3987e2da 100644 --- a/static/js/topic_zoom.js +++ b/static/js/topic_zoom.js @@ -1,7 +1,3 @@ -var topic_zoom = (function () { - -var exports = {}; - var zoomed_in = false; exports.is_zoomed_in = function () { @@ -66,9 +62,4 @@ exports.initialize = function () { }); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = topic_zoom; -} -window.topic_zoom = topic_zoom; +window.topic_zoom = exports; diff --git a/static/js/transmit.js b/static/js/transmit.js index c5db12c718..f5b3bfccc6 100644 --- a/static/js/transmit.js +++ b/static/js/transmit.js @@ -1,7 +1,3 @@ -var transmit = (function () { - -var exports = {}; - var socket; exports.initialize = function () { // We initialize the socket inside a function so that this code @@ -114,7 +110,7 @@ exports.reply_message = function (opts) { reply.content = content; util.set_message_topic(reply, util.get_message_topic(message)); - transmit.send_message(reply, success, error); + exports.send_message(reply, success, error); return; } @@ -125,17 +121,11 @@ exports.reply_message = function (opts) { reply.to = JSON.stringify(pm_recipient.split(',')); reply.content = content; - transmit.send_message(reply, success, error); + exports.send_message(reply, success, error); return; } blueslip.error('unknown message type: ' + message.type); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = transmit; -} -window.transmit = transmit; +window.transmit = exports; diff --git a/static/js/tutorial.js b/static/js/tutorial.js index 714c748d21..daaf439f5c 100644 --- a/static/js/tutorial.js +++ b/static/js/tutorial.js @@ -1,7 +1,3 @@ -var tutorial = (function () { - -var exports = {}; - function set_tutorial_status(status, callback) { return channel.post({ url: '/json/users/me/tutorial_status', @@ -17,9 +13,4 @@ exports.initialize = function () { } }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = tutorial; -} -window.tutorial = tutorial; +window.tutorial = exports; diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 3c5fa19bc4..6ea85b35ce 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -1,10 +1,6 @@ var render_typeahead_list_item = require('../templates/typeahead_list_item.hbs'); var Dict = require('./dict').Dict; -var typeahead_helper = (function () { - -var exports = {}; - // Returns an array of private message recipients, removing empty elements. // For example, "a,,b, " => ["a", "b"] exports.get_cleaned_pm_recipients = function (query_string) { @@ -126,10 +122,10 @@ exports.render_user_group = function (user_group) { exports.render_person_or_user_group = function (item) { if (user_groups.is_user_group(item)) { - return typeahead_helper.render_user_group(item); + return exports.render_user_group(item); } - return typeahead_helper.render_person(item); + return exports.render_person(item); }; exports.clear_rendered_stream = function (stream_id) { @@ -434,7 +430,7 @@ exports.sort_people_and_user_groups = function (query, matches) { } }); - var recipients = typeahead_helper.sort_recipients( + var recipients = exports.sort_recipients( users, query, compose_state.stream_name(), @@ -443,10 +439,4 @@ exports.sort_people_and_user_groups = function (query, matches) { return recipients; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = typeahead_helper; -} -window.typeahead_helper = typeahead_helper; +window.typeahead_helper = exports; diff --git a/static/js/typing.js b/static/js/typing.js index 4d01809bb5..3049d8482c 100644 --- a/static/js/typing.js +++ b/static/js/typing.js @@ -1,8 +1,5 @@ const typing_status = require("../shared/js/typing_status"); -var typing = (function () { -var exports = {}; - // This module handles the outbound side of typing indicators. // We detect changes in the compose box and notify the server // when we are typing. For the inbound side see typing_events.js. @@ -76,10 +73,4 @@ exports.initialize = function () { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = typing; -} -window.typing = typing; +window.typing = exports; diff --git a/static/js/typing_data.js b/static/js/typing_data.js index 0d27da07c0..2c4b1ea6eb 100644 --- a/static/js/typing_data.js +++ b/static/js/typing_data.js @@ -1,8 +1,5 @@ var Dict = require('./dict').Dict; -var typing_data = (function () { -var exports = {}; - // See docs/subsystems/typing-indicators.md for details on typing indicators. var typist_dct = new Dict(); @@ -75,10 +72,4 @@ exports.kickstart_inbound_timer = function (group, delay, callback) { }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = typing_data; -} -window.typing_data = typing_data; +window.typing_data = exports; diff --git a/static/js/typing_events.js b/static/js/typing_events.js index fcef921b2b..e905755af2 100644 --- a/static/js/typing_events.js +++ b/static/js/typing_events.js @@ -1,8 +1,5 @@ var render_typing_notifications = require('../templates/typing_notifications.hbs'); -var typing_events = (function () { -var exports = {}; - // See docs/subsystems/typing-indicators.md for details on typing indicators. // This code handles the inbound side of typing notifications. @@ -90,10 +87,4 @@ exports.display_notification = function (event) { } ); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = typing_events; -} -window.typing_events = typing_events; +window.typing_events = exports; diff --git a/static/js/ui.js b/static/js/ui.js index 1bd29f5bcd..fa9075adcd 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -1,9 +1,5 @@ -var ui = (function () { - var SimpleBar = require("simplebar").default; -var exports = {}; - // What, if anything, obscures the home tab? exports.replace_emoji_with_text = function (element) { @@ -202,10 +198,4 @@ exports.initialize = function () { exports.show_error_for_unsupported_platform(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = ui; -} -window.ui = ui; +window.ui = exports; diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 70e6d2015f..73f9040030 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -1,5 +1,3 @@ -(function () { - // This is where most of our initialization takes place. // TODO: Organize it a lot better. In particular, move bigger // functions to other modules. @@ -361,6 +359,3 @@ exports.initialize_everything = function () { $(function () { exports.initialize_everything(); }); - - -}()); diff --git a/static/js/ui_report.js b/static/js/ui_report.js index 3dbe50218b..578b592f64 100644 --- a/static/js/ui_report.js +++ b/static/js/ui_report.js @@ -1,7 +1,3 @@ -var ui_report = (function () { - -var exports = {}; - /* Arguments used in the report_* functions are, response- response that we want to display status_box- element being used to display the response @@ -81,10 +77,4 @@ exports.show_error = function ($target) { $target.addClass("show"); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = ui_report; -} -window.ui_report = ui_report; +window.ui_report = exports; diff --git a/static/js/ui_util.js b/static/js/ui_util.js index 84e8e7b00b..8410cea803 100644 --- a/static/js/ui_util.js +++ b/static/js/ui_util.js @@ -1,7 +1,3 @@ -var ui_util = (function () { - -var exports = {}; - // Add functions to this that have no non-trivial // dependencies other than jQuery. @@ -34,10 +30,4 @@ exports.blur_active_element = function () { document.activeElement.blur(); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = ui_util; -} -window.ui_util = ui_util; +window.ui_util = exports; diff --git a/static/js/unread.js b/static/js/unread.js index c42b8ae563..9f4d2d733e 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -3,10 +3,6 @@ var Dict = require('./dict').Dict; // See https://zulip.readthedocs.io/en/latest/subsystems/pointer.html for notes on // how this system is designed. -var unread = (function () { - -var exports = {}; - exports.suppress_unread_counts = true; exports.set_suppress_unread_counts = function (value) { exports.suppress_unread_counts = value; @@ -651,9 +647,4 @@ exports.initialize = function () { unread_messages.add_many(unread_msgs.mentions); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = unread; -} -window.unread = unread; +window.unread = exports; diff --git a/static/js/unread_ops.js b/static/js/unread_ops.js index 510beb47ff..019441a29b 100644 --- a/static/js/unread_ops.js +++ b/static/js/unread_ops.js @@ -1,7 +1,3 @@ -var unread_ops = (function () { - -var exports = {}; - exports.mark_all_as_read = function (cont) { unread.declare_bankruptcy(); unread_ui.update_unread_counts(); @@ -119,9 +115,4 @@ exports.mark_topic_as_read = function (stream_id, topic, cont) { }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = unread_ops; -} -window.unread_ops = unread_ops; +window.unread_ops = exports; diff --git a/static/js/unread_ui.js b/static/js/unread_ui.js index ef2f38e480..aec48fe2fc 100644 --- a/static/js/unread_ui.js +++ b/static/js/unread_ui.js @@ -1,9 +1,5 @@ var render_bankruptcy_modal = require('../templates/bankruptcy_modal.hbs'); -var unread_ui = (function () { - -var exports = {}; - var last_mention_count = 0; function do_new_messages_animation(li) { @@ -96,7 +92,7 @@ function consider_bankruptcy() { exports.initialize = function () { // No matter how the bankruptcy modal is closed, show unread counts after. $("#bankruptcy").on("hide", function () { - unread_ui.enable(); + exports.enable(); }); $('#yes-bankrupt').click(function () { @@ -111,9 +107,4 @@ exports.initialize = function () { consider_bankruptcy(); }; -return exports; -}()); -if (typeof module !== 'undefined') { - module.exports = unread_ui; -} -window.unread_ui = unread_ui; +window.unread_ui = exports; diff --git a/static/js/upload.js b/static/js/upload.js index 29c4e4b515..a920a1923a 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -1,7 +1,3 @@ -var upload = (function () { - -var exports = {}; - function make_upload_absolute(uri) { if (uri.indexOf(compose.uploads_path) === 0) { // Rewrite the URI to a usable link @@ -199,10 +195,4 @@ exports.options = function (config) { }; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = upload; -} -window.upload = upload; +window.upload = exports; diff --git a/static/js/upload_widget.js b/static/js/upload_widget.js index 70d2f855fc..fc7fab6e9a 100644 --- a/static/js/upload_widget.js +++ b/static/js/upload_widget.js @@ -1,7 +1,3 @@ -var upload_widget = (function () { - -var exports = {}; - var default_max_file_size = 5; var supported_types = [ @@ -172,11 +168,4 @@ exports.build_direct_upload_widget = function ( }); }; -return exports; - -}()); - -if (typeof module !== 'undefined') { - module.exports = upload_widget; -} -window.upload_widget = upload_widget; +window.upload_widget = exports; diff --git a/static/js/user_events.js b/static/js/user_events.js index 97a7f387dd..72b338e38e 100644 --- a/static/js/user_events.js +++ b/static/js/user_events.js @@ -1,7 +1,3 @@ -var user_events = (function () { - -var exports = {}; - // This module is kind of small, but it will help us keep // server_events.js simple while breaking some circular // dependencies that existed when this code was in people.js. @@ -97,10 +93,4 @@ exports.update_person = function update(person) { } }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = user_events; -} -window.user_events = user_events; +window.user_events = exports; diff --git a/static/js/user_groups.js b/static/js/user_groups.js index 0f2422677c..70ca8c6eab 100644 --- a/static/js/user_groups.js +++ b/static/js/user_groups.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var user_groups = (function () { - -var exports = {}; - var user_group_name_dict; var user_group_by_id_dict; @@ -98,10 +94,4 @@ exports.is_user_group = function (item) { return item.hasOwnProperty('members'); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = user_groups; -} -window.user_groups = user_groups; +window.user_groups = exports; diff --git a/static/js/user_pill.js b/static/js/user_pill.js index 90f30e85a8..7dd55254ed 100644 --- a/static/js/user_pill.js +++ b/static/js/user_pill.js @@ -1,7 +1,3 @@ -var user_pill = (function () { - -var exports = {}; - // This will be used for pills for things like composing PMs // or adding users to a stream/group. @@ -150,10 +146,4 @@ exports.set_up_typeahead_on_pills = function (input, pills, update_func) { }); }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = user_pill; -} -window.user_pill = user_pill; +window.user_pill = exports; diff --git a/static/js/user_search.js b/static/js/user_search.js index 7ba29d5ffb..4f5445169c 100644 --- a/static/js/user_search.js +++ b/static/js/user_search.js @@ -114,7 +114,5 @@ var user_search = function (opts) { return self; }; -if (typeof module !== 'undefined') { - module.exports = user_search; -} +module.exports = user_search; window.user_search = user_search; diff --git a/static/js/user_status.js b/static/js/user_status.js index b3c40a8660..10fd465cb3 100644 --- a/static/js/user_status.js +++ b/static/js/user_status.js @@ -1,9 +1,5 @@ var Dict = require('./dict').Dict; -var user_status = (function () { - -var exports = {}; - var away_user_ids = new Dict(); var user_info = new Dict(); @@ -70,10 +66,4 @@ exports.initialize = function () { delete page_params.user_status; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = user_status; -} -window.user_status = user_status; +window.user_status = exports; diff --git a/static/js/user_status_ui.js b/static/js/user_status_ui.js index 36ab410813..13b812b13b 100644 --- a/static/js/user_status_ui.js +++ b/static/js/user_status_ui.js @@ -1,7 +1,3 @@ -var user_status_ui = (function () { - -var exports = {}; - exports.input_field = function () { return $('.user_status_overlay input.user_status'); }; @@ -97,10 +93,4 @@ exports.initialize = function () { }); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = user_status_ui; -} -window.user_status_ui = user_status_ui; +window.user_status_ui = exports; diff --git a/static/js/util.js b/static/js/util.js index 5b2c944c5b..7dd085a4c9 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -1,7 +1,3 @@ -var util = (function () { - -var exports = {}; - // From MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random exports.random_int = function random_int(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; @@ -351,10 +347,4 @@ exports.convert_message_topic = function (message) { } }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = util; -} -window.util = util; +window.util = exports; diff --git a/static/js/widgetize.js b/static/js/widgetize.js index 25a4fa3466..5b65120113 100644 --- a/static/js/widgetize.js +++ b/static/js/widgetize.js @@ -1,7 +1,3 @@ -var widgetize = (function () { - -var exports = {}; - var widgets = {}; widgets.poll = poll_widget; @@ -97,11 +93,4 @@ exports.handle_event = function (widget_event) { widget_elem.handle_events(events); }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = widgetize; -} - -window.widgetize = widgetize; +window.widgetize = exports; diff --git a/static/js/zcommand.js b/static/js/zcommand.js index 1ac474ce32..b470d34d22 100644 --- a/static/js/zcommand.js +++ b/static/js/zcommand.js @@ -1,7 +1,3 @@ -var zcommand = (function () { - -var exports = {}; - /* What in the heck is a zcommand? @@ -135,11 +131,4 @@ exports.process = function (message_content) { return false; }; -return exports; -}()); - -if (typeof module !== 'undefined') { - module.exports = zcommand; -} - -window.zcommand = zcommand; +window.zcommand = exports; diff --git a/static/js/zform.js b/static/js/zform.js index 7fe4542b81..fcc65a290a 100644 --- a/static/js/zform.js +++ b/static/js/zform.js @@ -1,9 +1,5 @@ var render_widgets_zform_choices = require('../templates/widgets/zform_choices.hbs'); -var zform = (function () { - -var exports = {}; - exports.validate_extra_data = function (data) { function check(data) { function check_choice_data(data) { @@ -109,11 +105,4 @@ exports.activate = function (opts) { return self; }; -return exports; - -}()); -if (typeof module !== 'undefined') { - module.exports = zform; -} - -window.zform = zform; +window.zform = exports; diff --git a/static/js/zulip.js b/static/js/zulip.js index e4c5cc5873..54fac0e419 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -7,11 +7,6 @@ var home_msg_list = new message_list.MessageList({ filter: new Filter([{operator: "in", operand: "home"}]), muting_enabled: true, }); -var current_msg_list = home_msg_list; - -if (typeof module !== 'undefined') { - module.exports.current_msg_list = current_msg_list; -} window.home_msg_list = home_msg_list; -window.current_msg_list = current_msg_list; +window.current_msg_list = home_msg_list;