MediaWiki:Common.js/kiln.js

var api = new mw.Api, $wrapper, $buttons, $msgs, $map, i, $left, $right, $select, $button, curr = 1, width; function get_map(wave) { var params = { action: 'parse', text: '', prop: 'text', title: 'Fight Kiln map', disablepp: 'true' };       $buttons.children.each(function  { $(this).prop('disabled',true); }); $msgs.text('Loading...'); api.post(params).done(           function (response) {                $map.html(response.parse.text['*']);                $buttons.children.each(function  { $(this).prop('disabled',false); });                $msgs.text('');            }        ).fail(            function (_,err) {                $buttons.children.each(function  { $(this).prop('disabled',false); });                $msgs.text('There was an error loading the map');                console.log(err);            }        ); }   function check_buttons { $right.prop('disabled', false); $left.prop('disabled', false); if (curr === 1) { $left.prop('disabled', true); } else if (curr === 37) { $right.prop('disabled', true); }       $select.val(curr); }   width = $('#kilnmap table').width; $wrapper = $('#kilnmap') .css('width', (width+2) + 'px'); $buttons = $(' '); $msgs = $(' '); $map = $(' ').html($wrapper.html); $wrapper.html('') .append($buttons) .append($msgs) .append($map); $left = $('') .text('←') .addClass('button'); $left.click(function { curr--; get_map(curr); check_buttons; }); $right = $('') .text('→') .addClass('button'); $right.click(function { curr++; get_map(curr); check_buttons; }); $select = $(''); $select.change(function { var $val = parseInt($(this).val, 10); if (!isNaN($val) && $val <= 37 && $val >= 1) { curr = $val; get_map(curr); } else { $msgs.text('Error: please enter a number between 1 and 37.'); } check_buttons; }); $buttons.append($left) .append($select) .append($right); check_buttons; }(this.jQuery, this.mediaWiki));
 * (function ($, mw) {