Jump to content

User:Mxn/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mxn (talk | contribs) at 16:11, 16 March 2012 (using [[mw:CodeEditor|CodeEditor]]). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// importScript("User:ProveIt GT/ProveIt.js");
// [[User:ProveIt GT/ProveIt.js]]

//importScriptURI("http://toolserver.org/~magnus/wysiwtf/wysiwtf.js");

/**
 * MediaWiki:Gadget-codeeditor.js
 * Stub to load [[Extension:CodeEditor]] and Ace syntax-highlighting editor 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:CodeEditor JS bits are GPLv2 -- http://www.mediawiki.org/wiki/Extension:CodeEditor
 *
 * Syntax highlighting, auto-indenting code editor widget for on-wiki JS and CSS pages.
 * Uses embedded Ajax.org Cloud9 Editor: http://ace.ajax.org/
 * MPL/LGPL/GPL
 */
(function($) {
    // @fixme need an SSL alternative
    mw.config.set('wgCodeEditorAssetsPath', '//toolserver.org/~brion/extensions');
 
    var moduleBase = mw.config.get('wgCodeEditorAssetsPath') + '/CodeEditor/modules',
        $box = $('#wpTextbox1'),
        matches = /\.(js|css)$/.exec(mw.config.get('wgTitle'));
    if ($box.length && matches && (wgNamespaceNumber === 2 /* User: */ || wgNamespaceNumber === 8 /* MediaWiki: */)) {
        $(function() {
            var modules = [
                moduleBase + '/ace/ace.js',
                moduleBase + '/ace/mode-javascript.js',
                moduleBase + '/ace/mode-css.js',
                moduleBase + '/jquery.codeEditor.js',
                moduleBase + '/ext.codeEditor.js'
            ];
            var i = 0;
            // @fixme loading serially is kinda lame, but it works for now
            var ping = function() {
                if ( i < modules.length ) {
                    var url = modules[i];
                    $.getScript(url, function() {
                        i++;
                        ping();
                    });
                }
            };
            ping();
        });
    }
})(jQuery);

if (mw.config.get("wgAction") == "view") {
    mw.loader.using("mediawiki.api", function () {
        var api = new mw.Api();
        
        function fetchAdjacentArticle(forward, ok) {
            api.get({
                list: "allpages",
                apfrom: mw.config.get("wgPageName"),
                apnamespace: 0,
                aplimit: 2,
                apdir: forward ? "ascending" : "descending",
            }, {
                ok: function (data) {
                    var pages = data.query && data.query.allpages;
                    var page = pages && data.query.allpages[1];
                    
                    $.get(mw.util.wikiScript("index"), {
                        title: page.title,
                        action: "render",
                    }, ok, "html");
                },
            });
        }
        
        function insertPreviousArticle(title, html) {
            console.log(title, html);                                           // debug
            
            $("#bodyContent").prepend($("#firstHeading"));
            $("#firstHeading").css({
                "font-size": 1.25 * parseFloat($("#firstHeading").css("font-size")),
            });
            
            $("#bodyContent").prepend($(html).wrap("<div id='prevBodyContent'></div>"))
                             .prepend("<h1 id='prevFirstHeading' class='firstHeading assess-c-text'>" +
                                      "<span dir='auto'>" + title + "</span>" +
                                      "</h1>");
        };
        
        $(function () {
            fetchAdjacentArticle(insertPreviousArticle);
//            fetchAdjacentArticle(insertNextArticle);
        });
    });
}