1. 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

Discussion in 'XenForo Suggestions' started by CyberAP, Aug 22, 2016.

  1. CyberAP

    CyberAP Well-Known Member

    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');
     
  2. CyberAP

    CyberAP Well-Known Member

    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.
     

Share This Page