Commit Graph

145 Commits

Author SHA1 Message Date
Steve Howell ead356971c hashchange: Pass in a "section" to subs.change_state.
We also eliminate get_hash_components() and clean up the
code a bit in change_state().
2018-12-07 08:03:55 -08:00
Steve Howell 7cbf031f18 hashchange: Add warning if pushState is not available. 2018-12-07 08:03:39 -08:00
Steve Howell 0914037bed hashchange: Extract get_full_url(). 2018-12-07 08:03:29 -08:00
Steve Howell 75bdd2c62c hashchange: Remove unreachable code for drafts.
I missed this in an earlier commit where I swept
the overlays for unreachable code.
2018-12-07 07:39:51 -08:00
Steve Howell 44ef8baff1 hashchange: Add hash_util.get_hash_category().
This replaces hashchange.get_main_hash(), which had
a slightly misleading name.  Also, moving this to
hash_util forces us to keep 100% coverage on it.
2018-12-04 17:16:40 -08:00
Steve Howell bcb142e68e hashchange: Move parse_narrow to hash_util.js.
The goal here was to enforce 100% coverage on
parse_narrow, but the code has an unreachable line
and is overly tolerant of bogus urls.  This will
be fixed in the next commit.
2018-12-04 17:16:32 -08:00
Steve Howell dac543891f hashchange: Move functions around in file.
This just puts similar functions near each other.
2018-12-04 17:16:29 -08:00
Steve Howell d9439e819e hashchange: Remove block comment.
This comment is less necessary now that we have docs
and have cleaned up the code a bit.
2018-12-04 16:13:18 -08:00
Steve Howell 4af1061974 Remove unused expected_hash variable.
We stopped setting this nearly five years ago, as part
of bd9cccffce

The big conditional that I removed here should have
always evaluated to false, as I understand the code.
Presumably either the browsers handle # -> '' redirects
better now, or we address this somewhere else in our
codebase.
2018-12-04 12:24:39 -08:00
Steve Howell 7a2527aed1 hashchange: Call stop_auto_scrolling() directly. 2018-12-04 12:24:39 -08:00
Steve Howell 6bfcebe6da Update hashchange docs and tweak function names.
This is mostly doc updates, and we also rename
a couple functions to have more consistent naming.
2018-12-04 12:24:39 -08:00
Steve Howell 1804d6c9ce Make back button work for some Settings/Org changes.
This change removes all the complexity around
get_hash_group(), and we now only go into the
"same overlay" logic within Settings or within
Manage Organization, but not between them.

This means if you're in Settings but hit the back
button to something under "#organization" we now
do "more stuff", since we want to err on the side
of reloading sections, etc.

There's not much flicker in my testing, and
this is not a super common transition, anyway.
2018-12-04 12:24:39 -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 05be16e051 hashchange: Remove is_exit_overlay code.
Just calling update_browser_history is sufficient
here, and we end up short-circuiting some code
in hashchanged():

    * we don't need to set state.old_hash, because
      that's what update_browser_history does
    * we bypass the is_overlay_check, which is always
      false in this context
2018-12-03 10:09:35 -08:00
Steve Howell 846dfb2fe4 hashchange: Extract hashchange.go_to_location().
We use this API when we want the machinery
of the hashchanged system to come into play.
2018-12-02 19:07:15 -08:00
Steve Howell 84d0b541e3 hashchange: Add hashchange.update_browser_history().
This helps us encapsulate the situation where we don't
want to trigger hashchanged(), without having to do it
within sub.js with prevent_once().
2018-12-02 19:07:10 -08:00
Steve Howell 13af91869d Deprecate unreachable code in hashchange.
The overlay URLs are never handled in this function,
and the prior code just created confusion.
2018-12-02 18:40:00 -08:00
Steve Howell 7859a441ac bug fix: Avoid spurious calls to subs.change_state.
This diff looks a bit more complicated than it really is.

We had a bug where we'd call subs.change_state for
non-streams-related changes.  The bug probably barely
impacted customers, since it's hard to get into that
situation unless you're in "Settings", and then the
code mostly did nothing.  There's still a deeper issue
of what we actually do want to for settings changes,
but this fix does not address that.

We invert the conditionals related to internal state
changes, so that we can handle internal state changes.

And we make sure to only call subs.change_state if our
"base" is "streams".
2018-12-02 18:40:00 -08:00
Steve Howell b80de69932 hashchange: Rename `ignore` to `state`. 2018-12-02 18:40:00 -08:00
Steve Howell 4b6ae10fb7 Rename group to old_overlay_group. 2018-12-02 18:40:00 -08:00
Steve Howell d11d1313d9 refactor: Flatten code for hashchanged().
Using early-exit make the 3 cases a bit more clear.

    opening overlay
    closing overlay
    "normal"
2018-12-02 18:40:00 -08:00
Steve Howell 1f41a65c88 Rename ignore.flag to is_exiting_overlay. 2018-12-02 18:40:00 -08:00
Steve Howell cee29483cf hashchange: Extract hashchanged_overlay().
This is mostly extracting the code within the `if`
block, as well as setting `base`, which wasn't used
elsewhere.

Also, the `else` no longer calls `is_overlay_hash`,
which was a redundant check.
2018-12-02 18:40:00 -08:00
Steve Howell 20bbc375a5 Rename ignore.prev to ignore.hash_before_overlay. 2018-12-02 18:40:00 -08:00
Steve Howell 53e99c0a55 hashchange: Remove unused ignore.last. 2018-12-02 18:40:00 -08:00
Steve Howell 682235af80 Rename hashchange.should_ignore to is_overlay_hash. 2018-12-02 18:40:00 -08:00
Steve Howell 7b2f5ccabc Rename markdown-help to message-formatting.
This just makes the id match the name of the
menu item.
2018-08-31 11:51:22 -07:00
Steve Howell 9accc2a3b6 refactor: Move operators_to_hash to hash_utils.
This breaks some unnecessary dependencies on
hashchange.js, in favor of hash_util, which
has fewer dependencies.
2018-08-04 09:32:27 -07: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
Shubham Dhama 80a2d5bc59 eslint: Enable `conditionalAssign` config of no-trailing-spaces rule. 2018-06-11 07:51:24 -04:00
Shubham Dhama dcb6254a4e eslint: Enable `no-extra-parens` rule.
Following sub-configuration is disabled:
                "nestedBinaryExpressions": false,
2018-06-11 07:51:24 -04:00
Shubham Dhama cc03f9fb8f eslint: Enable space-infix-ops rule.
More about rule at  https://eslint.org/docs/rules/space-infix-ops
2018-06-05 00:47:35 +05:30
Steve Howell b8f12728bc Rename invite.initialize() to invite.launch().
We generally want initialize() functions to only run
once at startup, whereas launch() is consistent with
other modals.
2018-05-15 15:43:55 -07:00
Shubham Padia f0d874d51f hashchange: Handle trailing slashes in narrowing URLs.
Fixes #9305.
Empty operators are not allowed while parsing narrowing URLs.
`parse_narrow` stops parsing further if it encounters an empty string
operator.
2018-05-15 09:34:50 -07:00
Tim Abbott 26ac1d237b narrow: Remove now-unnecessary use_initial_narrow_pointer option.
We replace it with the much more intuitive then_select_offset option.
2018-04-22 21:33:34 -07:00
Tim Abbott e4c50ff4fd narrow: Remove unnecessary select_first_unread option.
We consistently either pass a `then_select_id` into narrow.activate,
or were using the select_first_unread option.  Now, we just compute
select_first_unread based on the value of then_select_id.
2018-04-22 21:33:33 -07:00
Steve Howell 9ce9c2f9db Extract info_overlay.js.
There are several ways we open help for keyboard shortcuts,
markdown help, and search operators.

    - from the gear menu
    - from the compose box
    - from the search box
    - hitting ? for keyboard help
    - arrowing/clicking through the tabs

This just moves the relevant code into a module and changes a
bunch of one-line calls in various places.
2018-03-30 09:07:23 -07:00
Rohitt Vashishtha b22e8dc2b7 lint: Replace 'return undefined;' with 'return;'.
Also adds a custom rule to eslint. Since the recommended way of extending
eslint is to create plugins as standalone npm packages, the separate rule
is published as 'eslint-plugins-empty-returns'.

Fixes #8669.
2018-03-13 08:22:42 -04:00
Steve Howell c7724c6ec4 minor: Fix typos in hashchange comments.
We make the URL slightly more realistic and fix a spelling typo.
2018-02-19 09:03:11 -08:00
Tim Abbott 054952a44a docs: Update links from codebase to point to ReadTheDocs. 2017-11-16 10:53:49 -08:00
Steve Howell 34f26f14aa narrow: Remove redundant from_reload option.
The narrowing option from_reload was only used in
conjunction with use_initial_narrow_pointer, but the
latter option already takes into account whether a
reload happened.
2017-06-15 12:16:27 -07:00
Steve Howell 961d54692e narrow: Rename var to use_initial_narrow_pointer. 2017-06-15 12:16:25 -07:00
Tim Abbott cbce98edd6 Support informational overlays in hashchange system.
This helps the !modal_link links in our tutorial messages.

Fixes #5206.
2017-06-03 18:39:47 -07:00
Rohitt Vashishtha 2d73e03e37 ui-refactor: Rename modals.js to overlays.js.
Fixed #4702.
2017-05-29 11:24:46 -07:00
Rohitt Vashishtha 442537ebb8 overlays: Rename hashchange.exit_modal() to exit_overlay. 2017-05-28 18:40:54 -07:00
Steve Howell 3c0ef6295f Enforce that only one modal can be open at any time. 2017-05-08 22:04:56 -07:00
Tim Abbott 5d7aa4fae7 hashchange: Fix buggy narrowing to wrong message.
Due to a past refactoring, the from_reload argument to do_hashchange
changed from having true/undefined as the possible values to
true/false instead.  The check that sets the from_reload and
first_unread_from_server narrow options was thus incorreclty treating
from_reload of false the same as a from_reload of undefined.

As a result, if the browser had been loaded with a
page_params.initial_narrow_pointer (aka via the background reload code
path), then for the duration of that browser session, every time one
narrowed via a hashchange rather than an explicit click handler (which
apparently includes clicking on a PM thread in the left sidebar), we'd
end up narrowing with a then_select_id of the that initial narrow
pointer, not the correct first unread message.

The fix is simply changing the check for truthiness, not undefined, in
do_hashchange.
2017-04-26 12:07:56 -07:00
Abhijeet Kaur 8f88b045a4 Rename "Administration" to "Organization" in the settings UI.
This better sets expectatations for the fact that in Zulip, the
Organization settings UI is available read-only to non-administrator
users.

Tweaked by tabbott to update some additional references.
2017-04-07 17:32:56 -07:00
Moritz Neeb 9866805937 docs: fix a typo in hashchange.js 2017-03-23 15:16:02 -07:00
Tim Abbott 2a5269baa9 docs: Document the frontend hashchange system. 2017-03-22 15:21:36 -07:00
Steve Howell d026344b37 Extract js/ui_util.js. 2017-03-19 11:05:45 -07:00
Rishi Gupta 19d8d16126 js dependencies: Split hash_util.js from hashchange.js. 2017-03-18 20:40:34 -07:00
Steve Howell 27f37e6378 Add hash_util.encodeHashComponent() shim. 2017-03-18 15:52:50 -07:00
Brock Whittaker 3bc2ed6dc9 Switch "invite users" to new component overlay.
Fixes #4036.
2017-03-15 12:29:09 -07:00
Brock Whittaker b0e5aeb313 Consolidate JavaScript modal closing in modals.js.
This consolidates all actions to close modals into modals.js and
triggers the correct cleaning/collapsing function dependent on what the
data-overlay attribute is labeled as.

It also ensures these all have an e.stopPropagation().

Fixes #4029.
2017-03-15 12:27:44 -07:00
Brock Whittaker 2e30cef8e9 Change "hashchange.exit_settings" to "hashchange.exit_modal".
Change the name of the hashignore and replace mechanism from
exit_settings to exit_modals since it is now used for more than just
the settings.
2017-03-15 12:17:27 -07:00
Tim Abbott 3b59e6c3cc subs: Rename /#subscriptions to /#streams.
Fixes #3653.
2017-03-08 16:57:58 -08:00
Brock Whittaker 461066cab9 Add deep linking to #subscriptions/new and #subscriptions/:stream_id.
This mechanism allows for a user to deep link to a particular
subscription or the form for creating a new subscription.
2017-02-23 15:34:30 -08:00
Sampriti Panda 1929cc5190 Implement persistent drafts functionality
* Created a drafts modal to display/restore/delete drafts
* Created a Draft model to support storing draft data in localstorage
* Removed existing restore-draft functionality
* Added casper and node tests for drafts functionality

Fixes #1717.
2017-02-23 02:58:23 -08:00
Brock Whittaker 1143ed7219 redesign: Change /#settings and /#administration to an overlay.
This also adds a box-shadow to the #deactivate_self_modal so that it
looks similar to the old backdrop.
2017-02-09 23:35:10 -08:00
brockwhittaker 894f0b5bf0 Fix hashchange closing #subscriptions on IE.
This fixes an issue where Array.prototype.split is called on an
undefined instance due to the EventTarget.oldURL property not being
recorded in IE. We fix this by recording it ourselves.
2017-02-02 11:40:26 -08:00
Steve Howell cd6115c24d Make nicer slugs for "sender" narrows.
Slugs are now like our "pm-with" slugs:

    narrow/sender/3-cordelia
2017-01-19 14:54:50 -08:00
Brock Whittaker eccca8fc61 Unify subs modal closing with subs.close().
The new subs.close() function should unify all closing events of the
subscriptions overlay. The function also now tracks whether the
subscription overlay is in a closed or open state.
2017-01-19 14:23:25 -08:00
Steve Howell d757f840dd Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.

Examples:

    narrow/pm-with/3-cordelia
    narrow/pm-with/3,5-group

The part of the URL that is actionable is the comma-delimited
list of one or more userids.

When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans.  If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).

For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL.  We may tinker with this later.

Basically, the heart of this change is these two new methods:

    people.emails_to_slug
    people.slug_to_emails

And then we unify the encode codepath as follows:

    narrow.pm_with_uri ->
    hashchange.operators_to_hash ->
    hashchange.encode_operand ->
    people.emails_to_slug

The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-17 15:13:49 -08:00
Steve Howell 3ee733eb51 Extract encode_operand/decode_operand in hashchange.js.
These are just one-liners for now, but they will set us up
to do different encodings for different narrows.
2017-01-11 18:31:17 -08:00
Steve Howell 030c6649ae tests: Improve hashchange coverage for operators.
Test round tripping of operators in hashchange.js.
2017-01-11 18:31:17 -08:00
Tim Abbott 998dff9e50 lint: Add dangling commas in JavaScript objects. 2017-01-11 15:23:42 -08:00
Brock Whittaker 660144a79d Blur the active element on settings/streams modal exit.
This blurs any focused element so that you can’t accidentally enter
into anything on a hidden modal.
2016-12-14 15:37:43 -08:00
Brock Whittaker 1886f0a015 redesign: Convert subscriptions page to overlay.
This is a major change to the /#subscriptions page, converting it to
by a side-by-side list of streams and their settings in an overlay.
There are no new features added/removed, but it's a huge changeset,
because it replaces the old navigation logic and moves the stream
creation modal to appear in the right side of this overlay.
2016-12-09 11:08:08 -08:00
lonerz dc6849952b eslint: change space-before-function-paren from warning to error.
Also fix violations.
2016-12-05 09:50:37 -08:00
AZtheAsian ed0bc831be eslint: change one-var from warning to error and fix violations 2016-12-02 11:25:16 -07:00
Brock Whittaker 1def0b6701 hashchange: Add hashchange ignore mechanism for overlays.
This will make it possible to do hash changes in soon-to-be-overlay
pages like the /#subscriptions and /#settings page.
2016-11-15 11:53:38 -08:00
Tim Abbott 28cefc4996 hashchange: Fix buggy arguments to hashchanged causing scrolltop bug.
Because jQuery passes the actual hashchange event to an onhashchange
handler, the `if reload` checks in the `hashchanged` function were
always returning true, resulting in the wrong logic being used for
computing where to send the user in the event that they edited the
hash in the browser to change their narrow.
2016-10-23 20:07:12 -07:00
Tim Abbott cb18ef07a7 Rename hashchange.zulip event to avoid jquery 1.8 interaction. 2016-07-08 11:09:09 -07:00
Steve Howell 405c3d7626 Created floating_recipient_bar.js (with code from ui.js).
(imported from commit 2b6631938b0fc8e39c14aacd92f9f1670b68b199)
2014-03-14 20:48:58 -04:00
Steve Howell 7fce920522 Move favicon-related functions to favicon.js
util.reset_favicon -> favicon.reset
util.set_favicon -> favicon.set

(imported from commit 250848ec5dc7ac58649197c8cc4b7b4e7b19f25c)
2014-03-14 20:48:55 -04:00
Jason Michalski 16df239f39 Use the first unread from server on reload
When reloading the page we want to narrow to the location that is
restored from the query parameters. This is only done if we ask narrow
to use the first unread message from the server.

(imported from commit b585ef51cbb85788b24d90d831b42c45fd188569)
2014-03-03 18:17:15 -05:00
Steve Howell 5631e7e624 Remove transitional defensive code in hashchange.js
(imported from commit b02de9a51426339f3fdbe74fb61b89f5dd4ce8d4)
2014-02-19 16:20:29 -05:00
Steve Howell 2fb7c0059d Support negated searches on staging.
Behind a feature flag you can now do searches like this:

    -pm-with:othello@example.com is:private

The "-" in front of "pm-with" tells us to exclude messages
with Othello from our search.  We support "-" in front of
all operators, although the behavior for "-search:" and
and "-near:" doesn't really change in this commit.

Note that the filtering out of "negated" predicates only
happens on the client side in this commit.  On the server
side we ignore negated predicates and send back a superset
of the results.

(imported from commit 6cdeaf32f2d493fbbb838630f0da3da880b1ca18)
2014-02-13 14:14:24 -05:00
Jason Michalski 044e3ced4f Fix how the hash URL is build for IE support
IE sometimes returns the pathname without a leading slash. Also
location.origin is not supported and must be build manually.

(imported from commit fb64478aeaac0f17d31021b7c370ff56781b48d1)
2014-02-13 12:39:24 -05:00
Jason Michalski dd345bdece Make sure the hash we change to always starts with a #
(imported from commit b27d4a3b9b89b2576d4b1339d55d54ba338a576d)
2014-02-12 16:30:07 -05:00
Tim Abbott 19dcc3f385 Disable centering narrows around first unread message on server.
(imported from commit 11b17c2874370d63528e2c9e978eb605da8005e4)
2014-02-12 15:34:33 -05:00
Jason Michalski bd9cccffce Use pushState where supported to change the URL hash
This this removed one forced relayout of the page on unnarrow. This
saves about 100ms for me.

(imported from commit 0755f425abbe3d99b8a99765549a5bbf3c620b9a)
2014-02-12 15:19:10 -05:00
Tim Abbott fcb8c106b1 Fix saving of pointer on server-initiated reload when narrowed.
Previously, we saved the current_msg_list selected id and then
restored it as the home_msg_list selected id, which could result in
the home view loading to the wrong place.

This takes some already bad code and makes it even more in need of
refactoring, but it does fix a pressing bug.  We should definitely
refactor both:

* the top of narrow.js
* the save/restore code in reload.js

after this, though.

(imported from commit bb2040219e4f545ba90bb04a696996cec2831484)
2014-02-12 14:40:38 -05:00
Tim Abbott f4c514fbf3 hashchange: Fix indentation on main switch statement.
(imported from commit 1420cc2513e1bf6b80c8e52a6c0d3d66e82a5a1d)
2014-02-12 14:40:38 -05:00
Steve Howell c87b77e52e Report errors due to legacy tuples in hashchange.operators_to_hash.
(imported from commit f639ba52f85bf103afdd26dc4f279e1f03570119)
2014-02-11 11:45:44 -05:00
Steve Howell 9c48ba43fb Do not return terms as tuples in hashchange.parse_narrow.
(imported from commit ffc4acacdd220de57e0179c9dc8272e6b5c33457)
2014-02-04 13:16:34 -05:00
Steve Howell 7fb7950f70 Support non-tuple operators in hashchange.operators_to_hash().
(imported from commit e002293c586d4ef754612feee2b7f33215cf305f)
2014-02-04 13:16:28 -05:00
Tim Abbott f26af47fb6 Center on-page-load narrows on first unread message.
This implementation is somewhat hackish in large part because I think
we're going to be wanting to redo the get_old_messages API somewhat
soon, and this may naturally become a lot cleaner as a result, but
this isn't a lot of code and fixes #2235 part (A) and substantially
mitigates #1510.

(imported from commit 47a2160a44befa9d83190c5cc95b90e92cc5b4cc)
2014-02-03 13:32:02 -05:00
Jason Michalski bf57839e85 Remove scrollTop workaround for hash changes
Now that we are not scrolling the document we can remove the workaround
to prevent browsers from scrolling on hash changes.

(imported from commit 67fdaa4980d4d54d80ca9c259bbee567b8eeb917)
2014-01-30 01:48:15 -05:00
Steve Howell c53845a69c Add unit tests for stream_list.
(imported from commit 1d04a2e6115f29b7949466260ec2ba3126b882e6)
2013-11-27 15:09:20 -05:00
Luke Faraone ecc42bc9f8 Add administrative panel to allow for user deactivations etc.
We now show a list of users and allow you to deactivate a user using the
same process as `python manage.py deactivate_user`.

We add a new menu item accessible from the gear icon which will eventually
have much more than just this, but we have a good start here.

Here we also add a property to UserProfile which determines whether you're
eligible to access the administration panel, and then have code which shows
the menu option if so.

This introduces a new JS file, admin.js.

(imported from commit 52296fdedb46b4f32d541df43022ffccfb277297)
2013-08-13 14:20:18 -04:00
Scott Feeney 8703134a23 Replace $.each with _.each
In a few cases the $.each was doing something imperatively that was
terser and easier to understand by using a different Underscore method,
so a few of these I rewrote.

Some code was using the fact that jQuery sets `this` in the callback to
be the item; I rewrote those to use an explicit parameter.

Some code was using $(some selector).each(callback). I converted these
to _.each($(some selector), callback).

One function, ui.process_condensing, was written to be a jQuery $.each
callback despite being in a totally different module from code using it.
I noticed this and updated the function's args.

(imported from commit bf5922a35f257c168cc09ec1d077415d6ef19a03)
2013-07-30 12:12:58 -04:00
Tim Abbott bc4d7c687d Rename our custom JS events to use Zulip, not Zephyr.
(imported from commit 61ac456d394a6dbc14f3e9183a53313990db5059)
2013-07-29 12:11:26 -04:00
Tim Abbott 3bba0cc927 Move zephyr/static to just static.
It's not really a part of the server (aka the rest of zephyr/).

(imported from commit 27f6b6b064938ad927075a68d873e4b68710d279)
2013-07-29 12:11:26 -04:00