Commit Graph

815 Commits

Author SHA1 Message Date
Niklas Laxström
4387bb9d61 CompactLinks: Better handling of opening links to new tab/window
* Check for any of Shift, Ctrl or Meta
* Only do it for links
* Support both mouse and keyboard

Change-Id: I0b331b802e1d96ae0e0511746d6b42663db924b1
2020-11-16 14:51:47 +00:00
jdlrobson
e3569d32a7 Separate compacting of language list from launching of dialog
This refactor will allow us to separate these two functions so that
the modernized version of Vector can avoid loading the compact
language list.

Changes:
* `options` is now optional to the CompactInterlanguageList constructor
The max value is already defined in
CompactInterlanguageList.prototype.init
* this.interlanguageList is now initialized inside the constructor
Previously calling CompactInterlanguageList.prototype.createSelector
or getCompactList before calling init would throw an exception.
This will be important in I0518ecdf402ebf5eb6bad2c430f6462322c0d8e1 when
the responsibilities of wiring up the button and compacting the languages
is separated.

Bug: T264824
Change-Id: I9606df30a050d0cdaf7add2deff849cd5b895bab
2020-11-05 08:44:06 +00:00
Niklas Laxström
79a038f166 Handle Apply button little bit more sanely
Change-Id: I55d48de703662f139549d764bf7c1f235111d5ab
2020-11-02 11:08:25 +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
Niklas Laxström
094c30bc1c Fix language selection using [...] button
Introduced in I740600d18859422b2f98a5ef92d0321f6e9615a2.

When onSelect was called for the new language, it set dirty to true.
Then the, now delayed, render function reset the dirty status to false.

There is no need to set dirty to false on render, so moved it to the
constructor.

Change-Id: Ibfa23f545c9d358e7e03fb299c238182ea449d7c
2020-10-28 09:29:47 +01: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
f8fde38197 Use require to clarify ext.uls.preferences
ext.uls.preferences only depended on ext.uls.common because of its
use of the uls global. This is unnecessary, and made clearer by using
require and module.exports to access it.

Change-Id: Ied2a1b560d19a18529fd766ced778c912199fa2f
2020-10-20 16:08:59 +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
jdlrobson
a1963ce12d Merge ext.uls.inputsettings into ext.uls.displaysettings
These modules are always loaded together. There is no need to load
them in separate ResourceLoader modules

Change-Id: Ibdf7d1bbd9090ffed6a142055ee684ad97dd6680
2020-10-14 21:11:03 +00:00
Reedy
99937ba18b Add GochiHand font
Bug: T258839
Change-Id: I38eacbfbc3293c7b7a2a6bf4f680b2f70f1a43ad
2020-09-16 05:20:07 +00:00
David Kamholz
dc4937eb1f update Bali fonts to fix spacing issue
Change-Id: I221e9c2db3373ffc14a9f764e5de311e980a93a6
2020-07-27 14:29:15 -07:00
Ed Sanders
e128c51356 build: Update eslint-config-wikimedia to 0.16.2
Change-Id: Iea4b73bdceb66e113b7f9c9244ae6b37a3ce205f
2020-07-09 16:40:05 +01:00
Seb35
54ff8272ab Remove jQuery 3 migration warnings
Bug: T175236
Change-Id: Ibbeec40bd46523c14ba53da1441f46fc9cdfbc10
2020-05-08 11:48:58 +00:00
David Kamholz
a1628b0af0 Balinese fonts: update Pustaka Bali and add new Kadiri font
Change-Id: Ica823ce359bcdacc4982faf6c19f37549be37088
2020-04-20 04:27:49 +00:00
Abijeet Patro
56c38a5515 Revert "Simplify ext.uls.preferences module"
This reverts commit 61f1a9863a.

Reason: mw.storage.getObject was introduced in MW 1.34. Need to
support MW 1.33 for MLEB 2020.04 release.

Change-Id: If9cd8d1f9e1ab544eba280c8fa7b36db91b64573
2020-04-16 12:43:38 +00:00
David Kamholz
44ea2ceeb3 added Pustaka Bali and Vimala fonts for Balinese
Bug: T247142
Change-Id: Ie77a72ca532272662dd2c3f7f4d5a3ea2236f067
2020-03-09 05:47:15 +00:00
Reedy
da1c81d691 Run compile-font-repo.php
Running it on a repo without any changes, results in ext.uls.webfonts.repository.js changes

Change-Id: I28353a1da384eb6e3386d8697e80a2b33daaf455
2020-03-07 08:05:45 +00:00
Niklas Laxström
61f1a9863a Simplify ext.uls.preferences module
Related to T246370

Change-Id: Iedef79c75ef0ab9c1baff5a0e6f1953c3c56ac91
2020-03-03 11:38:23 +00:00
Fomafix
9fabb9a4ff Simplify variable assignment.
This makes the code shorter and the message is generated only in the
else path.

Change-Id: I1367280b6c154fe77b8a2cfbcdb6333aecefab53
2020-01-23 14:40:25 +01:00
Thiemo Kreuz
a5ae7cb556 Streamline a few pieces of JavaScript code
The main goal here is to reduce complexity. For example, the method to
remove a parameter from the current URL is never used with another
parameter. The complexity is not needed.

This is inspired by the changes I have seen in Icaf086f.

Change-Id: If22c25e84f50ac380320cd581690835ddb70f01d
2020-01-23 09:29:12 +00:00
Abijeet
459d55c5d3 Remove setlang URL parameter on dialog close
Add two new options for ext.uls.dialog - afterOpen and afterClose.
These are callback function which will be triggered after the dialog
opens or closes.

Using the afterClose callback in ext.uls.setlang to remove the
setlang parameter from the URL if the dialog is closed without
pressing any button. This might happen if the user closes the dialog
by pressing Esc, or by clicking on the overlay.

Also see: Ie3215d12d9c77f15597495e21610707b272eeee9

In addition, renamed all occurrence of setlang to setLang.

Bug: T63115
Change-Id: Icaf086f947b1d91bf7ad5b36f126da0be1fc7747
2020-01-23 09:27:15 +00:00
Fomafix
80b8d411aa Use document.documentElement instead of 'html' as jQuery selector
Change-Id: I1b3bb53a31125333d14d1659fdadd2a81140ae50
2020-01-20 14:52:13 +00:00
Abijeet
5ad4f74ea9 Add support for keyboard events for the setlang dialog
Support has been added for:

* Esc: Closes the dialog
* Tab: Ensures that tabbing keeps focus on the focusable elements
  in the dialog. If no overlay is not present, the focus is
  allowed to flow normally.

This should not happen but if NO focusable elements are found and
overlay is displayed, focus is locked on the overlay.

Also add description and other license information for uls.dialog
& uls.setlang files.

Bug: T63115
Change-Id: Ie3215d12d9c77f15597495e21610707b272eeee9
2020-01-14 15:14:37 +00:00
Fomafix
5fda459531 Remove URL parameter setlang from history when language is unchanged
This change allows to use the ULS language changer without getting a
dialog for restoring the old language.

This change requires that the module is also loaded in this case.

Change-Id: Ie5169e986d0362034ede122b0bc29ce7a4aa481e
2019-12-19 20:32:25 +01:00
Fomafix
d31fddd8e7 Use history.replaceState instead of history.pushState
This removes the URL with the URL parameter setlang from the history.
A click on history back doesn't show the URL parameter setlang anymore.

Change-Id: I0ea8c4508bedd9758a1cebbe8ecb2a7113bf8538
2019-12-19 20:11:19 +01:00
Abijeet
ff02e63a45 Update setlang to display confirmation dialog to change language
setlang will now display a dialog to confirm with the user that
they would like to change their interface language. The preferred
language will only be updated if the user confirms.

The dialog will be displayed if the setlang parameter is present in
the query string and,

* A user is logged in, and their preferred language is not the same
  as the one passed via setlang.
* For an anonymous user if the wgULSAnonCanChangeLanguage is true,
  and the current interface language is not the same as the one
  passed via setlang.

Bug: T63115
Change-Id: I882297d99a594fd82fd0aec3b4664e8bfd1eac3a
2019-12-19 14:54:34 +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
Ladsgroup
32b36828fd Revert "Return target of redirect languages in mw.uls.getFrequentLanguageList"
This reverts commit 76551ed4a7.

Reason for revert: It seems it's breaking Serbian editing Wikidata

Bug: T217770
Bug: T121747
Change-Id: If69156400ff665a8c488a24f70d6a100e26761da
2019-08-25 22:11:57 +00:00
Amir Sarabadani
76551ed4a7 Return target of redirect languages in mw.uls.getFrequentLanguageList
When mw.uls.getFrequentLanguageList() is requested sometimes
the language that is a redirect returned causing other codebases (like Wikibase)
to show an invalid language to the user.

Bug: T217770
Change-Id: I49c802d584081aa5992dd0ba76144059bcac56c8
2019-07-18 09:23:34 +00:00
Fomafix
8366a0a029 ext.uls.eventlogger: Remove use of mw.eventLog.logEvent() promise
This change prevents a failure when clicking on the language revert
button.

This change is a follow-up to c578db020d.

Change-Id: Ic5da1b1dcdcc07de417a6eef0189940cb5a2392f
2019-04-26 21:26:51 +00:00
Timo Tijhof
ea671b1f24 ext.uls.eventlogger: Use mw.track() and remove EventLogging dep
Given the code no longer uses any EventLogging methods directly,
but rather mw.track(), this means it also doesn't need to declare
any dependencies, including for older MediaWiki versions this
will work as-is.

Change-Id: I8cdcef54321d0887c509fc3683acf132c113e628
2019-04-17 04:04:01 +00:00
Timo Tijhof
c578db020d ext.uls.eventlogger: Remove use of mw.eventLog.logEvent() promise
I guess the expectation was that for browsers that don't support
Navigator.sendBeacon, the promise would wait for the 'new Image'
fallback to complete.

However, EventLogging never did that. In browsers where the Beacon API
is not supported, 'new Image' starts asynchronously and either
way the returned promise is immediately resolved.

The only purpose of the returned promise was to detect errors
in the format of the event (e.g. missing properties), which this
code is not concerned with (given that it uses "always",
not "done"). And besides, for that you'd probably want to use
the EventLogging debug mode [1] instead.

This is the last step before ULS can switch to a soft EL dependency
by using mw.track instead, which I'll do in the next commit.

Change-Id: If016b73dcd7320ddf1478c1678d2cc6371fe0fa1
2019-04-17 04:03:47 +00:00
Santhosh Thottingal
da0aad3e03 Add fonts for Church Slavonic
Adding Ponomar, Fedorovs, Menaion and Monomakh restaurant.

Bug: T156843
Change-Id: I8f7c4861fc667bba3dfd4359f2c59633fa6f83ff
2019-04-01 12:39:33 -07:00
Ed Sanders
c080452013 build: Update eslint-config-wikimedia to 0.11.0
Change-Id: Ic59891fab5f8e35420bddbed34072841883fa543
2019-03-13 23:41:14 +00:00
Timo Tijhof
232b6a8a58 ext.uls.eventlogger: Remove unused class
* Simplify as pure functions.
* Remove unused 'schema' parameter to log().
* Remove unused 'module.exports'.

Change-Id: I900303f29cc425cc579acc7379a88ef4f0e882af
2019-03-13 18:11:57 +00:00
Timo Tijhof
1c99196ef8 ext.uls.eventlogger: Remove unused code
Follows-up e58be7c411, 1ad0c9c819.

* The mw.uls.eventlogger property does not appear to be
  used anywhere indexed by Codesearch. It was also undocumented.
  Removed without deprecation. Kept exposed for debugging purpopses
  via module.exports, which could be retreived in tests via require(),
  or via mw.loader.require() from the browser console.

* Remove redundant $.Deferred wrapper.

Change-Id: Id081038e5d4902c7e38967353c6f551c12517311
2019-02-19 08:44:36 +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
petarpetkovic
4dc988f6b9 Replace $.each usage in ext.uls.compactlinks with native JS
Change-Id: Icda997b910162b2c220e35ff360a70ade992b71b
2018-12-14 17:44:05 +01:00
Ed Sanders
7bf345669a build: Update linters
eslint-config-wikimedia      0.8.1  →   0.9.0
 stylelint-config-wikimedia   0.4.3  →   0.5.0

Change-Id: I0f55e743c2f38bb8910931c3989a6516e0527703
2018-12-10 14:24:24 +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
Niklas Laxström
dd390d2ec0 Do not precompute href or autonym in #getInterlanguageList
Only store reference to the element, where they can easily be read
when needed.

Also removed one unnecessary use of `self` as an alias.

Change-Id: I39fa897002037a6d6478a3fb1f40ac60833e392e
2018-10-11 13:07:25 +00:00
Niklas Laxström
5ed2ff7d8f Update some outdated comments
Change-Id: I73c7b0549d7335019a1919229afa2e45a92ffacd
2018-10-10 16:14:05 +00:00
Timo Tijhof
1ad0c9c819 ext.uls.eventlogger: Remove use of removed setDefaults() method
Follows-up 2ac8a0a4b6, which removed this method. In checking
Codesearch, I somehow missed this one call among the false positive
results for Datepicker and TMH-related calls to a different method
also called "setDefaults".

Bug: T206588
Bug: T187207
Change-Id: I4f94ce6f8f1b85c192b69c5b50c3f090f7b4bfd2
2018-10-10 02:42:02 +00:00
Timo Tijhof
fcfa36ac77 compactlinks: Optimise performance of list creation logic
Add potential items directly to a single array with two indexOf
checks.

Previously, potential items were first put in a new temporary array,
then that array was filtered with indexOf checks into another temporary
array, and then the result of that combined with the previous results
into another temporary filtered array, and then the previous results
array replaced with the new one. This eliminates 2*2N filter+concat
calls an their overhead from calling functions, creating arrays,
copying arrays and the memory for those arrays. (Where N is the number
of language-list strategies). It also reduces the total number of
indexOf calls.

Below is a comparison of time spent in createCompactList() during
page load process, compared to master without this and the previous
commit. Measured on localhost with Vector, EventLogging, Interwiki,
and ULS installed; on a page that is a copy of en.wikipedia.org/Messier_87
and its 51 interlanguage links. This page was a featured article
last week. Its count of links seems average compared to other
featured and/or most-viewed articles last week (the other ones
I checked had 23, 43, 52, and 76 langlinks respectively).

|--------------|----------|--------|
|              | Before   | After  |
|--------------|----------|--------|
| Chrome 69    | 77.5ms   | 41.4ms |
| MacBook Pro  | 57.7ms   | 44.4ms |
| CPU 1/6th    | 63.8ms   | 45.3ms |
|--------------|----------|--------|
| Firefox 61   | 12ms     | 10ms   |
|              | 10ms     | 9ms    |
|              | 11ms     | 8ms    |
|--------------|----------|--------|
| Safari 11    | 3.5ms    | 2.7ms  |
|              | 3.3ms    | 2.6ms  |
|              | 3.4ms    | 2.8ms  |
|--------------|----------|--------|

Bug: T127328
Change-Id: I56052e7c01c6a667500773e12c755a7a5f5d9cd0
2018-09-24 17:19:45 +00:00
Timo Tijhof
effcd80471 compactlinks: Optimise performance of DOM logic
The createCompactList() function runs synchronously during the
module execution burst. Due to it visually changing the page, I
won't defer it with rIC for the time being, although that should
be considered for the future. For this commit, I'm trying to make
it fit the budget of <50ms because ULS is currently usually taking
80ms-180ms on desktop (MacBook/Chrome CPU/4), and that's during
batch execution with other modules as well, thus freezing the
UI thread for much longer than that.

constructor:
* Remove needless clone of jQuery object.
  Use $foo instead of $( $foo ).
* Remove creation of 'interlanguageList' and 'compactList' objects
  that are immediately removed and re-created by init().

init/getInterlanguageList:
* Use the HTMLElement.lang and HTMLAnchorElement.href properties
  directly instead of the DOM getAttribute().
  This means stores a full url instead of a relative url, which
  should help avoid other bugs in the future.
* Remove needless jQuery() constructor and jQuery.text() call.
  Use Node.textContent directly instead.
* Use HTMLElement#querySelectorAll instead of jQuery#find().

init/getCompactList/../filterByLangsInText:
* Avoid jQuery() constructor and jQuery.attr(),
  use the HTMLElement.lang property directly.
* Avoid jQuery() selector, call querySelectorAll directly.

init/getCompactList/../getCommonLanguages/../getFrequentLanguageList:
* Avoid temporary array copies from concat() and function overhead
  with forEach() and filter().
  Instead, keep only a single array, and iterate it once.

init/getCompactList/../filterByBadges (~10m -> ~0.5ms):
* Use one query via $(), instead of two queries $()+find().
* Use $.map() directly instead of map()+fakejQueryObject+toArray().
* Use querySelector(One) for the child instead of $()+find().
* Use HTMLElement.lang property directly.

init/hideOriginal (~5m -> ~0.8ms):
* Use querySelectorAll() directly instead of jQuery find().
* Set HTMLElement.style directly instead of jQuery() css().

init/render/addTrigger:
* Use createElement() and direct properties instead of $(), addClass(),
  prop() and text().
* The mw.msg() calls use text() and jqueryMsg#parser which is
  expensive.
  Use plain() for 'ext-uls-compact-link-info', which doesn't need parsing.
  Keep text() for the other message, and document why.

init/listen:
* Use async Deferred#then() instead of sometimes-sync Deferred#done().

Bug: T127328
Change-Id: I424c34fb82c8e95407f7b934e6d42019becbf909
2018-09-13 11:11:42 +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
Fomafix
971e4c742d Simplify by using native JavaScript instead of jQuery
Still use $.each for iterating over an Object because there is no
adequate function in ES5.

Change-Id: Idbec13c471e75a9cd5d67204d54bededdbd5582b
2018-09-07 22:35:13 +00:00