Commit Graph

13 Commits

Author SHA1 Message Date
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
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
Fomafix
6a5b9e3164 Consistently use setTimeout, clearTimeout and location without window
Change-Id: Ie83313b3f2a7f9bc939eb19d7a82bc980f12b0b8
2019-12-16 10:19:35 +00: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
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
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
Niklas Laxström
fa9cea4627 Support UI language change when global preferences are present
Notable changes:
* First query global preferences to detect if global language setting
  is in use. If there is no global language setting, or if GlobalPreferences
  extension is not installed, it will fall back to changing the language
  as usual. If global language setting is found, it will add an override
  instead.
* If a local override is added, the undo tooltip is different and links to
  the global preferences page. The task design shows mw.notify style popup
  located on a bottom right corner (LTR). I deviate from the design and
  re-use the old undo tooltip with a different message instead, for
  consistency. The message is chosen depending on whether local storage
  value `uls-gp` is set to '1' (set in mw.uls.changeLanguage).
* I removed one use of deprecated mediawiki.api.options module. One other
  use still remains.
* I changed tooltip text generation from html acrobatics to use
  mw.message.parseDom. Because of that I also had to move the click handler
  to avoid buildup of click handlers.
* In message documentation fixed acronym -> autonym.

Bug: T198206
Change-Id: Ie2ed792e222be919522bd1cdea98042515a0619d
2018-08-30 22:40:17 +00:00
petarpetkovic
6ce67b8dda Use JS native methods for array manipulations
* In mw.uls.addPreviousLanguage, jQuery.map was used for what is
essentially filtering, not mapping. Filtering was used to remove
one element from array. Use Array.prototype.splice instead.
* In mw.uls.getFrequentLanguageList, replace:
- jQuery.each with Array.prototype.forEach
- jQuery.inArray with Array.prototype.indexOf
- jQuery.grep with Array.prototype.filter

Change-Id: Id2208b3c89e982f91f49981d18e588ae8ce3b130
2018-08-24 20:07:49 +02:00
Kartik Mistry
ca45dc7404 Update eslint and stylelint and fixes
Change-Id: I02e615e0efa95b673702f1ce8c957a37397ced13
2017-11-25 08:34:04 +05:30
Ed Sanders
811944c49a build: Replace jscs+jshint with eslint
Change-Id: I7f114267fbb4efd62a9162758445cff4fb3c0973
2016-11-09 15:57:38 +00:00
jdlrobson
9e0dcbde35 Enable UniversalLanguageSelector modules for mobile
Enable several of the ULS modules so they can be used in a mobile context,
in particular by the Translate Extension

Changes:
* Create a ext.uls.common module that can be loaded safely on mobile
* Only add the ext.uls.init entry point module on desktop (ensured by
the use of targets). On mobile it has no impact other than to increase
the amount of bytes shipped to users.
* Note various modules have not been enabled for mobile usage.

Bug: T102922
Change-Id: If2808886f0bfa153f5918e3c7536e88641028da9
2016-08-17 06:43:46 +00:00