User:1234qwer1234qwer4/holiday.js

/** * Script for holiday wishes (β) * Rip-off from SD0001's BDCS (User:SD0001/BDCS.js) * Rip-off from Twinkle's Welcome module (MediaWiki:Gadget-friendlywelcome.js) */

// $.when(	mw.loader.using('ext.gadget.morebits'), 	$.ready ).then(function {

if (!mw.config.get('wgRelevantUserName')) { return; }

var Holiday = {}; window.Holiday = Holiday;

Holiday.advert = ' (holiday.js)';

var li = mw.util.addPortletLink('p-cactions', '#', 'Holiday', 'p-holiday', 'Wish user'); li.addEventListener('click', function {	Holiday.callback(mw.config.get('wgRelevantUserName')); });

Holiday.callback = function (uid) { if (uid === mw.config.get('wgUserName') && !confirm('Are you really sure you want to wish yourself?...')) { return; }	Morebits.wiki.api.setApiUserAgent('w:User:1234qwer1234qwer4/holiday');

var Window = new Morebits.simpleWindow(600, 420); Window.setTitle('Wish user');

var form = new Morebits.quickForm(Holiday.callback.evaluate);

form.append({		type: 'select',		name: 'type',		label: 'Type of holiday: ',		event: Holiday.populateHolidayList,		list: [			{ type: 'option', value: 'seasonalgreetings', label: 'Seasonal greetings (inclusive)', selected: true },			{ type: 'option', value: 'christmas', label: 'Merry Christmas' },			{ type: 'option', value: 'newyear', label: 'Happy New Year' },			{ type: 'option', value: 'hanukkah', label: 'Happy Hanukkah' },			{ type: 'option', value: 'passover', label: 'Happy Passover' },			{ type: 'option', value: 'halloween', label: 'Happy Halloween' }		].concat( window.Holiday_CustomTemplates && window.Holiday_CustomTemplates.length ? [ { type: 'option', value: 'custom', label: 'Custom templates' } ] : [] )	});

form.append({		type: 'div',		id: 'HolidayWorkArea'	});

form.append({		type: 'input',		name: 'heading',		label: 'Section heading: ',		value: 'Happy holidays!'	});

var previewlink = document.createElement('a'); $(previewlink).click(function {		Holiday.callbacks.preview(result); // |result| is defined below	}); previewlink.style.cursor = 'pointer'; previewlink.textContent = 'Preview'; form.append({ type: 'div', id: 'Holidaypreview', label: [ previewlink ] }); form.append({ type: 'div', id: 'Holiday-previewbox', style: 'display: none' });

form.append({ type: 'submit' });

var result = form.render; Window.setContent(result); Window.display; result.previewer = new Morebits.wiki.preview($('#Holiday-previewbox').last[0]);

// initialize the Holiday list var evt = document.createEvent('Event'); evt.initEvent('change', true, true); result.type.dispatchEvent(evt); };

Holiday.populateHolidayList = function(e) { var type = e.target.value; var form = e.target.form; var container = new Morebits.quickForm.element({ type: 'fragment' });

var appendTemplates = function(list) { container.append({			type: 'radio',			name: 'template',			list: list.map(function(obj) { return { value: obj, label: '' }			})		});	};

switch (type) { case 'seasonalgreetings': form.heading.value = 'Seasonal greetings!'; appendTemplates([				'Happy holidays',				'Scenic Christmas Peace',				'Season\'s Greetings',				'Yuletide'			]); break;

case 'christmas': form.heading.value = 'Merry Christmas!'; appendTemplates([				'Christmas Peace',				'Happy holidays',				'Multi-language Season\'s Greetings',				'Seasonal Greetings',				'The 12 Days of Wikipedia',				'Xmas2',				'Xmas3',				'Xmas4',				'Xmas5'			]); break;

case 'newyear': form.heading.value = 'Happy New Year!'; appendTemplates([				'Happy New Year',				'Happy New Year 2',				'Happy New Year 2016',				'Happy New Year 2020',				'Happy New Year Wiki Friends',				'Happy New Year elves',				'Happy New Year fireworks',				'Happy New Year fireworks (static)',				'Happy New Year snowman',				'New Year 1',				'Vivons joyeulx',				'Happy Sinhala & Tamil New Year',				'Hindu new year'			]); break;

case 'hanukkah': form.heading.value = 'Happy Hanukkah!'; appendTemplates([				'Potato pancakes'			]); break;

case 'passover': form.heading.value = 'Happy Passover!'; appendTemplates([				'Happy Passover'			]); break;

case 'halloween': form.heading.value = 'Happy Halloween!'; appendTemplates([				'Happy Halloween'			]); break;

case 'custom': form.heading.value = ''; appendTemplates(window.Holiday_CustomTemplates); break;

default: container.append({ type: 'div', label: 'Holiday.populateHolidayList: something went wrong' }); break; }

var rendered = container.render; $('#HolidayWorkArea').empty.append(rendered);

var firstRadio = form.template[0] || form.template; firstRadio.checked = true; };

Holiday.getTemplateWikitext = function(template, heading) { return heading?'==' + heading + '==\n':'\n'; };

Holiday.callbacks = { preview: function(form) { form.previewer.beginRender(Holiday.getTemplateWikitext(form.getChecked('template'), form.heading.value), 'User talk:' + mw.config.get('wgRelevantUserName')); },	main: function(pageobj) { var params = pageobj.getCallbackParameters; var text = pageobj.getPageText;

var HolidayText = Holiday.getTemplateWikitext(params.value, params.heading);

text += '\n' + HolidayText;

summaryText = (params.heading ? ('/* ' + params.heading + ' */ ') : '') + 'new section'; pageobj.setPageText(text); pageobj.setEditSummary(summaryText + Holiday.advert); pageobj.setCreateOption('nocreate'); pageobj.save; } };

Holiday.callback.evaluate = function HolidayEvaluate(e) { var form = e.target;

var params = { value: form.getChecked('template'), heading: form.heading.value };

Morebits.simpleWindow.setButtonsEnabled(false); Morebits.status.init(form);

var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName'); Morebits.wiki.actionCompleted.redirect = userTalkPage; Morebits.wiki.actionCompleted.notice = 'Wishing complete, reloading talk page in a few seconds';

var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification'); wikipedia_page.setFollowRedirect(true); wikipedia_page.setCallbackParameters(params); wikipedia_page.load(Holiday.callbacks.main); };

}); //