mzubala / jquery-custom-scrollbar

189 stars 102 forks source link

Issue with removeWindowResize #45

Open Jevedor opened 10 years ago

Jevedor commented 10 years ago

The function removeWindowResize has an issue in that it does not confirm that the method this.windowResize has been instantiated.

removeWindowResize: function () { $(window).unbind("resize", this.windowResize); },

this.windowResize gets defined based on an if statement in the initWindowResize method.

initWindowResize: function () { if (this.scrollable.options.updateOnWindowResize) { var _this = this; this.windowResize = function () { _this.resize(); }; $(window).resize(this.windowResize); } },

This means that it may not ever be defined. If this is the case and then the removeWindowResize is called when the second arguement gets passed to the unbind method it is 'undefined'. This results in jQuery treating the unbind method as if it did not have a specified handler. When unbind does not have a specified handler it unbinds everything on the targeted event. This is an issue that can be fixed by confirming this.windowResize is defined before unbinding it.

removeWindowResize: function () { if (typeof this.windowResize == 'function'){ $(window).unbind("resize", this.windowResize); } },