MediaWiki:Common.js: Difference between revisions

From Imperivm Romanvm
Jump to navigation Jump to search
m (Use DateInput)
No edit summary
Line 2: Line 2:


$(function() {
$(function() {
let dateInput = new mw.widgets.DateInputWidget({id: 'date'});
var dateInput = new mw.widgets.DateInputWidget({id: 'date'});
$('#ir-roman-date-converter').append(dateInput.$element);
$('#ir-roman-date-converter').append(dateInput.$element);
$('#ir-roman-date-converter').append('<div class=\"mw-inputbox-centered\"> \
$('#ir-roman-date-converter').append('<div class=\"mw-inputbox-centered\"> \
Line 11: Line 11:
                 const resultDiv = document.getElementById(\"result\"); \
                 const resultDiv = document.getElementById(\"result\"); \
                 const api = new mw.Api(); \
                 const api = new mw.Api(); \
                 let date = $(#date).getValue(); \
                 let date = $(\'#date\').getValue(); \
                 api.get({ \
                 api.get({ \
                     action: \'expandtemplates\', \
                     action: \'expandtemplates\', \

Revision as of 10:11, 29 June 2022

/* Any JavaScript here will be loaded for all users on every page load. */

$(function() {
	var dateInput = new mw.widgets.DateInputWidget({id: 'date'});
	$('#ir-roman-date-converter').append(dateInput.$element);
	$('#ir-roman-date-converter').append('<div class=\"mw-inputbox-centered\"> \
        <input type=\"submit\" onclick=\"submit()\" class=\"mw-ui-button mw-ui-progressive webfonts-changed\" value=\"Convert Date\"> \
        <div id=\"result\"></div> \
        <script> \
            function submit(){ \
                const resultDiv = document.getElementById(\"result\"); \
                const api = new mw.Api(); \
                let date = $(\'#date\').getValue(); \
                api.get({ \
                    action: \'expandtemplates\', \
                    prop: \'wikitext\', \
                    text:\'{{#invoke:Roman Date| main | \' + date + \' }}\' \
                }).done( function ( data ) { \
                    resultDiv.innerHTML = data.expandtemplates.wikitext; \
                } ); \
            } \
        </script> \
    </div>');
});