MediaWiki:Gadget-ParserPlayground.js

From RimWorld Wiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 * MediaWiki:Gadget-ParserPlayground.js
 * Stub to load [[Extension:ParserPlayground]] as a gadget.
 *
 * Requires enhanced editing toolbar (WikiEditor extension); integrates with toolbar.
 *
 * Gadget stub CC-BY-SA 2
 * (c) 2011 Brion Vibber <brion @ pobox.com>
 * 
 * Extension:ParserPlayground JS bits are GPLv2 or compat -- http://www.mediawiki.org/wiki/Extension:ParserPlayground
 */
( function($) {
    // @fixme need an SSL alternative
    mw.config.set('wgParserPlaygroundAssetsPath', 'http://toolserver.org/~brion/extensions');
    var moduleBase = mw.config.get('wgParserPlaygroundAssetsPath') + '/ParserPlayground/modules';
    var $box = $('#wpTextbox1');
    if ($box.length) {
        $(function() {
            var scripts = [
                'lib.jsdiff.js',
                'lib.pegjs.js',
                'jquery.nodetree.js',
                'ext.parserPlayground.hashMap.js',
                'ext.parserPlayground.classicParser.js',
                'ext.parserPlayground.serializer.js',
                'ext.parserPlayground.renderer.js',
                'ext.parserPlayground.pegParser.js',
                'ext.parserPlayground.js'
            ],
            styles = [
                'jquery.nodetree.css',
                'ext.parserPlayground.css'
            ],
            $head = $('head');

            mw.messages.set({
                'vis-edit-source-ok': 'Ok',
                'vis-edit-source-cancel': 'Cancel'
            });

            $.each(styles, function(i, style) {
                var $link = $('<link>')
                    .attr('rel', 'stylesheet')
                    .attr('href', moduleBase + '/' + style)
                    .attr('type', 'text/css');
                $head.append($link);
            });
            $.each(scripts, function(i, script) {
                var $script = $('<script>').attr('src', moduleBase + '/' + script);
                $head.append($script);
            });
        });
    }
})(jQuery);