Commit graph

53 commits

Author SHA1 Message Date
Ed Sanders dda9227947 ESLint: Manually fix remaining no-var violations
Change-Id: I4474bd0205e7a1ed8e60147e52675e3e0b93ccd9
2024-05-24 16:50:11 +01:00
Ed Sanders ca5157156a ESLint: Autofix no-var rule
Leave rule off for now as manual fixes are required.

Also temporarily disable prefer-const rule as that
will also require some manual fixes.

Change-Id: I8c3478f26f51287acb943bd38c9c1020c06b9f39
2024-05-24 16:49:36 +01:00
Bartosz Dziewoński d4c5aebd8f Prefer short arrow functions
When an arrow function body contains just a single `return` statement,
the braces can be omitted.

(Changes are mostly made by `grunt eslint --fix`, with only some line
breaks added by hand.)

Change-Id: I37f259f87085c8d20ed09cfa58a8456dd36cdc38
2024-04-20 00:08:51 +02:00
Ed Sanders a74c00ba8c Prefer arrow functions for callbacks
This allows us to remove our `this` bindings.

Change-Id: Ie8c8c38d36af8a033b5181870c39f8981a57b939
2024-04-19 12:34:23 +01:00
Ed Sanders 329a268564 ThreadItem.js: Rename getNativeRange to getRange
Makes the class more similar to PHP. The non-native
ranges exist for efficiency, but users will usually
want native ranges.

Change-Id: Ifd7dd034d2e0f3b9af050ecdab3e063df73dde5e
2023-12-15 16:22:52 +00:00
Ed Sanders 4733eb0362 Show new location of missing comments in notification
Bug: T304579
Change-Id: I5c9229a25875f0bb73c2a4dbfd0e1ac25f9c893e
2023-12-06 18:39:27 +00:00
Ed Sanders f2265f918f highlighter: Show a different message for missing heading links
These are not widely used anywhere, but linking to an #h- heading ID
that doesn't exist should say "topic not found" rather than
"comment not found".

Change-Id: Ifd269cc72e640f36431f85c751874ca06229ba9f
2023-10-28 15:28:30 +01:00
Ed Sanders 7aee0a48f0 highlighter: Replace "comment" with "thread item" in several places
We support highlighter HeadingItem's despite saying CommentItem
in a bunch of places.

Also potentially show the "not found" notification if the URL hash
starts "h-" as well as "c-".

Change-Id: I51894902bfca405bbdec89806bb9c1d76e0b40ef
2023-10-21 15:54:25 +01:00
Ed Sanders b33cafe0cd Manually expand any section containing a highlight
Bug: T336190
Change-Id: Ia0d46dad8f98c3f364bc1c378ab25f745e642f86
2023-08-17 13:25:03 +01:00
Ed Sanders e66327746a New topics notifications: Only highlight comments in new threads
Bug: T333476
Change-Id: I3f29c4b5a9be916d25415db18f50bd8efe6532af
2023-03-30 18:42:28 +00:00
Ed Sanders fd45c64491 Merge extra arguments to highlightNewComments into 'options'
Change-Id: I2e459b380ee8e1a63af5502eecf166189c9f6916
2023-03-30 16:40:52 +01:00
Bartosz Dziewoński 6d8f92a6b2 Tweaks for new heading HTML structure
Bug: T327328
Bug: T327469
Change-Id: I8c7593e98dc677b28925129dda592dbc24106220
2023-01-20 06:23:23 +01:00
Bartosz Dziewoński 86ffa41af7 highlighter: Fix double-escaping of popup notifications
Bug: T323351
Change-Id: Iaa69ccd944114f2a7ff88e01b6e58d70d38cac89
2022-11-18 14:56:36 +01:00
Ed Sanders 2883829678 highlighter: Use upstream getTargetFromFragment
Bug: T315872
Depends-On: I605a24c708e60ccffde9dce524485f61fd5c7b06
Change-Id: Ie689c57ce23b6298e089c7bf9bc53409abc45016
2022-08-31 13:10:10 +00:00
Ed Sanders 4a092df740 percentDecode: Pre-escape query string separators (&,=)
Change-Id: I1f648f192749fdd1d9d1217a87bd0a78ba064f7d
2022-08-26 13:33:38 +01:00
Ed Sanders 837591f12e Don't pass an empty string to getElementById to avoid Firefox warning
Bug: T315614
Change-Id: I6d4eedd75a23f6ada26aedca54da80c5e33ea4f0
2022-08-22 16:36:09 +01:00
jenkins-bot 91a94fe9bb Merge "Pass empty string to unused argument of pushState/replaceState" 2022-08-09 20:48:12 +00:00
Ed Sanders b3b543040b Implement percentDecode for finding link fragment targets
Relying on :target getting set means we can't use
history.pushState to change the URL without scrolling.

Should conform to https://url.spec.whatwg.org/#percent-decode

Change-Id: I4ccc3fd745884849a781a9f7fc8b00b8b689e20a
2022-08-09 20:06:28 +00:00
Ed Sanders 9f27c55f8c Pass empty string to unused argument of pushState/replaceState
Per https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
this argument is treated as unused in all the browsers we support.

Change-Id: I515193fdafaaf1c19701bc77e590d6f66b1cf4bf
2022-08-09 13:37:57 +01:00
Bartosz Dziewoński dc342291b5 highlighter: Fix exception when trying to highlight an unknown comment
If some content is loaded without re-initializing DiscussionTools
(this currently happens on live preview), then a link to a comment is
clicked, we will not find the comment, which previously caused an
exception. Just ignore this, other code paths in highlighter already
handled this situation in this way.

Bug: T309423
Change-Id: Ie46fd782b8a45907dc6fc604691575c4b55d08ce
2022-07-22 17:47:09 +02:00
Bartosz Dziewoński 1ec97b18d9 Fix race condition causing highlights to not be cleared
We cleared the highlight outside the setTimeout(), then set a new one
inside the setTimeout(). If this method was called twice quickly, two
highlights would be created, and the first one of them would become
impossible to clear.

Move the setTimeout() outside of the method to avoid this.

Bug: T311021
Change-Id: Ic8b2cf2a782a429c4ea073871efd215f4b300ed8
2022-06-20 22:51:39 +02:00
Bartosz Dziewoński d73ce24059 Tweak positioning of highlights to make them prettier
* Fix math and styling for RTL
* Make highlights for headings and framed comments cover them fully
* Align the far edges of wide comments

Bug: T309444
Change-Id: Iadbf83e02801fd9bd6336c84015994ee2819ce51
2022-06-20 19:03:50 +02:00
Ed Sanders 95ec3e7920 Dismiss "new comment" highlights when clicking
Bug: T307807
Change-Id: I40ae5fdbadfb223b1484ebf6041d29263aafa347
2022-05-06 17:44:21 +01:00
Bartosz Dziewoński f411f1c342 highlighter: Set the location hash for new topics on desktop as well
The old section=new wikitext editor does this, and I'd rather support
the same behavior on desktop and mobile than different ones.
Follow-up to 89a1efc9d8.

Change-Id: I5371f932680638ee159f2f713bbca44bba5675aa
2022-04-21 22:36:35 +02:00
Bartosz Dziewoński d910663bbc highlighter: Ensure items in .ranges and .$element are in the same order
jQuery#add sorts the nodes in DOM order (and removes duplicates).
We did not sort the ranges, so they could end up in a different
order, causing #update to apply the CSS to the wrong nodes.
This was usually harmless, but it could cause incorrect rendering
when some elements are positioned or hidden.

Change-Id: Ic359db08dafa3d86a5778426a7dc2419c94feabd
2022-04-20 19:41:44 +02:00
Ed Sanders 89a1efc9d8 Fix highlighting and expanding of new topics on mobile
Set the location hash to that of the new topic, then wait
for the section to expand before drawing the highlight.

Bug: T306399
Bug: T301840
Change-Id: I8bc78b49f359e10279584c16269fcb78a087eae0
2022-04-19 15:41:28 +00:00
Bartosz Dziewoński cf255f28bf Replace mediawiki.Uri with native URL (or polyfill)
Depends-On: I7c4f9b6449a4317d68f4923fb4f198181bbfe800
Depends-On: I04464c17369ffb0dd4e7c33d2bd4db7b2d050bf4
Bug: T305010
Change-Id: I02da91010304af35f0b1f2bd4d65a84d51f29930
2022-04-08 00:35:37 +02:00
Ed Sanders 3c66f066c2 Refactor highlights into a class, and add window resize listener
Bug: T303616
Change-Id: Id369cdfc511a7f0f5e19fff4c6424bec2f34ff55
2022-03-14 14:57:19 +00:00
Ed Sanders 4f91a0b883 Highlight new comments when refreshing
Bug: T300215
Change-Id: I72655e05dccbe96f9dfa4ccca4e91b3edf133d97
2022-03-04 00:40:29 +00:00
Ed Sanders 1032db4878 Move (auto) topic subscription initialisation to separate file
Bug: T302805
Change-Id: Ia901cba731233719dd1d5916eb5211a551d34091
2022-03-01 21:27:08 +00:00
Ed Sanders f5d4df12a9 Move highlightPublishedComment to highlighter.js
Bug: T302805
Change-Id: I429148b16f790e1d1f5cbbd84fc35139727b4402
2022-03-01 14:44:21 +00:00
Ed Sanders ecbe75c453 Move highlighting methods to separate file
Bug: T302805
Change-Id: Ie4a8ea3f351015ab5bb4b817ef997cf6d77428da
2022-03-01 14:29:10 +00:00
Ed Sanders b6136c9a58 Rename highlighter to debughighlighter
Change-Id: I8c3873fb345fee3687efb1632f3eae36c030f9cf
2022-03-01 14:20:18 +00:00
Ed Sanders dbe900b08c Handle window resize in debug mode
Change-Id: I1fdefd40b02a7d188c09b754b76aa658e7a18b76
2021-11-09 13:38:48 +00:00
Ed Sanders 1893405635 Code style: Move var declarations inline
Change-Id: I1686603388b050ba4ec22eff23e4806cdf262b87
2021-04-22 17:43:46 +00:00
Ed Sanders ece8ff69ff Change dt- class prefix to ext-discussiontools-
Longer, but follows the style guide and less likely to conflict.

We need to account for init classes in the cache being around for
a while.

Change-Id: I738bc93393850db320fdbda2b003ca8ac40556da
2021-03-13 14:42:39 +00:00
Ed Sanders cb4a833cd2 Stylelint: Enforce class prefixes
Change-Id: Id3f13f73f63883277044cd24c9e27874c688577f
2020-12-23 16:47:55 +00:00
Ed Sanders e2f93727d4 Improve highlighter styling
Change-Id: Ie2982d1f8da217cad2fe7080137c39900451c591
2020-11-16 23:34:26 +00:00
Ed Sanders 2328a3cad0 Group comment warnings in DOM so they don't break alternate colours
Change-Id: I0516a57a30a59ee6eac0ad2f23f05ad83c396391
2020-11-16 23:32:56 +00:00
Ed Sanders 4d0498853d Highlighter: Fix check for comment warnings
This was causing the highlighter to not alternate colours.

Change-Id: I9bb95e02ae91967c696f026198efb27d4d8414d4
2020-11-16 23:18:05 +00:00
Bartosz Dziewoński ca41a405ec Fix debug mode after language variant changes
Follow-up to 329df8c953.

Change-Id: I49f7d580a7e7c5dde7c234ca8905157e6a0f4f5d
2020-09-24 19:49:04 +02:00
Ed Sanders 0dbda50781 Make getNativeRange a method of ThreadItem
Change-Id: Icdf9e4560ca6116f35fecf034a4e059dc7ed893e
2020-07-22 21:56:48 +01:00
Ed Sanders a2431fe006 Refactor CommentParser
* Pass rootNode to the constructor
* Rename getters to match CommentItem/HeadingItem/ThreadItem
  value classes.
* Always build the thread tree so CommentItem's always have
  and ID and replies/parent.

Change-Id: I508be9534de59016ff806e3d84edcbb1c76cb0c6
2020-07-20 23:38:10 +01:00
Bartosz Dziewoński 219339551c Stop printing console warnings
It was useful when I was debugging those parts of the code, but now
it's usually annoying.

The warnings can still sometimes be useful for understanding how the
tool parses some discussion, though. To keep that functionality, add
displaying warnings for each comment in the debug mode.

Change-Id: I2d218a8a394f179bcc0990ff988a0567c275ccf2
2020-05-18 23:37:37 +02:00
Bartosz Dziewoński 021c981817 Add utils.getNativeRange() method
Change-Id: Iab6c5fa092560ee9dff808bbcc405722914febe7
2020-04-28 23:11:26 +02:00
Bartosz Dziewoński 04365c0188 Merge RL modules which are only loaded by 'ext.discussionTools.init'
Bug: T240474
Change-Id: I1b83aa18666be8f1ea6a3602b299f92574d42cb7
2020-03-14 14:33:23 +01:00
Bartosz Dziewoński 3896babde3 Improve comment ruler drawing in debug mode when indentation is weird
Ignore the horizontal position of the comments' bounding boxes entirely.
It can be crazy because of de-indentation in the middle of the comment,
and even just text formatting with padding/margins (e.g. `<code>`) can
make it look weird. Just draw the rulers based on detected indentation.

Change-Id: Id4e5edf076d44bdedfb45958260d797daea29ed1
2020-02-11 02:32:32 +01:00
Bartosz Dziewoński a491e3aaac Rename the lines denoting child comments in debug mode to "rulers"
I got tired of typing "relationship".

Change-Id: I318bdd1c049d7ab7fdeb1512a083cf8f4121d598
2020-02-10 22:14:38 +01:00
Bartosz Dziewoński e5e6fdd3af Stop using native Range objects, they're too annoying
Native Range objects are automatically updated when the DOM elements
they refer to are affected (e.g. detached from the DOM, or their offset
changes because of siblings being added/removed).

This seemed harmless or maybe even slightly useful, but it turns out
it conflicts with VisualEditor, which has to wrap the entire page in a
new DOM node when it opens (and unwrap it when it closes), effectively
temporarily detaching it from the DOM, which destroys all our ranges.

Just use a plain object that stores the same data as a Range. And when
we need to use Range's API, we can simply construct a temporary one.

Bug: T241861
Change-Id: Iee64aa3d667877265ef8a59293c202e6478d7fb6
2020-02-05 19:42:03 +01:00
Bartosz Dziewoński e29b8173bf Handle comments before first section heading
The loop in parser.js assumed that there was always a heading before
any comments (not counting the page title, only section headings).

Bug: T243869
Change-Id: I3a0bb06716e75d4a17e25c40748673a071ee5f30
2020-01-30 00:14:46 -08:00