Commit Graph

45 Commits

Author SHA1 Message Date
Sahil Batra 6b59c3242d settings_panel_menu: Open first section if hash is invalid.
When trying to open settings overlay with invalid hash or
hash of a section which the user cannot view, for example
non-admins cannot view custom profile field section, then
we open the first section by default.

While if a user changes to a invalid hash by typing when
the overlay is already opened, then the previous section
remains open.

Fixes #23163.
2022-10-12 11:07:28 -07:00
Anders Kaseorg eb7770565a js: Fix no-jquery/no-sizzle.
The :first and :last selectors were deprecated in jQuery 3.4.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-17 13:10:23 -07:00
Anders Kaseorg f84a2c08d5 js: Prefix jQuery object variable names with $.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-16 12:52:07 -07:00
Priyank Patel 6ab66ea17a keydown_util: Use Event.key instead of deprecated properties.
The Event.which and Event.keyCode are deprecated as pointed out by
TypeScript intellisense based on the jQuery types. We use Event.key
instead which behaves similarly to Event.which & Event.keyCode for
our use case.

The only difference in functionality by this change is that the vim
keys won't work when Caps Lock is on. This is because, in this case,
the key property will be "J" instead of 'j'. We can fix this by
adding a mapping for this, however, I think we don't want to handle
this case so I left this change out. Tested by trying out the
everywhere keydown_util is used.

Finally, we also turn off the new-cap rule for tests since I think
it fine to only enforce it on real code and exempting test code is
fine.
2021-05-27 23:33:17 -07:00
aryanshridhar 9f9259683c settings_panel: Bind vim keys to SettingsPanelMenu.
Added a commit to bind vim keys with the SettingsPanelMenu,
allowing users to control the settings and organization tabs
using 'h','j','k' and 'l' keys.

vim_left('h') -> Switch between tab by shifting focus to the left.
vim_right('l') -> Switch between tab by shifting focus to the right.
vim_up('k') -> Move up.
vim_down('j') -> Move down.
2021-05-10 17:30:10 -07:00
Aman Agrawal eb72f77d0a settings: Allow switching between user and org settings manually.
Since the base hash for org settings and user settings are
different (organization and settings), the hashchange module
gets confused that we are going from one overlay to other.

A reproducer for this flow is to visit the organization "Bots" page,
click on your own profile as the owner of a bot, and then click "Edit
profile" from there.

So, we fix this by making an exception for this particular case
in the module.

Fixes part of #18011.
2021-04-07 01:02:03 -07:00
Steve Howell 746cc9e1f6 refactor: Extract browser_history module.
This mainly extracts a new module called
browser_history. It has much fewer dependencies
than hashchange.js, so any modules that just
need the smaller API from browser_history now
have fewer transitive dependencies.

Here are some details:
    * Move is_overlay_hash to hash_util.
    * Rename hashchange.update_browser_history to
      brower_history.update
    * Move go_to_location verbatim.
    * Remove unused argument for exit_overlay.
    * Introduce helper functions:
        * old_hash()
        * set_hash_before_overlay()
        * save_old_hash()

We now have 100% line coverage on the extracted
code.
2021-03-22 13:29:32 -07:00
Anders Kaseorg ea9ca6b7d0 js: Use jQuery as a module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:08:25 -08:00
Anders Kaseorg 5cc1f8d289 js: Convert static/js/ui.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-02 17:06:35 -08:00
Anders Kaseorg 972a52ca99 js: Convert static/js/settings.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg f94b29356c js: Convert static/js/settings_sections.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg e30df92944 js: Convert static/js/hashchange.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg b3f74af090 js: Convert static/js/popovers.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg dd84974a15 js: Convert static/js/settings_panel_menu.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg f85924dd0a js: Convert static/js/keydown_util.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg aa650a4c88 js: Escape strings interpolated into CSS selectors with CSS.escape.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-04 11:00:06 -08:00
Anders Kaseorg 6cd694b8e3 eslint: Fix unicorn/no-array-callback-reference.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
sahil839 1ae00a306b settings: Hide open popovers when switching panels in settings overlay.
This is a prep commit for changing the bots list page to show normal
user popover instead of extended profile one. This is added so that any
open popovers are closed while switching panels in settings overlay.

This change was not needed previously because we were using modal for
showing extended user profile. Now as we would be adding popover, we
would need this change to close the open popovers while switching
panels in settings overlay.
2020-08-12 17:31:25 -07:00
Anders Kaseorg 60a25b2721 docs: Fix spelling errors caught by codespell.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-08-11 10:23:06 -07:00
Anders Kaseorg b3ae3d6de9 settings_panel_menu: Remove leftover angry debugging assertions.
Apparently I forgot to remove these from commit
0b4483c8d2 (#15920).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-08-02 12:38:19 -07:00
Anders Kaseorg 6ec808b8df js: Add "use strict" directive to CommonJS files.
ES and TypeScript modules are strict by default and don’t need this
directive.  ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00
Anders Kaseorg 0b4483c8d2 settings_panel_menu: Convert make_menu to an ES6 class SettingsPanelMenu.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-26 17:00:05 -07:00
Anders Kaseorg a9ca5f603b js: Replace deprecated jQuery event trigger shorthand.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:01:26 -07:00
Anders Kaseorg f3726db89a js: Normalize strings to double quotes.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
sahil839 f73ecfc2f7 settings_panel_menu: Remove "settings-wrapper" class from jquery selectors.
This commit changes the jquery selector to remove "settings-wrapper" class.
There is no element in the templates with this class.
2020-07-03 16:48:06 -07:00
Gittenburg 35378d4660 settings: Fix settings launch on mobile.
I replaced activate_section() with activate_section_or_default()
to keep settings details out of hashchange.js.

Fixes #13737.
2020-06-25 11:08:40 -07:00
Gittenburg 5d279d5456 settings: Fix bugged navigation on mobile.
* Don't annoyingly open the first section when switching
  between the Settings and Organization tabs.

* Don't highlight currently active section in the settings list
  (we don't display the currently active section in the mobile settings
  list so it isn't actually active).

* Remove nearly invisible and buggy no-border logic.
2020-06-25 11:08:13 -07:00
Anders Kaseorg 28f3dfa284 js: Automatically convert var to let and const in most files.
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`.  It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -08:00
Anders Kaseorg d17b577d0c 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 <andersk@mit.edu>
2019-10-25 13:51:21 -07:00
Pragati Agrawal 6b5e98d554 settings_panel_menu: Fix the switching behavior for hidden section panels.
For organization settings page there are few sections' panels which are not
visible (unless you click on 'show more') but when we use up-down arrows to
navigate between sections, sections of hidden panels also get visible which
leads to confusion.

Fixes: #13008.
2019-08-15 16:51:19 -07:00
Thomas Ip 5b94e1dfad jQuery: Remove unnecessary :first selectors.
See example here: https://jsbin.com/relewizita/edit?html,js,output
Basically the original statement get the first of each input, button
and select element, and then select the first of these in the next
line. We can simply query the first one in one step. The settings
menu have at most 20 of these input elements so performance should
have no impact.
2019-06-06 15:21:26 -07:00
Anders Kaseorg 141088586b Completely replace perfect-scrollbar with SimpleBar.
perfect-scrollbar replaces both the appearance and the behavior of the
scrollbar, and its emulated behavior will never feel native on most
platforms.  SimpleBar customizes the appearance while preserving the
native behavior.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-05-17 12:06:51 -07:00
Steve Howell 3697add70c settings: Reset scroll when switching sections. 2019-02-26 14:26:15 -08:00
Steve Howell 7a44d99b96 settings: Eliminate admin_sections module.
We move all of its logic into settings_sections.

Note that this is slightly more than a refactor.
We are slightly more aggressive about resetting
sections.  For example, if you go into Settings,
then exit the overlay, then go into Manage
Organization, we will now reset sections for both
groups.
2018-12-17 10:13:20 -08:00
Steve Howell 779ed37cfa hashchange: Fix update_browser_history() call for settings.
Even prior to my recent change in settings_panel_menu.js,
we were assigning window.location.hash a value that doesn't
have a '#' prefix.  This probably doesn't matter too much
for the browser, but it does confuse our own checks about
whether we're redundantly updating browser history.

Now we prefix the settings hash with '#' and we encorce
this convention with a blueslip error.
2018-12-03 10:09:35 -08:00
Steve Howell c4d3578de3 Move more code into activate_section().
This code was added to the click handler, but it can
really go into activate_section().  This way the code
also runs when we first launch settings.
2018-12-02 19:07:24 -08:00
Steve Howell 473f2650fd refactor: Change settings_panel_menu.activate_section().
We now have activate_section take a section, rather than
an li, so it will be easier to call directly.
2018-12-02 19:07:24 -08:00
Steve Howell 636e54389b settings: Streamline code for navigating panels.
We call hashchanged.update_browser_history() when
we switch panels.  This API short circuits the
hashchanged callback and avoids code churn.

(We weren't actually double rendering, as the downstream
code does nothing at this point, so this is more
just preventig a pitfall and moving to a consistent
API.)
2018-12-02 19:07:15 -08:00
Armaan Ahluwalia 6d255efe4c app: Prepare JS files for consumption by webpack.
This commit prepares the frontend code to be consumed by webpack.

It is a hack: In theory, modules should be declaring and importing the
modules they depend on and the globals they expose directly.

However, that requires significant per-module work, which we don't
really want to block moving our toolchain to webpack on.

So we expose the modules by setting window.varName = varName; as
needed in the js files.
2018-07-05 10:53:36 +02:00
Akash Nimare d5e3ab761b settings: Unify code for setting-panel. 2018-06-27 11:48:50 -04:00
Steve Howell 3065bf0c58 settings: Make the enter key go to panels.
This is less than perfect, but for most settings hitting
the enter key will now take you to the first element in
the right panel.

The two exceptions are below.  They have checkboxes with
kind of strange markup:

    Notifications
    Authentication methods
2018-06-06 09:42:33 -07:00
Steve Howell e7e38253ec settings: Add better keyboard navigation for panel menus.
You can now use all four arrow keys intuitively in the
Settings/Organization panel menus.
2018-06-06 09:42:33 -07:00
Steve Howell a5f0163a67 Keep track of which settings sections are open.
If you toggle between Settings and Organization now, it
will remember where you were the last time (not counting
reload).  Likewise if you go in and out of settings.

The old code always put you in the first section, which I
think was an accident of implementation.  Of course, we'll
continue to default to the first row if you haven't gone
anywhere else.
2018-06-06 09:42:33 -07:00
Steve Howell beecee4b8c Move panel click handler into settings_panel_menu.js.
This is mostly a code move, but because things are more
modular now, we don't need the two conditionals to find
out what kind of panel menu we're inside of, and our
selectors are less brittle.
2018-06-06 09:42:33 -07:00
Steve Howell 8ce8e93645 refactor: Extract settings_panel_menu.js. 2018-06-06 09:42:33 -07:00