User:Vadim/common.js

From CruisersWiki

< User:Vadim
Revision as of 12:17, 20 January 2016 by Vadim (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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");

// deploy jQuery

(function () {
	var onloadFunctsNew = onloadFuncts;
	onloadFuncts = [];
	var doneOnloadHookNew = false;

	var addOnloadHookOld = addOnloadHook;
	addOnloadHook = function (hookFunct) {
	    // Allows add-on scripts to add onload functions
	    if(!doneOnloadHookNew) {
		    onloadFunctsNew[onloadFunctsNew.length] = hookFunct;
	    } else {
		    hookFunct();  // bug in MSIE script loading
	    }
	}

	var elem = importScriptURI("https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js");

	console.log('jQuery ' + typeof jQuery);
	addOnloadHook(function() {console.log('OnloadHook jQuery ' + typeof jQuery  + ' ' + typeof $)});

	if (elem) {
	    elem.onreadystatechange = function() {console.log('onreadystatechange jQuery ' + typeof jQuery)};

	    elem.onload = function() {
	        console.log('onload jQuery ' + typeof jQuery  + ' ' + typeof $);

	        if (typeof jQuery !== 'undefined') {
		        $.ajaxSetup({
		            cache: true
		        });
        		$(document).ready(function(){
        		    console.log('document ready');
        		    if (!doneOnloadHookNew) {
        			doneOnloadHookNew = true;
        			doneOnloadHook = false;
        			onloadFuncts = onloadFunctsNew;
        			runOnloadHook();
        		    }
        		});
	        }
	    };
	}
})();

function loadScript(url, callback) {
     addOnloadHook( function () {
	var elem = importScriptURI(url);
	if (elem) {
	    elem.onload = callback;
        } else {
            callback();
        }
    });
}

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

function initCodeEditor() {
    $wpTextbox1 = $( '#wpTextbox1' );
    $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" );
    $aceEditor.height($wpTextbox1.height());
    $aceEditor.text($wpTextbox1.text());
    $wpTextbox1.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().setMode("ace/mode/javascript");
}
Personal tools
advertisement
Friends of Cruisers Wiki