MediaWiki:Common.js/w/Wikibooks:Dialog
Appearance
| This is the JavaScript for all users. You can propose changes on the discussion page or at the proposals reading room. Errors made here can disrupt Wikibooks. You can test changes in your personal JavaScript first. Due to caching, changes can take up to 31 days before propagating to all users. |
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
/* For [[{{evalx|(get-substring (get-arg 3) (+ 1 (length (get-arg 2))))|{{dialog/js prefix}}|{{PAGENAME}}}}]]. See [[Special:WhatLinksHere/{{#titleparts:{{PAGENAME}}||2}}]]. [[Category:Dialog javascript pages|Dialog]] */
if (location.search) {
function converterVersion() { return '0.3 (2015-11-06)'; }
function showHere(content) {
$('div.wikidialog-url-converter').replaceWith(
'<div class="wikidialog-url-converter wikidialog-rewritten">' + content + '</div>');
}
function wikidialogShow(callback) {
if (('wikidialog' in window) && ('show' in window.wikidialog)) {
window.wikidialog.show();
if (callback) callback();
}
else $.getScript( // [[MediaWiki:Gadget-wikidialog.js]]
mw.config.get('wgScript') + '?title=' + mw.util.wikiUrlencode('MediaWiki:Gadget-wikidialog.js') +
'&action=raw&ctype=text/javascript',
function () {
if (callback) callback();
}
);
}
function safeHtml(s) { // just being safe; note, ampersands would mess up formatting
return s.replace(/\</g,'').replace(/\>/g,'');
};
function getQueryParams() {
var q = location.search.substring(1).split(/[&]/);
var result = {};
for (var k=0; k<q.length; k++) {
var j = q[k].search('=');
if (j > 0) result[safeHtml(q[k].substring(0,j))] = safeHtml(q[k].substring(j+1));
}
return result;
}
var queryParams = getQueryParams();
if (! ('dialog-action' in queryParams)) showHere('Missing query <tt>dialog-action</tt> parameter.');
else {
//
// assemble html
//
var fields = '';
var button = '<span class="wikidialog-button wikidialog-delegable">action=' + queryParams['dialog-action'] +
'&label=' + queryParams['dialog-action']; // [[Template:Dialog/button]]
var summary = '';
for (var p in queryParams) {
if (p == 'dialog-action') continue;
if (p == 'dialog-confirm') continue;
if (p == 'wikidialogrolledback') continue;
if (p == 'wikidialogid') continue;
fields += '<span class="wikidialog-textarea wikidialog-hidden" id="wikidialog-button-local-field-' +
p + '">cols=&rows=&' + queryParams[p] + '</span>'; // [[Template:dialog/textarea]]
button += '&' + p + ':button-local-field-' + p;
summary += '\n<hr></hr>\n<p><b>' + p + ':</b></p>\n<p><code>' + queryParams[p] + '</code></p>';
}
button += '&</span>' + summary + '<hr></hr><hr></hr>\nUrl converter version ' + converterVersion();
if (! (('dialog-confirm' in queryParams) || ('wikidialogrolledback' in queryParams)))
button = '<div style="display:none;">' + button + '</div>';
var s = button + fields;
//
// deploy
//
showHere(s);
wikidialogShow(function () {
if (! ('dialog-confirm' in queryParams) || ('wikidialogrolledback' in queryParams))
$("input.wikidialog-button").click();
else if ('dialog-confirm' in queryParams)
$.getScript( // [[MediaWiki:Dialog/receive]]
mw.config.get('wgScript') + '?title=' + mw.util.wikiUrlencode('MediaWiki:Dialog/receive') +
'&action=raw&ctype=text/javascript',
function () { window.wikidialog.purelySelfContained(); }
);
});
}
}