User:Vadim/common.js

From CruisersWiki

< User:Vadim
Revision as of 09:13, 22 January 2016 by Vadim (Talk | contribs)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

function addCustomEditButton (imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) {
mwCustomEditButtons[mwEditButtons.length] =
	{"imageId": imageId,
	 "imageFile": imageFile,
	 "speedTip": speedTip,
	 "tagOpen": tagOpen,
	 "tagClose": tagClose,
	 "sampleText": sampleText};
}

addCustomEditButton("/images/7/70/Button_POI.png","Add POI","{{poi | lat= | lon=\n| type=\n| name=","\n| text=\n}}\n","","mw-editbutton-poi");


// load code editor if required
addOnloadHook(function () { // https://ace.c9.io/#nav=embedding
    if ((wgAction == 'edit' || wgAction == 'submit') && (/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName))) {
        loadScript('https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js', initCodeEditor); //function () {});
    }
});

function initCodeEditor() {
    // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts<
    $wpTextbox1 = $( '#wpTextbox1' );
    $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" );
    $aceEditor.height($wpTextbox1.height());
    $aceEditor.text($wpTextbox1.text());
    $wpTextbox1.hide();
    $('#toolbox').hide;

    editor = ace.edit($aceEditor[0]);

    editor.getSession().on(
        'change', 
        function(e) {
            // e.type, etc
            $wpTextbox1.text(editor.getValue());
    });

    //    editor.setTheme("ace/theme/monokai");
    editor.getSession().setUseSoftTabs(true);

    if (/\.js$/.test(wgPageName)) {
        editor.getSession().setMode("ace/mode/javascript");
    } else if (/\.css$/.test(wgPageName)) {
        editor.getSession().setMode("ace/mode/css");
    }
}
Personal tools
advertisement
Friends of Cruisers Wiki