Page MenuHomePhabricator

Gadgets should provide skipFunctions
Open, Needs TriagePublicBUG REPORT

Description

Many gadgets are loaded in environments they are not ever used. For example:

  • A gadget may want to be used in devices where a mouse is available (and thus it is possible to hover over references).
  • Some gadgets require a certain screen size
  • Some gadgets rely on a certain editor being available e.g. mobile editor
  • Some gadgets add functionality that is not needed on the mobile Minerva skin. For example section collapsing is added on Minerva but only on mobile site. The MultimediaViewer is different on mobile and desktop (tracked in T65504) and Minerva has native support for tooltips so the gadget Reference Tooltips is not needed there.
  • MobileFrontend removes content from the article which means gadgets don't work as expected e.g. removal of navboxes breaks the navboxNavigation gadget. (T124168)

Originally suggested by @Tgr in T127268#8974464 we should provide "skipFunctions" for gadgets that allow gadget code to not load in certain circumstance.

Initially skipFunctions could be defined inside the Gadget extension and Gadget definitions could use them by reference

e.g. This might look something like this where requires=!touch-device adds a skip function relating to touch device support.

var isTouchDevice = 'ontouchstart' in document.documentElement;
var desktopResolution = window.innerWidth >= 1000;
* ReferenceTooltips[ResourceLoader|default|requires=!touch-device,desktop-resolution|skins=vector,vector-2022,monobook,timeless,modern,cologneblue|type=general|dependencies=mediawiki.cookie,jquery.client]|ReferenceTooltips.js|ReferenceTooltips.css

Event Timeline

the ReferenceTooltips gadget loads on all pages, but can only be used in devices where a mouse is available (and thus it is possible to hover over references).

Not correct: tooltips are just activated by click on touch devices, not by mouse hover. In fact, ReferenceTooltips even allows to read tooltips over <abbr> tags (for example, here in the "Historical population" table) that are otherwise unreachable on touch devices.

We could also just allow skip functions to be defined the same way as other JS code, on a JS wiki page (maybe with some built-in defaults).

Yeah, I think, if the future is ‘drop the checks entirely and load the same bandwidth of gadgets at mobile and desktop’, checks in the gadgets themselves seem like a much more sensible path than whatever skip functions are. It’s not like this kind of system would simplify anything, unless it was something more generic like a gadget with a skip page defined implements a module that only returns a check for its requirements, and only when the check is true, loads its JS to users. Doesn’t seem much sense to implement this for two simplifying writing a few JS variables.

If anything, it is kind of problematic in the same sense that JSON pages addition was: testing gadgets as interface admins would become harder because there might be a possibility that their code doesn’t work in its entirety and the reason isn’t noted anywhere in the code itself (with JSON pages bundling, it became harder because of require, gadget authors have to add debug variables for their testing now).