User:Vadim/common.js

From CruisersWiki

(Difference between revisions)
Jump to: navigation, search
Line 14: Line 14:
(function () {
(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");
var elem = importScriptURI("https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js");

Revision as of 16:51, 20 January 2016

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 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();
        		    }
        		});
	        }
	    };
	}
})();

// 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