Commit Graph

118 Commits

Author SHA1 Message Date
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
Aman Agrawal b34d46e00b css: Rename #home id to #message_feed_container. 2020-07-28 16:33:32 -07:00
Aman Agrawal 0859a91b14 hashchange: Go through hashchange to narrow to All messsages.
We should not allow every function who wants to narrow to All
messages to come up with their own method to do so. This
commit makes existing such functions use hashchange library to
do so.

Remove click event on All message button, it already contains
an <a> tag which navigates correctly.
2020-07-28 16:33:32 -07:00
Aman Agrawal 8b29c38e62 info_overlay: Make them overlays from quasi-overlays.
We always use hashchange.go_to_location method now to open the
info_overlay, this makes sure that the url hash are reliable and
hotkeys don't get confused if an overlay is open or not.

We don't want to change hash to "" (this also doesn't navigates
us to 'All messages' view, hence the bug was not noticed.) on
exit of info_overlay.
2020-07-28 16:33:25 -07:00
Anders Kaseorg b65d2e063d js: Reformat with Prettier.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 8046b6477a js: Remove extra consecutive spaces.
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:25 -07:00
Anders Kaseorg 6924d501bc js: Indent case clauses in switch statements.
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:25 -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
Anders Kaseorg c080b4da06 favicon: Remove ancient browser workarounds.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-15 20:56:58 -07:00
Anders Kaseorg a79322bc94 eslint: Enable prefer-arrow-callback.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -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
Aman Agrawal 9328dc8437 templates: Show Overlay of Recent Topics.
* Show an empty overlay of recent topics.
* Register click event to open recent topics.
* Launch recent topics on "t" keypress.

This is based on the draft overlay.
2020-06-09 22:08:31 -07:00
Anders Kaseorg 7e5c82291f hashchange: Update state.old_hash before returning early.
This fixes a bug where you can’t open the same overlay twice in a row
in IE 11, which doesn’t support HashChangeEvent.oldURL; it was exposed
by commit 05be16e051 (late 2018).

While here, parse the hash from oldURL in a less ad-hoc way.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-27 11:14:02 -08:00
Anders Kaseorg 719546641f js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer.

import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";

const checkExpression = (node: n.Node): node is K.ExpressionKind =>
  n.Expression.check(node);

for (const file of process.argv.slice(2)) {
  console.log("Parsing", file);
  const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
    parser: path.extname(file) === ".ts" ? tsParser : babelParser,
  });
  let changed = false;

  recast.visit(ast, {
    visitBinaryExpression(path) {
      const { operator, left, right } = path.node;
      if (
        n.CallExpression.check(left) &&
        n.MemberExpression.check(left.callee) &&
        !left.callee.computed &&
        n.Identifier.check(left.callee.property) &&
        left.callee.property.name === "indexOf" &&
        left.arguments.length === 1 &&
        checkExpression(left.arguments[0]) &&
        ((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
          n.UnaryExpression.check(right) &&
          right.operator == "-" &&
          n.Literal.check(right.argument) &&
          right.argument.value === 1) ||
          ([">=", "<"].includes(operator) &&
            n.Literal.check(right) &&
            right.value === 0))
      ) {
        const test = b.callExpression(
          b.memberExpression(left.callee.object, b.identifier("includes")),
          [left.arguments[0]]
        );
        path.replace(
          ["!==", "!=", ">", ">="].includes(operator)
            ? test
            : b.unaryExpression("!", test)
        );
        changed = true;
      }
      this.traverse(path);
    },
  });

  if (changed) {
    console.log("Writing", file);
    fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
  }
}

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08: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 a547413347 js: Add braces to case blocks declaring variables.
This helps to prepare for the migration of `var` to `let` and `const`.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-10-28 15:02:43 -07: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
Anders Kaseorg 0c80fc6aba hashchange: Use hashchange event listener.
The comment that jQuery “doesn’t have” this was nonsense: jQuery
supports every event the browser does.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-09 11:31:35 -07:00
Tim Abbott bdb3da4504 eslint: Add key-spacing linter rule.
Apparently, we didn't have one of these, and thus had a moderate
number of generally very old violations in the codebase.  Fix this and
clear the ones that exist..
2018-12-18 10:41:06 -08:00
Steve Howell 78e20c82a8 settings: Handle back button within settings/orgs panels.
The Casper code that I eliminated here seems to be
bogus, in that I don't think it really waited for
all the clicks.

I **think** the intent of the test was to verify that
when you leave settings and go back into it, it remembers
the panel.  I was able to verify this manually.
2018-12-07 11:45:25 -08:00
Steve Howell 3544688b35 settings: Call replaceState() when entering settings/orgs.
We have an upcoming change that lets us use the
back button after going arrowing through multiple
settings pages.

Without first adding this commit, we would have an
infinite loop when you came back to '#settings' and
then '#settings' would rewrite the url with the current
hash.

Just replacing the browser state allows the browser
to do the right thing.

The history protocol is pretty well supported:

    https://caniuse.com/#search=history
2018-12-07 11:45:23 -08:00
Steve Howell 2a1a55af8a settings: Streamline how we launch settings.
We can eliminate the janky `setup_page` methods
and just pass in section from `hashchanged`.

This sets us up to handle browser history more
nicely when you load '#settings' and we could essentially
redirect you to '#settings/your-account' (or similar
things).  A future commit will address that.

We also use `launch` as the new entry point, which
is more consistent with other modules.
2018-12-07 11:40:56 -08:00
Steve Howell 5a4a357afc cosmetic: Use early-return instead of else/if. 2018-12-07 11:40:56 -08:00
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