Jump to content

User:Kangaroopower/ajaxMove.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/**
 * Ajax Move
 * 
 * Creates a form to ajax move pages
 * 
 * @author Kangaroopower
 * @credits Ale_jrb (UI)
 *
 * From: [[User:Kangaroopower/Scripts]]
 *
 * To Do (Since this now uses a real dialog, the following are relatively easy to do): 
 * - More options
 * - Undo
 *
 */
$(function () {

	window.ajaxMove = {
		version: '1.93.1',
		active: false,

		/* Create the pop-up form */
		createPopUpForm: function () {
			if (ajaxMove.active) return;
			var popupHTML = '<div id="ajaxMoveUI"style="position: absolute; z-index: 9999999; left: 250px; top: 175px; width: 415px; height: 130px; background-color: white; padding: 3px; border-width: 1px; border-style: solid; border-color: #AAAAAA;  border-image: initial; overflow: visible; text-align: left; font-size: 10px;"><div><div style="width: 411px; border-bottom: 1px solid #aaaaaa; padding: 2px; font-weight: bold;">Ajax Move Module<span style="float:right"><a id="mv-close" href="#"><img src="http://upload.wikimedia.org/wikipedia/commons/b/b6/Chrome_close_button.png"/></a></span></div><div style="font-size: 11px; margin-left: 7px; margin-top: 8px; padding: 0px;">Move To: <input id="mv-new"style="margin-left: 9px; font-size: 11px; width: 300px;"type="text"/></div><div style="font-size: 11px; margin-left: 7px; margin-top: 8px; padding: 0px;">Reason: <input id="mv-why"style="margin-left: 13px; font-size: 11px; width: 300px;"type="text"/></div><div id="mv-error" ></div><div style="margin-top: 13px; text-align:center; font-size: 11px; ">-- <a href="#"onclick="ajaxMove.movePage();">Move</a> --</div></div></div>';
			$('body').append(popupHTML);
			ajaxMove.active = true;
			$('#mv-close').click(function() {
				ajaxMove.active = false;
				$( '#ajaxMoveUI' ).remove()
			});
			$('#ajaxMoveUI').draggable();
		},

		movePage: function (token) {
			var newpage = $('#mv-new').val(),
				summary = newpage + " [[User:Kangaroopower/ajaxMove.js|(Ajax Move)]]";
			if (newpage === "") {
				$('#mv-error').html('Please enter the destination for the move.');
			} else {
				Flash('move').load({targ: mw.config.get('wgPageName'), to: encodeURIComponent(newpage), summary: encodeURIComponent(summary), mTalk: true, mSub: true}).wait(function (data) {
					if (data.error) $('#mv-error').html('Error:' + data.error.info + '. Please see <a href="https://www.mediawiki.org/wiki/API:Move#Possible_errors">here</a> for more info');
					else location.reload(); 
				}).run();
			}
		}
	};
	
	$(document).ready(function () {
		if (typeof mw.loader.moduleRegistry.Flash === "undefined") {
			mw.loader.implement('Flash', [
				mw.util.wikiScript('index') + '?title=User:Kangaroopower/Flash.js&action=raw&ctype=text/javascript'
			], {}, {});
		}
		
		mw.loader.using(['Flash'], function () {
			startAJMove();
		});
		
		function startAJMove () {
			if ($.inArray( mw.config.get('wgUserGroups'), "autoconfirmed" ) && document.getElementById('ca-move') && mw.config.get('wgCanonicalNamespace') !== "Special") {
				mw.util.addPortletLink('p-cactions', 'javascript:ajaxMove.createPopUpForm();', "Ajax Move", "ca-ajaxMove", "Ajax Move");
			}
		}
	});
});