Expand all

mw.guidedTour.TourBuilder

A builder for defining a guided tour

Constructor

new mw.guidedTour.TourBuilder(tourSpec) #

Constructs a TourBuilder, backed by a tour, based on an object specifying it.

The newly constructed object can be further configured with fluent methods, such as #step

Parameters:

Name Type Description
tourSpec Object

Specification of tour

Properties:
Name Type Attributes Default Description
name string

Name of tour; must match module or wiki page name

isSinglePage boolean optional
false

Tour is used on a single page tour. This disables tour cookies.

showConditionally string optional

condition for showing tour. Currently, the supported conditions are:

  • 'stickToFirstPage' - Only show on pages with the same article ID (non- special pages) or page name (special pages) as the first page it showed on.
  • 'wikitext' - Show on pages that are part of a wikitext flow. This means all pages where the VisualEditor is not open.
  • 'VisualEditor' - Show on pages that are part of the VisualEditor flow. This means all pages, except for the wikitext editor, wikitext preview, and wikitext show changes.
emitTransitionOnStep boolean optional
false

Whether to emit a transition even (meaning transition callbacks are run) when the user clicks next or back.

Source:

Throws:

If tourSpec is missing or the tour is unnamed

Type
mw.guidedTour.TourDefinitionError

Methods

firstStep(stepSpec) → {mw.guidedTour.StepBuilder}static #

Creates and returns a StepBuilder, marking it as the first step (entry point) of the tour. This can only be called once.

Parameters:

Name Type Description
stepSpec Object

specification for step; see #step method for details.

Source:

Returns:

Created StepBuilder

Type
mw.guidedTour.StepBuilder

Throws:

When the step specification is invalid, or the first step has already been specified

Type
mw.guidedTour.TourDefinitionError

Creates and returns a StepBuilder, marking it as the first step (entry point) of the tour.

step(stepSpec) → {mw.guidedTour.StepBuilder}static #

Creates and returns a new StepBuilder, used to build a step of the tour. The StepBuilder will be bound to the tour being built.

Parameters:

Name Type Description
stepSpec Object

specification for this step of the tour

Properties:
Name Type Attributes Default Description
name string

Step name. This identifier is not displayed to the end user. but can be used as a reference to a step

title string

Title of guider. Used only for on-wiki tours

titlemsg string

Message key for title of guider. Used only for extension-defined tours

description string | mw.guidedTour.WikitextDescription | mw.Title

Description of guider. A string is treated as HTML, except that for backwards compatibility, if onShow is gt.parseDescription or gt.getPageAsDescription, the string is interpreted as described in onShow.

descriptionmsg string

Message key for description of guider. Used only for extension-defined tours.

position string | Object

A positional string specifying what part of the element the guider attaches to. One of 'topLeft', 'top', 'topRight', 'rightTop', 'right', 'rightBottom', 'bottomRight', 'bottom', 'bottomLeft', 'leftBottom', 'left', 'leftTop'

Or:

{
    fallback: 'defaultPosition'
    particularSkin: 'otherPosition',
    anotherSkin: 'anotherPosition'
}

particularSkin should be replaced with a MediaWiki skin name, such as monobook. There can be entries for any number of skins. 'defaultPosition' is used if there is no custom value for a skin.

The position is automatically horizontally flipped if needed (LTR/RTL interfaces).

attachTo string | Object | jQuery

The selector for an element to attach to, a jQuery-wrapped node, or an object for that purpose with the same format as position. The values within the structure can also be selectors or jQuery-wrapped nodes.

width number optional
400

Width, in pixels.

onShow function optional

Function to execute immediately before the guider is shown. Using this for gt.parseDescription or gt.getPageAsDescription is deprecated. However, a string value of description is interpreted as follows:

  • gt.parseDescription - Treat description as wikitext
  • gt.getPageAsDescription - Treat description as the name of a description page on the wiki
allowAutomaticOkay boolean optional
true

By default, if you do not specify an Okay or Next button, an Okay button will be generated.

To suppress this, set allowAutomaticOkay to false for the step.

allowAutomaticNext boolean optional
true

By default, if you call .next() and do not specify a Next button a next button will be generated automatically.

To suppress this, set allowAutomaticNext to false for the step.

autoFocus boolean optional
true

By default, the browser will scroll to make the guider visible.

To avoid this, set autoFocus to false for the step.

closeOnEscape boolean optional
true

Close the guider when the user presses the Escape key

closeOnClickOutside boolean optional
true

Close the guider when the user clicks elsewhere on screen

buttons Array

Buttons for step. See also above regarding button behavior and defaults. Each button can have:

Properties:
Name Type Attributes Description
name string

Text of button. Used only for on-wiki tours

namemsg string

Message key for text of button. Used only for extension-defined tours

onclick function

Function to execute when button is clicked

action string

Action keyword. For actions listed below, you do not need to manually specify button name and onclick.

Instead, you can pass a defined action as part of the buttons array. The actions currently supported are:

  • next - Goes to the next step. Requires mw.guidedTour.StepBuilder#next also be called, to specify how the next step is determined.

  • back - Goes back specified step. Requires mw.guidedTour.StepBuilder#back also be called, to specify how the step is determined.

  • okay - An arbitrary function is used for okay button. This must have an accompanying 'onclick':

    {
        action: 'okay',
        onclick: function () {
             // Do something...
        }
    }
    
  • end - Ends the tour.

  • wikiLink - links to a page on the same wiki

  • externalLink - links to an external page

A button action with no parameters looks like:

{
    action: 'next'
}

Multiple action fields for a single button are not possible.

page string

Page to link to, only for the wikiLink action

url string

URL to link to, only for the externalLink action

type string

string to add button type class. Currently supports: progressive, destructive.

classString string optional

Space-separated list of additional class names

Source:

Returns:

Created StepBuilder object

Type
mw.guidedTour.StepBuilder

Throws:

When the step specification is invalid

Type
mw.guidedTour.TourDefinitionError
Creates and returns a new StepBuilder, used to build a step of the tour.