• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Use namespaces in events for easy unbinding

CyberAP

Well-known member
#1
Here is some code from xenforo.js:
Code:
$(window).on('resize', function() {
                XenForo.checkQuoteSizing($(document));
            });
Anonymous function was bind to 'resize' event in window. There is no way to unbind this function and save all other functions that were bind to 'resize' event. Here is an easy way to solve this and make developers happy:
Code:
$(window).on('resize.checkQuoteSizing', function() {
                XenForo.checkQuoteSizing($(document));
            });
Now we can unbind this event with a simple call:
Code:
$(window).off('resize.checkQuoteSizing');
 

CyberAP

Well-known member
#2
Just analyzed some XF 2.0 JS and it still has the same event binding as in XF 1.0. I hope this gets changed in final release, so we can customize event listeners as we want to.