User:Lil' Miss Rarity/ToDo.js

/* main functions */ // create containing object ToDo = {}; ToDo.width = 400; ToDo.height = 300; ToDo.thingsToDoPage = "To do"; // name of subpage ToDo.pageName = Object.keys(mw.config.get("wgNamespaceIds"))[4] + ":" + encodeURIComponent(mw.config.get("wgUserName").replace(/ /g,"_")) + "/" + encodeURIComponent(ToDo.thingsToDoPage.replace(/ /g,"_")); // url encoded url of page name // save ToDo.save = function { $.ajax({		url: mw.util.wikiScript( 'api' ),		data: {			format: 'json',			action: 'edit',			title: ToDo.pageName,			text: $("nav#to-do-editor textarea").val,			token: mw.user.tokens.get("editToken")		},		dataType: 'json',		type: 'POST',		success: function( data ) {			if ( data && data.edit && data.edit.result == 'Success' ) {				ToDo.close; // close editor if done			} else if ( data && data.error ) {				alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );			} else {				alert( 'Error: Unknown result from API.' );			}		},		error: function( xhr ) {			alert( 'Error: Request failed.' );		}	}); } // load new content and show menu ToDo.update = function { $.getJSON("/api.php?action=query&format=json&prop=revisions&titles=" + ToDo.pageName + "&rvprop=content&cb=" + new Date.getTime, function(data) {		var pageData = data.query.pages;		for (var pageid in pageData) {			var pageContent = pageData[pageid].revisions[0]["*"]; // updated page content			$("nav#to-do-editor textarea").val(pageContent);			$("nav#to-do-editor").show;		}	}); } // close interface ToDo.close = function { $("nav#to-do-editor").hide; } /* markup and triggering function */ // add interface markup $("#WikiaArticle").append(	'\n' +		'\t Save To-do List ' +		'\t ' +		'\t' +	' ' ); // add trigger to bottom wiki menu $(".wikia-bar").last.find(".tools").append('To-do List'); // save button $("nav#to-do-editor #to-do-editor-save").click(function {	ToDo.save; }); // open to-do list editor $(".wikia-bar").last.find("#to-do-editor-trigger").click(function(event) {	event.preventDefault;	if ($("nav#to-do-editor").css("display") == "none") {		ToDo.update;	} }); // close interface trigger $("nav#to-do-editor #to-do-editor-close").click(function {	ToDo.close; }); /* css */ mw.util.addCSS(	'nav#to-do-editor {\n' +		'\tz-index: 999999;\n' +		'\twidth: ' + ToDo.width + 'px;\n' +		'\theight: ' + ToDo.height + 'px;\n' +		'\tposition: fixed;\n' +		'\tleft: ' + ((screen.availWidth - ToDo.width) / 2) + 'px;\n' +		'\ttop: ' + ((screen.availHeight - ToDo.height - 40) / 2) + 'px;\n' +		'\tpadding: 2px;\n' +		'\tbackground: #fafafa;\n' +		'\tborder: 1px solid #cccccc;\n' +	'}\n' +	'nav#to-do-editor textarea {\n' +		'\twidth: ' + (ToDo.width - 4) + 'px;\n' +		'\theight: 230px;\n' +		'\tresize: none;\n' +	'}\n' +	'nav#to-do-editor #to-do-editor-close {\n' +		'\tdisplay: inline-block;\n' +		'\twidth: 12px;\n' +		'\theight: 12px;\n' +		'\tfloat: right;\n' +		'\tbackground: url(\'http://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Emblem-unreadable.svg/14px-Emblem-unreadable.svg.png\') center no-repeat;\n' +		'\tborder: 1px solid #cccccc;\n' +		'\tborder-radius: 3px;\n' + '\t-moz-border-radius: 3px;\n' + '\t-webkit-border-radius: 3px;\n' + '\tcursor: hand;\n' + '\tcursor: pointer;\n' + '}' );