Here's a cleanup_jquery_listeners utility function:
const cleanup_jquery_listeners = cleanupspec => {
// cleanupspec is a list of triples of
// [jquery sets, selector or null, event string]
// example: [
// [[$origPostForm, $postForm], 'input[type="text"],select', '.quickreply'],
// [[$(window)], null, 'scroll.quickreply']
// ]
for (const [sets, sel, events] of cleanupspec) {
for (let oneset of sets) {
if (sel != null) {
oneset = oneset.find (sel)
}
oneset.off (events)
}
}
}Then in .close-btn click:
const spec = [
[[$origPostForm, $postForm], 'textarea[name="body"]', '.quickreply'],
[[$origPostForm, $postForm], 'input[type="text"],select', '.quickreply'],
[[$(window)], null, 'scroll.quickreply'],
[[$postForm], 'th .close-btn', 'click.quickreply'],
]
cleanup_jquery_listeners (spec)
The $postForm is cleaned up for completeness. When spoilers are synced
>>10441 they can be added to the spec list in the obvious way. All
on calls need .quickreply on their events. The click, focus and scroll calls become .on('click.quickreply', …) and equivalent. The exceptions are the last two listeners of
>>10455 which can be dealt with using callonce_factory
>>10109.