User:Noa T'Nessa Levinson/common.js: Difference between revisions
Jump to navigation
Jump to search
(initial creation for testy) |
mNo edit summary |
||
Line 15: | Line 15: | ||
function addCollapseEvent() { | 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 | //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); | $('mw-customtoggle-myDivision1').on('click.mw-collapsible keypress.mw-collapsible', checkIfCollapsed); | ||
} | } | ||
Line 20: | Line 21: | ||
function onReady() { | function onReady() { | ||
//Add a new listener to the hook fired after the collapsible elements are ready. | //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); | mw.hook('wikipage.collapsibleContent').add(addCollapseEvent); | ||
} | } | ||
console.log('Adding wikipage.content listener'); | |||
mw.hook('wikipage.content').add(onReady); | mw.hook('wikipage.content').add(onReady); |
Latest revision as of 21:01, 28 April 2021
//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);