User:Noa T'Nessa Levinson/common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
//Just a sample function that iterates over specific custom collapsibles and says whether or not they're collapsed (= if the click I just did collapsed them or not)
function checkIfCollapsed() {
$('[id=mw-customcollapsible-myDivision1]').each(function() {
//Collapsed elements should have the mw-collapsed class
if($(this)[0].className.split(' ').includes('mw-collapsed')) {
alert('Collapsed');
}
else {
alert('Not collapsed');
}
return false;
});
}
function addCollapseEvent() {
//Add new click and keypress event listeners, and bind them to the function above. They should trigger only AFTER the other existing events
console.log('Adding click event');
$('mw-customtoggle-myDivision1').on('click.mw-collapsible keypress.mw-collapsible', checkIfCollapsed);
}
function onReady() {
//Add a new listener to the hook fired after the collapsible elements are ready.
console.log('Adding collapsible listener');
mw.hook('wikipage.collapsibleContent').add(addCollapseEvent);
}
console.log('Adding wikipage.content listener');
mw.hook('wikipage.content').add(onReady);