JavaScript gadget – check uniqueness, validity and show position of anchors in page:

Usage

[edit]
mw.loader.load( "https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/fragmentAnchors/r.js&action=raw&bcache=1&maxage=604800&ctype=text/javascript",
                "text/javascript" );

User options

[edit]

CSS

[edit]

The appearance might be changed via CSS.

The following selectors will be provided:

JavaScript

[edit]

The following code should appear on your common.js, global.js or skin dependant JS best before an mw.loader.load() call as described in “Usage” section.

First, the application object is to be etablished:

if ( typeof mw.libs.fragmentAnchors !== "object" ) {
   mw.libs.fragmentAnchors = { };
}

After that, currently there are three options available:

mw.libs.fragmentAnchors.large = true;

This will decorate the full page and does not narrow to content area and not exclude source text edit form.

mw.libs.fragmentAnchors.launch = true;

This will trigger page decoration immediately after loading without generating a link in tool box. It is supposed that loading is limited to certain conditions.

mw.libs.fragmentAnchors.lock = true;

This will prevent from generating a link in tool box and gives opportunity to trigger decoration by any other means, calling .fetch() and .fire() methods.

API

[edit]

After the mw.hook fragmentAnchors.ready has been triggered a function may be called. The application object is the parameter of the mw.hook callback function and should be identical with mw.libs.fragmentAnchors.

All functions are components of the application object.

.fetch()

[edit]

Collect all fragments in HTML document (starting with # and not decoded).

Call .fetch()
Return value
  • Array – three elements
    • [0] Array of string items – all valid fragments in focus
    • [1] Object – all multiplied fragments, else false
      • Every component is a fragment.
      • The number of occurencies is assigned.
    • [2] Object – all missing inner targets, else false
      • Every component is a fragment.
      • The number of occurencies is assigned.
  • false – not yet ready

The document wouldn’t get decorated, except on locations of detected errors.

.fire()

[edit]

Trigger page decoration from external command.

Call .fire()
Return value
  • true – success
  • false – not yet ready, or already executed

Should declare .lock = true; in advance if link in tool box is undesired.

Testing and experience

[edit]

A test page provides examples.

Internationalization

[edit]

Not required, symbols only.

Codes

[edit]
Source code
ResourceLoader
  • ext.gadget.fragmentAnchors for mw:Extension:Gadgets
  • Dependencies:
    • None required (self-completing); 1. + 2. on startup, 3. when activated
      1. user
      2. mediawiki.util
      3. oojs, oojs-ui-core, oojs-ui-widgets
Namespaces Every.
Cookies None
mw.libs fragmentAnchors
mw.hook fragmentAnchors.ready

When page has been equipped with portlet, or is ready for decoration.

MediaWiki 1.23