user:js/ajaxPreview

From OpenWetWare
Jump to: navigation, search
ajaxPreview
Browsers *
Skins *
Code ajaxPreview.js
Updated 2009-07-26; 8 years ago
Developer   AlexSm

The script adds new preview and changes Ajax update buttons:

  • they are faster than standard buttons,
  • they retain the text cursor position and undo (Ctrl-Z) history,
  • and preview button uses less traffic.


Note that the standard «Show preview» is still required:

  • to update the preview of interwikis, categories, edit summary, and the list of used templates;
  • after you insert <source lang="xxx"> or <categorytree> for the first time.


Installation

Add this to your monobook.js (unless you use some other skin)
importScript('User:Js/ajaxPreview.js')


Configuration

By default the new buttons:

  • are placed on the right from the toolbar:

BIAb........................   previewchanges

  • capture p and v accesskeys from the standart buttons.
  • get names from the standard buttons (using last word).

This can be changed with the following parameters in your monobook.js.

Position: <source lang="javascript"> ajaxPreviewPos = 'left' //buttons on the left </source>

<source lang="javascript"> ajaxPreviewPos = 'bottom' //buttons on the bottom, replacing standard </source> Then standard buttons are then moved to the right and marked with ">": Save page Show preview> Show changes>

Accesskeys: <source lang="javascript"> ajaxPreviewKey = 'o' //"preview" button accesskey ajaxDiffKey = 'b' //"changes" button accesskey </source> Use empty string '' to disable accesskey.

Button text: <source lang="javascript"> ajaxPreviewButton = 'Ω' //"preview" button text ajaxDiffButton = 'Δ' //"changes" button text </source>

Scrolling: <source lang="javascript"> ajaxPreviewScrollTop = true //scroll to the top of preview/changes area after each update </source>


Compatibility with scripts

The script automatically calls sortable and collapsible JavaScript code after every preview update.

You can make it call any custom userscripts by defining ajaxPreviewExec() function. For example, if you use NavPopups and want popups to appear in the Ajax-updated preview, use the following code:

<source lang="javascript"> ajaxPreviewExec = function(previewArea){ //code to execute after each preview update

 if (window.setupTooltips) setupTooltips(previewArea)

} </source>


Notes

  • Script should work in all modern browsers, except Firefor 3 early betas.
  • Script was tested in Firefox 1.5, 2 and 3, Opera 9.27 and 9.52, IE 6 and 7.
  • «Preview» button uses &live index.php parameter, just like Live preview which is disabled here.
  • «Changes» button has to submit and receive the full page, since the MediaWiki cannot return "raw" changes.

ru:Википедия:Гаджеты/Ajax предпросмотр