Extension:GuidedTour/Shared tour instructions

A series of steps edit

First, you have to consider when and how your tour should start.

The tour itself is a sequence of dialog windows that appear on the page, called steps. (It is possible to have a single-step tour that operates as a fancy tooltip, and to jump into the tour at different points.)

Each step can optionally have a next button, a back button, or both. You can also have the tour automatically move (transition) from one step to another in response to a user action (for instance, when the user makes their first change to an open VisualEditor window). You define the tour in a JavaScript function, calling API methods to construct and link the steps together.

The extension keeps track of the current step in each tour in a browser cookie. By default, a tour will continue across multiple web pages.

Implementation edit

  1. Consult the design recommendations and the API documentation.
  2. Choose a tour name. This should be set when constructing the TourBuilder (see example tours below).
    name: 'tourname',
  3. For each step in your tour:
    1. Choose title and description text.
    2. Then, choose whether the step will have an attachment or a central overlay:
      • Attachment positions a step near a page element such as the Edit tab, a link, or the save button. You identify the page element using a selector. Any jQuery selector can be used. In general, this includes all CSS selectors. This example positions near the Edit tab using an id selector:
        attachTo: '#ca-edit',
        For attachments, you must choose an attachment position. The choices are topLeft, top, topRight, rightTop, right, rightBottom, bottomRight, bottom, bottomLeft, leftBottom, left, leftTop. You can experiment with these values, and may want to test in a skin beside your primary one (using the useskin parameter). For on-wiki tours, you should test in the wiki's site direction (which does not vary by user or according to uselang). If you're not sure what this is, you can check in a JavaScript console with:
        $( document.body ).is( '.sitedir-ltr' ) ? 'ltr' : 'rtl'
        Extension-defined tours should always be written left-to-right. In either case (on-wiki or extension tours), if the user is using another direction (for example, they are browsing English Wikipedia but have their interface language set to Hebrew in preferences), steps will automatically flip horizontally.
      • By default (if you do not choose one of the directions above) the step shows in the center of the screen. This allows you to explain something without attaching to an element. In this case, it is recommended that you use an overlay to draw focus to the step:
        overlay: true,
    3. To link steps together, you can use Next and Back buttons. These will automatically be added if you tell the tour how to find the Next and Back steps. For example:
      • For Next:
        step.next( 'nextStep' );
      • For Back:
        step.back( 'previousStep' );
      Both Next and Back can be used on the same step. Also, more powerful behavior is available (such as choosing a different next or back step depending on context); see the 'next' and 'back' methods in the API documentation.
    4. Choose any further button actions you want to add to the step. If you want the user to click something (such as the edit tab), you can provide no explicit buttons (an Okay button that dismisses the step will still show). If you only want Next and/or Back buttons, you do not need to specify anything here (see above). Otherwise, you will want to specify one or more. You can specify arbitrary button actions. However, there are helpers included for common button behaviors. For okay and end, no custom button text is necessary. For the others, use name or namemsg (see below sections):
      • okay - Shows as an Okay button. Will run the specified function when the button is clicked.
         { action: 'okay', onclick: function () { /* ... */ } }
      • end - Shows as an Okay button. Will end the tour when clicked.
        { action: 'end' }
      • wikiLink - Shows as a textual button. Will go to the specified wiki page when clicked.
        { action: 'wikiLink', page: 'Name of page' }
      • externalLink - Shows as a textual button. Will go the specified external web site when clicked.
        { action: 'externalLink', url: 'http://example.com' }
      • For any of the buttons, you can specify the type of button as neutral, progressive, constructive, destructive, or quiet. See the Living Style Guide for an explanation of the meanings. For example:
        { action: 'wikiLink', page: 'Name of page', type: 'neutral' }
      • You can add arbitrary CSS classes to the button using the classString parameter. For example:
        { action: 'wikiLink', page: 'Name of page', type: 'neutral', cssClass: 'class_1 class_2' }
    5. By default, the step will close when they click outside it. In some cases, such as on the edit page, you may want to disable this by including:
      closeOnClickOutside: false,
    6. Decide if you want transition behavior. In some cases, you will want to automatically transition to another step when an event (including page load) occurs. For example, if you have a step asking the user to click Edit, you may want to transition to a step pointing to the Preview button ("explainPreviewButton" in this example) once they're on the edit page. For more information about transitions, see the API documentation on the 'transition' method.
       step.transition( function () { if ( gt.isEditing() ) { return 'explainPreviewButton'; } } )

Note that if a step doesn't have a button to take them somewhere, you'll generally want to implement a transition() function for the current step that allows them to go somewhere. Otherwise the tour will "stall" on it — every time the user reloads the page or visits any page that loads your tour, the current step will reappear until the user exits the tour.

Tips edit

  • Use debug mode while developing your tours.
  • Inspect the tour cookie (named wgCookiePrefix-mw-tour) to see what step your tour is on.
  • Even when writing an on-wiki tour, use a JavaScript checker such as jshint to check for errors in your tour definition.
  • When stepping through your code in a browser debugger, the show() function in guiders.js is one of the most useful functions in which to set a breakpoint.

This is used at Guided tours/Write an on-wiki tour and Guided tours/Write an extension tour for common initial instructions.