MediaWiki:Common.js: Difference between revisions
From Artifacts of Capitalism
No edit summary |
No edit summary |
||
| Line 57: | Line 57: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
$('a.external').attr('target', '_blank'); | $('a.external').attr('target', '_blank'); | ||
}); | |||
mw.loader.using( 'mediawiki.util', function () { | |||
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'CreateAccount' ) { | |||
$( function () { | |||
const form = $('#mw-createaccount-form'); | |||
if (!form.length) return; | |||
const realNameDiv = form.find('#wpRealName').closest('.form-group, .mw-input, p'); | |||
if (!realNameDiv.length) return; | |||
// --- Affiliation field --- | |||
const affField = $(` | |||
<div class="form-group mw-input"> | |||
<label for="wpAffiliation">Affiliation</label> | |||
<input type="text" id="wpAffiliation" name="wpAffiliation" | |||
required class="form-control mw-ui-input"/> | |||
</div> | |||
`); | |||
// --- Institutional Email field --- | |||
const instField = $(` | |||
<div class="form-group mw-input"> | |||
<label for="wpInstitutionalEmail">Institutional Email</label> | |||
<input type="email" id="wpInstitutionalEmail" name="wpInstitutionalEmail" | |||
required class="form-control mw-ui-input"/> | |||
</div> | |||
`); | |||
// Insert right after Real Name | |||
realNameDiv.after( affField, instField ); | |||
}); | |||
} | |||
}); | }); | ||
Revision as of 15:56, 11 November 2025
// Ensure viewport meta exists (iOS layout fix)
(function () {
if (!document.querySelector('meta[name="viewport"]')) {
var m = document.createElement('meta');
m.name = 'viewport';
m.content = 'width=device-width, initial-scale=1, shrink-to-fit=no';
document.head.appendChild(m);
}
})();
mw.hook('wikipage.content').add(function ($c) {
var groups = mw.config.get('wgUserGroups') || [];
if (groups.indexOf('approver') !== -1) return; // approvers keep the checkbox
// Hide the Draft namespace checkbox in the advanced search pane
$c.find('input[name="ns' + 3000 + '"]').closest('label, .mw-advancedSearch-ns_option').hide();
});
// Load Google CSE only on Advanced_search page
mw.loader.using('mediawiki.util').then(function () {
var page = mw.config.get('wgPageName');
if (page !== 'Artifacts_of_Capitalism:Advanced_search') return;
console.log('[CSE] Loading on:', page);
// Ensure CSE callback setup exists before script load
window.__gcse = {
searchCallbacks: {
ready: function () {
try {
var params = new URLSearchParams(window.location.search);
var q = params.get('q');
if (q) {
var hash = 'gsc.tab=0&gsc.q=' + encodeURIComponent(q);
if (!window.location.hash.includes('gsc.q=')) {
window.location.hash = hash;
console.log('[CSE] Applied query:', q);
}
}
} catch (err) {
console.warn('[CSE] Query error:', err);
}
}
}
};
// Inject Google CSE script
var script = document.createElement('script');
script.async = true;
script.src = 'https://cse.google.com/cse.js?cx=b194aa5e4d64344ad';
script.onload = function () {
console.log('[CSE] Script loaded successfully');
};
script.onerror = function () {
console.error('[CSE] Failed to load cse.js');
};
document.body.appendChild(script);
});
// Open all external links in a new window or tab
$(document).ready(function() {
$('a.external').attr('target', '_blank');
});
mw.loader.using( 'mediawiki.util', function () {
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'CreateAccount' ) {
$( function () {
const form = $('#mw-createaccount-form');
if (!form.length) return;
const realNameDiv = form.find('#wpRealName').closest('.form-group, .mw-input, p');
if (!realNameDiv.length) return;
// --- Affiliation field ---
const affField = $(`
<div class="form-group mw-input">
<label for="wpAffiliation">Affiliation</label>
<input type="text" id="wpAffiliation" name="wpAffiliation"
required class="form-control mw-ui-input"/>
</div>
`);
// --- Institutional Email field ---
const instField = $(`
<div class="form-group mw-input">
<label for="wpInstitutionalEmail">Institutional Email</label>
<input type="email" id="wpInstitutionalEmail" name="wpInstitutionalEmail"
required class="form-control mw-ui-input"/>
</div>
`);
// Insert right after Real Name
realNameDiv.after( affField, instField );
});
}
});