Commit Graph

154 Commits

Author SHA1 Message Date
NikG
5d576d05b4 Add language settings button inside dropdown for non-content pages
Bug: T316559
Change-Id: Ifdf2a529b30e5a2df8867b606a525c9f7b3bdb6c
2023-01-09 05:02:57 +00:00
NikG
de77ea992e Remove unused code from ext.uls.interface.js
During the implementation of the “addEmptyState” method, a part of code
was copied from the “addActionsMenuTrigger” method. This part is the
rendering of the action menu items (Translate button, Open Language
Settings button, etc) that is common for both the empty state and the
actions menu. During this copy, two unused lines were also copied. These
lines basically create the trigger for the actions menu (the “ellipsis”
or “cog” icon button at the bottom right corner of non-empty ULS), which
is not rendered for the ULS empty state.

This patch removes these unused lines.

Change-Id: I4776c2038cb6e1c74401c4caa6705e98181c6dca
2022-11-02 05:07:32 +00:00
Santhosh Thottingal
3450f90678 Add support for empty states to the current language selector
Bug: T290436
Change-Id: I42c5d44ec15e291d71723c9738ddb8f0d1cf0b09
2022-07-01 09:16:40 +00:00
Santhosh Thottingal
cfd6d48bc1 Load OOUI widgets only when ULS is opened
OOUI widgets are required for the actions menu dialog, but no need
to have them loaded unconditionally.

Bug: T309793
Change-Id: Icc09b88aa70af1316bd67a56b13a411ebc8f7f8a
2022-06-06 12:35:48 +05:30
NikG
9fc25cc862 Require action menu items registry at the top of uls interface module
"ext.uls.actions.menu.items.registry.js" should be required at the
top of the "ext.uls.interface.js" file. The latter is the main file
of the "ext.uls.interface" module, and it's the only one that is
executed when the module is added as an external dependency. Since,
the "mw.uls.ActionsMenuItemsRegistry" object is needed outside ULS
extension (inside ContentTranslation), the corresponding file should
be required at the top of the main file so that it's available.

Bug: T289840
Change-Id: I70ced03c09b7907c6dbf2aa35a29d5fd14b790e6
2022-04-13 07:02:57 +00:00
Santhosh Thottingal
5e6838ebdf Add actions menu inside content language selector
This patch replaces the display and input settings menu bar at the
bottom of the content language selector, with a floating icon that
opens a menu containing all the available language actions. In case
that only the language settings action is available, the language
settings menu is being opened instead.

In order to provide extensibility and support the addition of new
action items from other extensions, a registry class that inherits
from OO.Registry class is created. This class is used to create a
singleton registry object that holds all action items that should
be rendered inside the menu. Other modules/extensions can use this
registry to add new actions items to the menu, by passing the item
as argument, in the following form:
{ name: "", icon: "", text: "", handler: function() {} }

Bug: T289840
Change-Id: Iee017a9e3e6a654145e9fdd2b7df35baa348697d
2022-04-11 05:24:08 +00:00
Ed Sanders
02e17c5242 build: Update eslint-config-wikimedia to 0.22.1
Change-Id: I02692eeabb23c5b99997faa7a17d42f019148ed1
2022-03-08 09:41:49 +00:00
Abijeet
03cf7863ec Stop propagating first click handler when loading languagesettings
The languagesettings dialog does not open when clicking the
uls.trigger for the first time. This issue occurs when the user is
not logged in, ULSPosition is personal, and ULSAnonCanChangeLanguage
is false.

Without this change, the following happens:
* uls.languagesettings is loaded via uls.interface
* uls.languagesettings::hide is called via uls.languagesettings::init
* click method is triggered immediately via script in uls.interface
* uls.languagesettings::show is called
* uls.languagesettings::hide is called - triggered via ::show
  method - $( document.documentElement ).trigger( 'click' ); but
  dialog is not visible yet, so this does nothing
* uls.languagesettings::show displays the uls.languagesettings
* hide method called again via click handler for documentElement

With this change in place the hide method is not called again due to
e.stopPropagation();

Additionally add a parameter autoOpen that can be set to open the dialog
automatically.

Bug: T301882
Change-Id: I54e8172ae017c4a9c6ab5b841d9328b2f24f97a8
2022-03-08 09:39:43 +00:00
Santhosh Thottingal
5bd64b167c Improve the loading time of ULS language selector by fetching modules early
Start fetching them on mouseover without waiting for click.

Bug: T299202
Change-Id: I1ba3b8516bd01ad1bf8bb4c57d72d10ca59e06ca
2022-01-27 14:31:07 +00:00
Clare Ming
f539619b1c Simplify function to check for standalone language button.
Change-Id: I4d4afa0e5098736e40e49924e87f471b3d09257a
2022-01-14 05:58:42 +00:00
jdlrobson
26aa8d450c Hide sticky header language button with preference disabled
Adds a class to body when the ULS dialog is disabled.

Bug: T297579
Change-Id: I791c65c6a7ac5221dcf24e5db01c22c3e2e9f81a
2022-01-06 05:13:45 +00:00
bwang
c95e8e70c5 Handle "Enter" keyboard event for checkbox hack selectors
"Enter" key support for Vector ULS button was previously handled by the core checkbox hack. With the upcoming changes to the checkbox hack implementation, it needs to be handled separately.
Context: https://gerrit.wikimedia.org/r/c/mediawiki/core/+/747877/10/resources/src/mediawiki.page.ready/checkboxHack.js#b275

Change-Id: Id74a80cda6cf460cc2b579269b8d5b2ce81c8ca5
2021-12-21 22:17:34 +00:00
Fomafix
6ee366a2c8 Reuse userCanChangeLanguage()
Change-Id: I52893ca8e2579520d21579bd7fdcb9af858a52b9
2021-11-21 19:39:25 +00:00
jdlrobson
869c721e91 Language button should prevent default click behavior
In Vector the language button is a checkbox. It uses the checkbox
hack to provide non-JS dropdown behaviour.

When the JS upgrades such a button, the checkbox behavior continues
to work. An unsatisfying hack in Vector workarounds this problem.

This provides a neater way to disable that behavior
in Vector once the button is clicked by adding support for the
well documented checkbox hack.

Bug: T283757
Change-Id: I97a69c30b27cb1ded06451389e086229561c3589
2021-09-13 07:04:33 +00:00
bwang
9e952f28af Add support for multiple ULS buttons
- Update document click handler for loading ULS
- Use data attributes to ensure ULS isnt loaded multiple times for an element

Bug: T289815
Change-Id: Iba6cbbd6c6e48a1abfda342421822e3ff2715362
2021-09-07 15:21:26 -05:00
Niklas Laxström
03d099eddc Fix regressions in ULS entry point setup
* Link in preferences is again opening ULS
* "personal" entry point now works even with compact languages
  preference disabled

I added lots of comments and refactored this code to give things
better names to make this code easier to understand and maintain
and hopefully reduce the amount of bugs in the future.

Bug: T282956
Bug: T286574
Change-Id: I9cd6776ea6664e33fd63c49dfa77c5f004fba799
2021-07-16 19:23:34 +00:00
jdlrobson
09a2b33bd6 Restore compact languages button user preference
The compact languages button user preference will be applied to
any compact language button provided by the skin, this allows users
to opt out of the feature as before.

This will be used immediately in Vector in
I436554d9d51470d277d59c2c71e08124735e12fd

Bug: T282149
Change-Id: I726c61d4c6895a28b999781752535e0ddc961744
2021-06-14 15:24:53 +00:00
Timo Tijhof
977e6c68c2 ext.uls.interface: remove some needless uses of jQuery
* $(node).prop(foo) -> node.foo

* For objects only expected to represent a single element,
  use native querySelector() and its natural null return
  fallback, instead of `$(), $.length, $()` etc.

* Fix a few minor non-voting eslint warnings that were in the CI
  output about line length and unknown type "bool".

* Remove presumed outdated comment about Vector splitting,
  per T234907.

* Rename ulsPosition to configPosition to be more clearly
  different from ulsPopupPosition.

* Remove various 'uls' prefixes of local variables,
  since this is ULS code in the ULS repository.

Change-Id: I1c617bf48283f47dc948550111c515faf173d1eb
2021-05-20 18:57:09 +00:00
Sam Smith
8e85f0d611 Fire hook when compact language links are opened
Following on from Icc64044d, we fire the
mw.uls.compact_language_links.open hook whenever that treatment is
opened (and not only the first time that the triggering element is
clicked).

Bug: T281928
Change-Id: I6fa966c22c738ca12bcbeb0225c03f3f8394ecee
2021-05-11 12:48:10 +01:00
Sam Smith
c914a7d0ab Fire hook when user clicks language button
This allows us to correctly instrument (via the
UniversalLanguageSelector instrument) this action so interaction rates
between treatments can be compared.

Bug: T273232
Bug: T273928
Change-Id: Icc64044d51c567482d4f286637366cefb7beeb3e
2021-05-10 20:46:37 +00:00
jdlrobson
ec8edeb8ec Use ev.currentTarget not ev.target
In modern Vector, the ULS trigger button has a child node which is
a span. When clicks are received on the span, they will result
in positioning relating to the span rather than the button.

The ev.currentTarget should be read outside the asynchronous function
to avoid bubbling.

Bug: T276248
Change-Id: I6e138c88e29b335b8e0bc22cf0aa07c289a5eb74
2021-04-26 16:59:47 +00:00
Niklas Laxström
2a044e1e0a Small cleanups and typo fixes
Change-Id: I4faeb4673fd5e903d2931d6071262a893d4009f5
2021-04-21 11:48:15 +00:00
Niklas Laxström
929e707c49 Simplify undo tooltip positioning
OOUI is smart enough to handle this automatically:
https://doc.wikimedia.org/oojs-ui/master/js/#!/api/OO.ui.PopupWidget-cfg-position
https://doc.wikimedia.org/oojs-ui/master/js/#!/api/OO.ui.PopupWidget-cfg-autoFlip

Change-Id: Ib8e4ea0e900b3ea0904b34d82c874227462e342e
2021-04-21 11:48:13 +00:00
Timo Tijhof
a6e0c10c54 ext.uls.interface: remove unused "ulsPopup remove" code
The ulsPopup variable is local to the showUndoTooltip() function.
If it is called multiple times, then a previous assignment of an
OO.ui.PopupWidget object would not be found here in subsequent calls.

This check can only ever be false since it is the first statement in
the function (after variable and function declarations, which don't
do anything other than call `$()`).

Change-Id: I7020c103428d01b5e48c65be695471401f588fc4
2021-04-15 07:01:13 +00:00
Niklas Laxström
50b345c83d Avoid JavaScript errors for tipsy if no entry point on the page
Bug: T278313
Change-Id: I48011eec9f7d876b914550012cc76e2209fc783c
2021-04-14 23:41:54 +00:00
libraryupgrader
e2ab4bb1c3 build: Updating dependencies
composer:
* mediawiki/minus-x: 1.1.0 → 1.1.1

npm:
* eslint-config-wikimedia: 0.17.0 → 0.19.0
  The following rules are failing and were disabled:
  * compat/compat

Additional changes:
* Added the "composer phan" command to conveniently run phan.
* eslint: Renamed `wikimedia/client` profile to `client-es5` (T277085).

Change-Id: Ib31cbcd8c615d2e6abf9ee30f0f4d7b7baa54e2e
2021-04-07 11:10:07 +00:00
Niklas Laxström
3af22f60d4 Fix ULS dialog positioning in some cases
In development environment, ev.currentTarget is the button.
In Beta Cluster, however, once ext.uls.mediawiki is loaded,
it is now the document (the event has bubbled up). I do not
know what causes the difference, but we can use the target.

Bug: T276255
Change-Id: Ie4c425510293a6f2ce81e4bf4a353f2c8d86d412
2021-03-24 10:32:08 +01:00
Niklas Laxström
e8747a022d Avoid content language selector dialog resize shortly after opening
Small dialogs were resizing after loading when display and input
setting buttons were added to it. Now delay showing the dialog until
they are loaded.

Bug: T276248
Change-Id: I7033903737afedbd4be908c84d07656c468ce801
2021-03-22 18:21:16 +00:00
Niklas Laxström
8c835588f2 Fix positioning of input/display settings for new language selector
Unrelated behavior change: ULS language selection dialog is hidden while
display or input settings is open.

Also simplified dead code in addDisplaySettings.

Bug: T276248
Change-Id: Ia91a2b83e7ad4072016649230e2376b0793cbbff
2021-03-22 12:11:39 +00:00
Niklas Laxström
d3a3ac082b ULS: Avoid JS error for undo tooltip with new language button
Change-Id: Ib571152ff14754e186a3e7dd9e1c08bc22239032
2021-03-18 08:43:06 +00:00
Niklas Laxström
dd8842517e Change ULS content language selector positioning
New Vector introduced a new content language selector trigger. This
code was hardcoding a behavior that works for compact language links
but is not so appropriate for other uses in the skin, which are out
of our control.

This patch aims to be a minimal change to allow other kinds of
behavior without changing the amount of tech debt. This changes
the default ULS dialog behavior to match the requirements shown
in the task. Compact language links specific behavior is retained but
only enabled for the compact language links trigger. The behavior
is chosen depending on the value of isUsingStandaloneLanguageButton().

For future changes, I propose that mw-interlanguage-selector class will
not have any styles attached to it. Whoever creates the trigger would
be in charge of styling it. Ideally that code would also define the
positioning and other behavior, but it is less clear how that can be
abstracted in a nice and decoupled way.

Bug: T276248
Change-Id: I52da6c2f5a1f25d64f322a3c8f6105da3b244b66
2021-03-16 22:36:18 +00:00
Niklas Laxström
95b1137a57 ext.uls.interface: clarify code
Changes to comments, naming and code to increase clarity of the code
and explain better what it does and why. No change in behavior.

Change-Id: I998fcfd620c2ee737618c3ab8f41fb6dfdd2c99a
2021-03-16 22:36:16 +00:00
jdlrobson
96656c5f41 Allow access to display and input settings in new vector
Light refactor of existing code into reusable method to support
this.

Use Extension attributes to allow skins to provide ULS
additional configuration.

Bug: T274396
Change-Id: I7dcd49f05fae83fbc0c15768bee8ca93eab17bcc
2021-02-22 11:02:10 +00:00
jdlrobson
64aeedfb17 Modern Vector should be compatible with ULS
Without the following changes the language button shows the
wrong label and opens a dialog with zero languages.

* Don't apply heading change to modern Vector
* Look for the element .mw-portlet-lang as well as #p-lang

Bug: T273232
Bug: T273928
Change-Id: Ic201b1983a17cc37fd1ff7c507aab656ea25f370
2021-02-09 18:07:11 +00:00
jdlrobson
d69d5773e5 Compact language links module is loaded via server side
This provides an alternative mechanism to
I0518ecdf402ebf5eb6bad2c430f6462322c0d8e1 for loading the compact
language link module. Instead of relying on the client, the HTML
is inspected.

Bug: T264824
Change-Id: I977a998388b3e70f7fe4d97fa05be3c1ac1bf676
2020-11-18 17:07:59 +00:00
jdlrobson
ab6decae11 Allow skins to register their own button and disable compact
Example usage:
Iabd4688c6081b4de391b9655b92a16f3a414e018

We will skip loading the compact link if we don't need
to compact the languages.

Note special handling is known for Timeless which stops
propagation of events. This will be fixed in Timeless at a
later date.

Bug: T264824
Change-Id: I0518ecdf402ebf5eb6bad2c430f6462322c0d8e1
2020-11-18 17:06:40 +00:00
Niklas Laxström
5cb2aec0a1 Fix language switching using the undo tooltip
Introduced in I740600d18859422b2f98a5ef92d0321f6e9615a2.

We need to prevent the default action (navigating a link) so that
our custom code has a chance to run. Before it was synchronous so
it called location.href before default action had a chance to execute.
When it was made asynchronous, the default action got executed before
our custom code.

Change-Id: I292f99aa5f5ff536d8197174c317018462685866
2020-10-28 11:44:33 +00:00
Timo Tijhof
09862cffec ext.uls.eventlogger: Remove more obsolete deferred complexity
Follows-up c578db02 and ea671b1f, which I thought removed
all code relating to the old async EventLogging method.
I didn't notice this UI code at the time, because I only took a
single pass over the code to find dead code. Now that that code
is gone, it is clear that the UI code is also redundant.

The mw.track() and logEvent() methods don't track the Beacon API's
async fetches, which also isn't needed, since the loss of browser
context upon navigation doesn't abort background beacons.

The loading of the EL library itself is already ensured via a
dependency so we already know there won't be an async fetch for
that.

What that leaves is some portion of older browsers in which a
EventLogging falls back to 'new Image'. This is basically just
IE 11 per <https://caniuse.com/beacon>, and for those some portion
of events will have been lost since EventLogging removed support
two+ years ago for tracking those fallback fetches via a Promise
(because of the perf issues caused by what the removed code here
was able to do).

Change-Id: Idf4378f983b6ba0e755ebadb97aa6d87cf95f7a5
2020-10-22 23:45:52 +00:00
jdlrobson
5cd10ce862 Reduce JS loaded on critical path
As a precursor to incorporating a new language switcher in the new
version of Vector I'd like to improve the performance of loading
the switcher.

It seems most code can be deferred until the language selector
button is clicked.

This shaves around 30kb of resources off the critical path for
most users. There's potential here for a positive performance
impact so we should follow up the deployment by checking the
associated performance graphs to see if there's improvement.

Note, if the compact personal links feature is enabled
there is no performance saving for now. This will be addressed in follow
ups.

Bug: T153844
Bug: T153845
Bug: T237061
Change-Id: I740600d18859422b2f98a5ef92d0321f6e9615a2
2020-10-20 13:40:49 +00:00
Seb35
54ff8272ab Remove jQuery 3 migration warnings
Bug: T175236
Change-Id: Ibbeec40bd46523c14ba53da1441f46fc9cdfbc10
2020-05-08 11:48:58 +00:00
Fomafix
80b8d411aa Use document.documentElement instead of 'html' as jQuery selector
Change-Id: I1b3bb53a31125333d14d1659fdadd2a81140ae50
2020-01-20 14:52:13 +00:00
Fomafix
61ebecff91 Use document.body instead of 'body' as jQuery selector
Change-Id: Ia551b3050ed546de1f9db44dbd332a5b6c108a9f
2019-12-16 15:51:09 +00:00
Fomafix
6a5b9e3164 Consistently use setTimeout, clearTimeout and location without window
Change-Id: Ie83313b3f2a7f9bc939eb19d7a82bc980f12b0b8
2019-12-16 10:19:35 +00:00
Ed Sanders
b105c2cadc build: Update linters
Change-Id: Ib83952a64224ab550f64975285e60713225b23b7
2019-11-12 14:45:01 +00:00
Ed Sanders
dae53b628c build: Update linters
Change-Id: Ib513d9fe879fb0c848cdfefaaaa753cc7279e242
2019-09-17 14:55:46 +01:00
Ed Sanders
c080452013 build: Update eslint-config-wikimedia to 0.11.0
Change-Id: Ic59891fab5f8e35420bddbed34072841883fa543
2019-03-13 23:41:14 +00:00
Niklas Laxström
e93e1bc845 Remove disabling of max-len rule and fix violations
Change-Id: I39ec2e572e569a05c11929dd17241653abf954ef
2018-12-15 17:12:18 +00:00
Fomafix
d052482cb0 Use <a> instead of <a href="#"> for JavaScript click events
* No status line with URL and "#".
* No new tab on middle click.

tabindex="0" ensures to have the normal tab order.

role="button" according to
https://www.mediawiki.org/wiki/Accessibility_guide_for_developers

Change-Id: I82f1923b3905f111ce7719c03a3919633271720a
2018-10-17 20:16:19 +00:00
Bartosz Dziewoński
f0ad6be4ab Avoid reflow (FOUC) due to ULS link on Special:Preferences
Rather than building the link in JS, which is delayed until the JS
code loads, we build it in PHP and hide it from no-JS users with CSS.

Change-Id: If0c3a4dc137d8bf6cf24957dd063bd0a39791d2e
2018-09-09 10:52:17 +00:00
Timo Tijhof
4e067715dc Remove redundant closure aliases
'mw' are '$' are globals, always have been, and aren't going
anywhere. They're every bit as real as their longer versions.
If anything, the longer ones are less "real" or 'stable" because
they're not used internally by RL and easier to accidentally
replace or override. For anecdotes and history, see 91f950d6b0.

Change-Id: I526fb8c961d9477992d88f2780a0ff4cbdc51923
2018-09-07 19:23:17 +00:00