MediaWiki:DYK-nomination-wizard.js: Difference between revisions
Content deleted Content added
Refactored User:SD0001/DYK-helper.js for loading on a project using URL parameter |
update |
||
Line 1:
/**
*
* using [[mw:Snippets/Load JS and CSS by URL]]
*
*
* Automates:
* - Creation of the nomination page
Line 20:
$.ready
).then(function() {
if (mw.config.get('wgNamespaceNumber') === 0) {
$(mw.util.addPortletLink('p-cactions', '#', 'DYK', 'dyk-portlet', 'Nominate for DYK'))
.click(function () {
window.open('/wiki/Wikipedia:Did_you_know/Create_new_nomination?article=' + encodeURIComponent(Morebits.pageNameNorm), '_blank')
});▼
}
if (mw.config.get('wgPageName') !== 'Wikipedia:Did_you_know/Create_new_nomination' ||
mw.config.get('wgAction') !== 'view') return;
Line 44 ⟶ 50:
}
return charCount;
};
dyk.proseCharCount = function ($html) {
});
} else {
}
};
dyk.updateProseSize = function (form, article) {
if (!article) return;
// Speedy prose size calculation faster without API call if we were invoked from the article
try { // Just in case of issues with window.opener use
if (window.opener && opener.document.title === article + ' - Wikipedia') { // ideally should compare with MediaWiki:Pagetitle
var $html = $(opener.document.body).find('.mw-parser-output');
dyk.proseCharCount($html);
return;
}
} catch(e) { console.log(e); }
$('#dyk-prosesize').text('Prose size: calculating...').css('color', 'black');
new mw.Api().get({
Line 56 ⟶ 90:
}).then(function (json) {
if (article !== form.article.value) {
$('#dyk-prosesize').text('');
return; // input was changed, ignore this response
}
var $html = $(json.parse.text);
dyk.proseCharCount($html);
}).catch(function (code, error) {
▲ var charCount = 0, readable_text = '';
if (code === 'missingtitle') {
▲ $html.find('> p').each(function(i, el) {
$('#dyk-prosesize').text('Article does not exist!').css('color', 'red');
▲ charCount += dyk.proseCharCountInNode(el);
▲ readable_text += el.textContent.trim();
▲ });
▲ var wordCount = readable_text.split(/\s/).length;
▲ var prosesizediv = document.getElementById('dyk-prosesize');
▲ prosesizediv.textContent = 'Prose size: ' + wordCount + ' words, ' + charCount + ' characters';
▲ if (charCount < 1500) {
▲ prosesizediv.style.color = 'red';
▲ Morebits.quickForm.element.generateTooltip(prosesizediv, {
▲ tooltip: 'Article must have at least 1500 characters of prose to be eligible for DYK'
▲ });
} else {
$('#dyk-prosesize').text(''); // empty it
▲ prosesizediv.style.color = 'green';
console.error(error);
}
});
};
dyk.callback = function dykMainCallback(
var form = new Morebits.quickForm( dyk.evaluate );
Line 88 ⟶ 112:
type: 'div',
style: 'float: right; font-style: italic;',
id: 'dyk-prosesize'
});
Line 322 ⟶ 345:
.addClass('hlist')
.append(
$('<li>').append(Morebits.createHtml('[[en:WP:DYKRULES|DYK rules]]')),
$('<li>').append(Morebits.createHtml('[[en:User talk:SD0001/DYK-helper|Give feedback]]'))
).get()
});
Line 429 ⟶ 452:
var diff = curDate.getTime() - date.getTime();
if (date.toString() === 'Invalid date' || diff < 0) {
checkElem.textContent = 'Invalid date' + (diff < 0 ? '. Back from the future, are you?' : '');
checkElem.style.color = 'red';
return;
|