MediaWiki:Common.js
From CruisersWiki
(Difference between revisions)
Line 1: | Line 1: | ||
- | // ------------------------------------------------------------------------------- | + | addOnloadHook(function () { |
- | // Force Preview JavaScript code - Start | + | // ------------------------------------------------------------------------------- |
- | // | + | // Force Preview JavaScript code - Start |
- | // To allow any group to bypass being forced to preview, | + | // |
- | // enter the group name in the permittedGroups array. | + | // To allow any group to bypass being forced to preview, |
- | // E.g. | + | // enter the group name in the permittedGroups array. |
- | // var permittedGroups = []; // force everyone | + | // E.g. |
- | // var permittedGroups = [ "user"]; // permit logged-in users | + | // var permittedGroups = []; // force everyone |
- | // var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat | + | // var permittedGroups = [ "user"]; // permit logged-in users |
- | // ------------------------------------------------------------------------------- | + | // var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat |
- | var permittedGroups = []; | + | // ------------------------------------------------------------------------------- |
- | + | var permittedGroups = ["sysop"]; | |
- | + | ||
- | + | ||
- | + | /* Array.prototype.intersects = function() { */ // avoid an assignment to Array.prototype due to a bug in Navionics webapi | |
- | + | var array_intersects = function() { | |
- | + | // -------------------------------------------------------- | |
- | + | // Returns true if any element in the argument array | |
- | + | // is the same as an element in this array | |
- | + | // -------------------------------------------------------- | |
- | + | if( !arguments.length ){ | |
- | + | return false; | |
- | + | } | |
- | + | var array2 = arguments[0]; | |
- | + | ||
- | + | var len1 = this.length; | |
- | + | var len2 = array2.length; | |
- | + | if ( len2 == 0 ){ | |
- | + | return false; | |
- | + | } | |
- | + | ||
- | + | for(var i=0; i<len1; i++){ | |
- | + | for(var j=0; j<len2; j++) { | |
- | + | if( this[i] === array2[j] ) { | |
+ | return true; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return false; | ||
+ | }; | ||
+ | |||
+ | if( wgAction != "edit") | ||
+ | return; | ||
+ | if( wgUserGroups === null) { | ||
+ | wgUserGroups = []; | ||
} | } | ||
- | + | /* if( wgUserGroups.intersects(permittedGroups) ) { */ | |
- | + | if( array_intersects.call(wgUserGroups, permittedGroups) ) { | |
- | + | return; | |
- | + | } | |
- | + | var saveButton = document.getElementById("wpSave"); | |
- | + | if( !saveButton ) | |
- | + | return; | |
- | + | saveButton.disabled = true; | |
- | + | saveButton.value = "Save page (use preview first)"; | |
- | + | saveButton.style.fontWeight = "normal"; | |
- | /* if( wgUserGroups.intersects(permittedGroups) ) { */ | + | document.getElementById("wpPreview").style.fontWeight = "bold"; |
- | + | }); | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | } | + | |
- | + | ||
- | + | ||
// ----------------------------------------------------- | // ----------------------------------------------------- | ||
// Force Preview JavaScript code - End | // Force Preview JavaScript code - End | ||
// --------------------------------------------- | // --------------------------------------------- | ||
- | |||
// define setZeroTimeout | // define setZeroTimeout | ||
Line 70: | Line 67: | ||
setTimeout(cb, 100); | setTimeout(cb, 100); | ||
}; | }; | ||
- | } else { | + | } else { |
(function() { // see http://dbaron.org/log/20100309-faster-timeouts | (function() { // see http://dbaron.org/log/20100309-faster-timeouts | ||
// Only add setZeroTimeout to the window object, and hide everything | // Only add setZeroTimeout to the window object, and hide everything | ||
Line 76: | Line 73: | ||
var timeouts = []; | var timeouts = []; | ||
var messageName = "zero-timeout-message"; | var messageName = "zero-timeout-message"; | ||
- | + | ||
// Like setTimeout, but only takes a function argument. There's | // Like setTimeout, but only takes a function argument. There's | ||
// no time argument (always zero) and no arguments (you have to | // no time argument (always zero) and no arguments (you have to | ||
Line 84: | Line 81: | ||
window.postMessage(messageName, "*"); | window.postMessage(messageName, "*"); | ||
} | } | ||
- | + | ||
function handleMessage(event) { | function handleMessage(event) { | ||
if (event.source == window && event.data == messageName) { | if (event.source == window && event.data == messageName) { | ||
Line 95: | Line 92: | ||
} | } | ||
window.addEventListener("message", handleMessage, true); | window.addEventListener("message", handleMessage, true); | ||
- | + | ||
// Add the one thing we want added to the window object. | // Add the one thing we want added to the window object. | ||
window.setZeroTimeout = setZeroTimeout; | window.setZeroTimeout = setZeroTimeout; | ||
Line 104: | Line 101: | ||
function wikiUri(page, ctype) { | function wikiUri(page, ctype) { | ||
- | + | return wgServer + wgScript + '?title=' + | |
- | + | encodeURIComponent(page.replace(/ /g,'_')).replace('%2F','/').replace('%3A',':') + | |
- | + | (ctype ? '&action=raw&ctype=' + ctype : ''); | |
} | } | ||
function wikiScript(page) { | function wikiScript(page) { | ||
- | + | return wikiUri(page, 'text/javascript'); | |
} | } | ||
function wikiCss(page) { | function wikiCss(page) { | ||
- | + | return wikiUri(page, 'text/css'); | |
} | } | ||
function loadScript(url, callback) { | function loadScript(url, callback) { | ||
addOnloadHook( function () { | addOnloadHook( function () { | ||
- | + | var elem = importScriptURI(url); | |
- | + | if (callback) { | |
- | + | if (elem) { | |
elem.onload = callback; | elem.onload = callback; | ||
} else { | } else { | ||
callback(); | callback(); | ||
} | } | ||
- | + | } | |
}); | }); | ||
} | } | ||
Line 136: | Line 133: | ||
var loadedCss = {}; // included-scripts tracker | var loadedCss = {}; // included-scripts tracker | ||
function loadCss(url, callback) { | function loadCss(url, callback) { | ||
- | + | if (loadedCss[url]) { | |
- | + | callback && callback(); | |
- | + | return null; | |
- | + | } | |
- | + | loadedCss[url] = true; | |
- | + | var elem = document.createElement('link'); | |
- | + | document.getElementsByTagName('head')[0].appendChild(elem); | |
- | + | elem.setAttribute('type','text/css'); | |
- | + | elem.setAttribute('rel','stylesheet'); | |
- | + | elem.setAttribute('href',url); | |
- | + | ||
- | + | if (callback) { | |
elem.onload = callback; | elem.onload = callback; | ||
- | + | } | |
- | + | return elem; | |
} | } | ||
Line 158: | Line 155: | ||
// load jQuery | // load jQuery | ||
- | + | ||
(function () { | (function () { | ||
- | + | ||
// modify addOnloadHook from wikibits.js | // modify addOnloadHook from wikibits.js | ||
- | + | var onloadFunctsNew = onloadFuncts; // create new queue | |
- | + | onloadFuncts = []; // clear old queue | |
- | + | var doneOnloadHookNew = false; | |
- | + | var addOnloadHookOld = addOnloadHook; | |
- | + | addOnloadHook = function (callback) { | |
- | + | var hookFunct = function () { // isolate ecach callback call | |
- | + | setZeroTimeout(callback); | |
- | + | } | |
- | + | // Allows add-on scripts to add onload functions | |
- | + | if(!doneOnloadHookNew) { | |
- | + | onloadFunctsNew[onloadFunctsNew.length] = hookFunct; | |
- | + | } else { | |
- | + | hookFunct(); // bug in MSIE script loading | |
- | + | } | |
- | + | }; | |
- | + | ||
- | + | // workaround for license badge src set to invalid host -- www.cruiserswiki.com: "http://www.cruiserswiki.com/images/f/fe/Creativecommons.png" | |
var licenseBadgeFix = function () { | var licenseBadgeFix = function () { | ||
console.log('licenseBadgeFix'); | console.log('licenseBadgeFix'); | ||
Line 185: | Line 182: | ||
}; | }; | ||
- | // fix for toolbar element is sometimes not available in edit mode | + | // fix for toolbar element is sometimes not available in edit mode |
var toolbarFix = function () { | var toolbarFix = function () { | ||
if ((window.wgAction == 'edit' || window.wgAction == 'submit') && $('#toolbar').length == 0) { | if ((window.wgAction == 'edit' || window.wgAction == 'submit') && $('#toolbar').length == 0) { | ||
Line 191: | Line 188: | ||
} | } | ||
}; | }; | ||
- | + | ||
- | + | ||
// rearrange toolbar buttons | // rearrange toolbar buttons | ||
- | + | ||
var editToolBarFix = function () { | var editToolBarFix = function () { | ||
- | mwEditButtons = []; | + | mwEditButtons = []; |
mwCustomEditButtons = []; | mwCustomEditButtons = []; | ||
- | + | ||
addButton("/skins/common/images/button_sig.png","Your signature with timestamp","--~~{{{dummy|}}}~~","","","mw-editbutton-signature"); | addButton("/skins/common/images/button_sig.png","Your signature with timestamp","--~~{{{dummy|}}}~~","","","mw-editbutton-signature"); | ||
addButton("/skins/common/images/button_bold.png","Bold text","\'\'\'","\'\'\'","Bold text","mw-editbutton-bold"); | addButton("/skins/common/images/button_bold.png","Bold text","\'\'\'","\'\'\'","Bold text","mw-editbutton-bold"); | ||
Line 210: | Line 206: | ||
addButton("/skins/common/images/button_nowiki.png","Ignore wiki formatting","\x3cnowiki\x3e","\x3c/nowiki\x3e","Insert non-formatted text here","mw-editbutton-nowiki"); | addButton("/skins/common/images/button_nowiki.png","Ignore wiki formatting","\x3cnowiki\x3e","\x3c/nowiki\x3e","Insert non-formatted text here","mw-editbutton-nowiki"); | ||
// addButton("/skins/common/images/button_hr.png","Horizontal line (use sparingly)","\n----\n","","","mw-editbutton-hr"); | // addButton("/skins/common/images/button_hr.png","Horizontal line (use sparingly)","\n----\n","","","mw-editbutton-hr"); | ||
- | + | ||
addButton("/images/7/70/Button_POI.png","Add POI","{{poi | lat= | lon=\n| type=\n| name=","\n| text=\n}}\n","","mw-editbutton-poi"); | addButton("/images/7/70/Button_POI.png","Add POI","{{poi | lat= | lon=\n| type=\n| name=","\n| text=\n}}\n","","mw-editbutton-poi"); | ||
}; | }; | ||
- | + | ||
- | + | // don't use loadScript here as it uses addOnloadHook | |
- | + | ||
- | + | var elem = importScript("MediaWiki:jquery-1.12.0.min.js"); | |
- | // | + | //~ var elem = importScriptURI("https://code.jquery.com/jquery-1.12.0.min.js"); |
- | + | if (!elem) { | |
- | + | return; | |
- | + | } | |
- | + | elem.onload = function () { // isolate ecach callback call | |
- | + | // console.log('onload jQuery ' + typeof jQuery + ' ' + typeof $+' document.readyState ' + document.readyState); | |
- | + | if (typeof jQuery === 'undefined') { | |
- | + | console.error('jQuery not loaded!'); | |
- | + | return; | |
- | + | } | |
- | + | $.ajaxSetup({ cache: true }); | |
- | + | ||
- | + | var jQueryReady = function(){ | |
- | + | console.log('document ready'); | |
- | + | ||
- | + | licenseBadgeFix(); | |
- | + | toolbarFix(); | |
- | + | // editToolBarFix(); | |
- | + | ||
- | + | // process OnloadHookNew | |
- | + | var f; | |
- | + | while (f = onloadFunctsNew.shift()) { | |
- | + | f(); | |
- | + | } | |
- | + | doneOnloadHookNew = true; | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
}; | }; | ||
- | + | ||
+ | if ( document.readyState ) { | ||
+ | var documentReady = function () { | ||
+ | console.log('document.readyState ' + document.readyState); | ||
+ | if (document.readyState == 'interactive' || document.readyState == 'complete') { | ||
+ | setZeroTimeout(jQueryReady); | ||
+ | } else { | ||
+ | setTimeout(documentReady, 100); | ||
+ | } | ||
+ | } | ||
+ | documentReady(); | ||
+ | } else { | ||
+ | $(jQueryReady); | ||
+ | } | ||
+ | }; | ||
})(); | })(); | ||
// chartlets | // chartlets | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
if ($('.cw-chartlet, .cw-chartlet-standalone').length > 0) { | if ($('.cw-chartlet, .cw-chartlet-standalone').length > 0) { | ||
loadWikiScript('MediaWiki:Chartlet.js'); | loadWikiScript('MediaWiki:Chartlet.js'); | ||
Line 268: | Line 264: | ||
}); | }); | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
if ($('.ol3-chartlet').length > 0) { | if ($('.ol3-chartlet').length > 0) { | ||
loadWikiScript('CruisersWiki:Ol3chartlet.js'); | loadWikiScript('CruisersWiki:Ol3chartlet.js'); | ||
Line 276: | Line 272: | ||
// add toggle poi sample link display to toolbox | // add toggle poi sample link display to toolbox | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
if ($('.cw-poi').length > 0) { | if ($('.cw-poi').length > 0) { | ||
var $a = $('<a style="cursor:pointer">Show POI links</a>') | var $a = $('<a style="cursor:pointer">Show POI links</a>') | ||
Line 288: | Line 284: | ||
// add kml download link to toolbox | // add kml download link to toolbox | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
if ($('.h-geo').length > 0) { | if ($('.h-geo').length > 0) { | ||
loadWikiScript('MediaWiki:GetKml.js'); | loadWikiScript('MediaWiki:GetKml.js'); | ||
Line 296: | Line 292: | ||
// remove broken fckeditor | // remove broken fckeditor | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
$('script[src*="fckeditor"]').remove(); | $('script[src*="fckeditor"]').remove(); | ||
$('#fckTools').remove(); | $('#fckTools').remove(); | ||
Line 303: | Line 299: | ||
// rewrite image links' titles | // rewrite image links' titles | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
$('a.image>img[alt]').each(function(i) { | $('a.image>img[alt]').each(function(i) { | ||
var $this = $(this); | var $this = $(this); | ||
Line 313: | Line 309: | ||
// after [[w:User:Rezonansowy/SimpleLightbox]] | // after [[w:User:Rezonansowy/SimpleLightbox]] | ||
- | + | ||
- | addOnloadHook(function () { | + | addOnloadHook(function () { |
// $('body').append( | // $('body').append( | ||
- | // '<div id="lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + | + | // '<div id="lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + |
// '<span style="display: inline-block; height: 100%; vertical-align: middle;" ></span>' + // http://stackoverflow.com/a/7310398 | // '<span style="display: inline-block; height: 100%; vertical-align: middle;" ></span>' + // http://stackoverflow.com/a/7310398 | ||
// '<img style="display:none;background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />' + | // '<img style="display:none;background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />' + | ||
Line 329: | Line 325: | ||
$('body').append( | $('body').append( | ||
- | '<div id="cw-lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + | + | '<div id="cw-lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + |
'</div>' | '</div>' | ||
); | ); | ||
Line 338: | Line 334: | ||
var thumb = src.match(/^(.*)(\/thumb)(.*)(\/[^\/]*)$/,''); | var thumb = src.match(/^(.*)(\/thumb)(.*)(\/[^\/]*)$/,''); | ||
if (thumb) { | if (thumb) { | ||
- | + | src = thumb[1] + thumb[3]; | |
} else if (src.match("/Special:Redirect/") ) { | } else if (src.match("/Special:Redirect/") ) { | ||
src = src.replace(/(\?width=.*)$/,''); | src = src.replace(/(\?width=.*)$/,''); | ||
Line 349: | Line 345: | ||
// $(this).fadeIn('fast'); | // $(this).fadeIn('fast'); | ||
// }); | // }); | ||
- | + | ||
$('#cw-lightbox') | $('#cw-lightbox') | ||
// .html('<img src="'+src+'" style="background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />') | // .html('<img src="'+src+'" style="background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />') | ||
Line 369: | Line 365: | ||
function addCustomEditButton (imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) { | function addCustomEditButton (imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) { | ||
mwCustomEditButtons[mwCustomEditButtons.length] = | mwCustomEditButtons[mwCustomEditButtons.length] = | ||
- | + | {"imageId": imageId, | |
- | + | "imageFile": imageFile, | |
- | + | "speedTip": speedTip, | |
- | + | "tagOpen": tagOpen, | |
- | + | "tagClose": tagClose, | |
- | + | "sampleText": sampleText}; | |
} | } | ||
Revision as of 17:31, 24 February 2016
addOnloadHook(function () { // ------------------------------------------------------------------------------- // Force Preview JavaScript code - Start // // To allow any group to bypass being forced to preview, // enter the group name in the permittedGroups array. // E.g. // var permittedGroups = []; // force everyone // var permittedGroups = [ "user"]; // permit logged-in users // var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat // ------------------------------------------------------------------------------- var permittedGroups = ["sysop"]; /* Array.prototype.intersects = function() { */ // avoid an assignment to Array.prototype due to a bug in Navionics webapi var array_intersects = function() { // -------------------------------------------------------- // Returns true if any element in the argument array // is the same as an element in this array // -------------------------------------------------------- if( !arguments.length ){ return false; } var array2 = arguments[0]; var len1 = this.length; var len2 = array2.length; if ( len2 == 0 ){ return false; } for(var i=0; i<len1; i++){ for(var j=0; j<len2; j++) { if( this[i] === array2[j] ) { return true; } } } return false; }; if( wgAction != "edit") return; if( wgUserGroups === null) { wgUserGroups = []; } /* if( wgUserGroups.intersects(permittedGroups) ) { */ if( array_intersects.call(wgUserGroups, permittedGroups) ) { return; } var saveButton = document.getElementById("wpSave"); if( !saveButton ) return; saveButton.disabled = true; saveButton.value = "Save page (use preview first)"; saveButton.style.fontWeight = "normal"; document.getElementById("wpPreview").style.fontWeight = "bold"; }); // ----------------------------------------------------- // Force Preview JavaScript code - End // --------------------------------------------- // define setZeroTimeout if (! window.postMessage) { window.setZeroTimeout = function (cb) { setTimeout(cb, 100); }; } else { (function() { // see http://dbaron.org/log/20100309-faster-timeouts // Only add setZeroTimeout to the window object, and hide everything // else in a closure. var timeouts = []; var messageName = "zero-timeout-message"; // Like setTimeout, but only takes a function argument. There's // no time argument (always zero) and no arguments (you have to // use a closure). function setZeroTimeout(fn) { timeouts.push(fn); window.postMessage(messageName, "*"); } function handleMessage(event) { if (event.source == window && event.data == messageName) { event.stopPropagation(); if (timeouts.length > 0) { var fn = timeouts.shift(); fn(); } } } window.addEventListener("message", handleMessage, true); // Add the one thing we want added to the window object. window.setZeroTimeout = setZeroTimeout; })(); } // utility functions function wikiUri(page, ctype) { return wgServer + wgScript + '?title=' + encodeURIComponent(page.replace(/ /g,'_')).replace('%2F','/').replace('%3A',':') + (ctype ? '&action=raw&ctype=' + ctype : ''); } function wikiScript(page) { return wikiUri(page, 'text/javascript'); } function wikiCss(page) { return wikiUri(page, 'text/css'); } function loadScript(url, callback) { addOnloadHook( function () { var elem = importScriptURI(url); if (callback) { if (elem) { elem.onload = callback; } else { callback(); } } }); } function loadWikiScript(page, callback) { loadScript(wikiScript(page), callback); } var loadedCss = {}; // included-scripts tracker function loadCss(url, callback) { if (loadedCss[url]) { callback && callback(); return null; } loadedCss[url] = true; var elem = document.createElement('link'); document.getElementsByTagName('head')[0].appendChild(elem); elem.setAttribute('type','text/css'); elem.setAttribute('rel','stylesheet'); elem.setAttribute('href',url); if (callback) { elem.onload = callback; } return elem; } function loadWikiCss(page, callback) { loadCss(wikiCss(page), callback); } // load jQuery (function () { // modify addOnloadHook from wikibits.js var onloadFunctsNew = onloadFuncts; // create new queue onloadFuncts = []; // clear old queue var doneOnloadHookNew = false; var addOnloadHookOld = addOnloadHook; addOnloadHook = function (callback) { var hookFunct = function () { // isolate ecach callback call setZeroTimeout(callback); } // Allows add-on scripts to add onload functions if(!doneOnloadHookNew) { onloadFunctsNew[onloadFunctsNew.length] = hookFunct; } else { hookFunct(); // bug in MSIE script loading } }; // workaround for license badge src set to invalid host -- www.cruiserswiki.com: "http://www.cruiserswiki.com/images/f/fe/Creativecommons.png" var licenseBadgeFix = function () { console.log('licenseBadgeFix'); $('img[src*="reativecommons.png"]').attr('src', '/images/f/fe/Creativecommons.png' ); }; // fix for toolbar element is sometimes not available in edit mode var toolbarFix = function () { if ((window.wgAction == 'edit' || window.wgAction == 'submit') && $('#toolbar').length == 0) { $('<div id="toolbar">').insertBefore($('#editform')); } }; // rearrange toolbar buttons var editToolBarFix = function () { mwEditButtons = []; mwCustomEditButtons = []; addButton("/skins/common/images/button_sig.png","Your signature with timestamp","--~~{{{dummy|}}}~~","","","mw-editbutton-signature"); addButton("/skins/common/images/button_bold.png","Bold text","\'\'\'","\'\'\'","Bold text","mw-editbutton-bold"); addButton("/skins/common/images/button_italic.png","Italic text","\'\'","\'\'","Italic text","mw-editbutton-italic"); addButton("/skins/common/images/button_link.png","Internal link","[[","]]","Link title","mw-editbutton-link"); addButton("/skins/common/images/button_extlink.png","External link (remember http:// prefix)","[","]","http://www.example.com link title","mw-editbutton-extlink"); addButton("/skins/common/images/button_headline.png","Level 2 headline","\n== "," ==\n","Headline text","mw-editbutton-headline"); addButton("/skins/common/images/button_image.png","Embedded file","[[File:","]]","Example.jpg","mw-editbutton-image"); addButton("/skins/common/images/button_media.png","File link","[[Media:","]]","Example.ogg","mw-editbutton-media"); // addButton("/skins/common/images/button_math.png","Mathematical formula (LaTeX)","\x3cmath\x3e","\x3c/math\x3e","Insert formula here","mw-editbutton-math"); addButton("/skins/common/images/button_nowiki.png","Ignore wiki formatting","\x3cnowiki\x3e","\x3c/nowiki\x3e","Insert non-formatted text here","mw-editbutton-nowiki"); // addButton("/skins/common/images/button_hr.png","Horizontal line (use sparingly)","\n----\n","","","mw-editbutton-hr"); addButton("/images/7/70/Button_POI.png","Add POI","{{poi | lat= | lon=\n| type=\n| name=","\n| text=\n}}\n","","mw-editbutton-poi"); }; // don't use loadScript here as it uses addOnloadHook var elem = importScript("MediaWiki:jquery-1.12.0.min.js"); //~ var elem = importScriptURI("https://code.jquery.com/jquery-1.12.0.min.js"); if (!elem) { return; } elem.onload = function () { // isolate ecach callback call // console.log('onload jQuery ' + typeof jQuery + ' ' + typeof $+' document.readyState ' + document.readyState); if (typeof jQuery === 'undefined') { console.error('jQuery not loaded!'); return; } $.ajaxSetup({ cache: true }); var jQueryReady = function(){ console.log('document ready'); licenseBadgeFix(); toolbarFix(); // editToolBarFix(); // process OnloadHookNew var f; while (f = onloadFunctsNew.shift()) { f(); } doneOnloadHookNew = true; }; if ( document.readyState ) { var documentReady = function () { console.log('document.readyState ' + document.readyState); if (document.readyState == 'interactive' || document.readyState == 'complete') { setZeroTimeout(jQueryReady); } else { setTimeout(documentReady, 100); } } documentReady(); } else { $(jQueryReady); } }; })(); // chartlets addOnloadHook(function () { if ($('.cw-chartlet, .cw-chartlet-standalone').length > 0) { loadWikiScript('MediaWiki:Chartlet.js'); } }); addOnloadHook(function () { if ($('.ol3-chartlet').length > 0) { loadWikiScript('CruisersWiki:Ol3chartlet.js'); } }); // add toggle poi sample link display to toolbox addOnloadHook(function () { if ($('.cw-poi').length > 0) { var $a = $('<a style="cursor:pointer">Show POI links</a>') .click(function () { $('body').toggleClass('cw-poi-sample-link-dislay'); }); $('#p-tb ul').append($('<li>').append($a)); } }); // add kml download link to toolbox addOnloadHook(function () { if ($('.h-geo').length > 0) { loadWikiScript('MediaWiki:GetKml.js'); } }); // remove broken fckeditor addOnloadHook(function () { $('script[src*="fckeditor"]').remove(); $('#fckTools').remove(); }); // rewrite image links' titles addOnloadHook(function () { $('a.image>img[alt]').each(function(i) { var $this = $(this); var alt = $this.attr('alt'); $this.attr('title', alt); // console.log(''+i+' '+alt); }); }); // after [[w:User:Rezonansowy/SimpleLightbox]] addOnloadHook(function () { // $('body').append( // '<div id="lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + // '<span style="display: inline-block; height: 100%; vertical-align: middle;" ></span>' + // http://stackoverflow.com/a/7310398 // '<img style="display:none;background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />' + // '</div>' // ); // $('#lightbox').on('click', function() { // $(this).fadeOut('fast', function () { // $('#lightbox img').hide(); // }); // }); // $('body').append('<div id="lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999"></div>'); $('body').append( '<div id="cw-lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + '</div>' ); $('a.image').click(function(e) { e.preventDefault(); var src = $(this).find('img').attr('src'); var thumb = src.match(/^(.*)(\/thumb)(.*)(\/[^\/]*)$/,''); if (thumb) { src = thumb[1] + thumb[3]; } else if (src.match("/Special:Redirect/") ) { src = src.replace(/(\?width=.*)$/,''); } // $('#lightbox').show(); // $('#lightbox img') // .attr('src', src) // .load(function () { // $(this).fadeIn('fast'); // }); $('#cw-lightbox') // .html('<img src="'+src+'" style="background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />') // .css('line-height', $(window).height()+'px') .html( '<span style="display: inline-block; height: 100%; vertical-align: middle;" ></span>' + // http://stackoverflow.com/a/7310398 '<img style="background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;cursor:pointer;"' + 'src="' + src + '" />' ) .fadeIn('fast') .on('click', function() { $(this).fadeOut('fast'); }); }); }); // custom edit toolbar buttons function addCustomEditButton (imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) { mwCustomEditButtons[mwCustomEditButtons.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"); if (wgUserName == 'Vadim') { importScript('User:Vadim/common.js'); }