From 3520e510be79a7bf56f33771c282fd6e905d7cea Mon Sep 17 00:00:00 2001 From: jlukic Date: Tue, 31 Mar 2015 11:30:10 -0400 Subject: [PATCH] #2042 add delegated events to rating --- src/definitions/modules/rating.js | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/definitions/modules/rating.js b/src/definitions/modules/rating.js index a4842d775..db8be05b8 100644 --- a/src/definitions/modules/rating.js +++ b/src/definitions/modules/rating.js @@ -87,12 +87,10 @@ $.fn.rating = function(parameters) { destroy: function() { module.verbose('Destroying previous instance', instance); + module.remove.events(); $module .removeData(moduleNamespace) ; - $icon - .off(eventNamespace) - ; }, refresh: function() { @@ -169,13 +167,29 @@ $.fn.rating = function(parameters) { return currentRating; }, + bind: { + events: function() { + module.verbose('Binding events'); + $module + .on('mouseenter' + eventNamespace, selector.icon, module.event.mouseenter) + .on('mouseleave' + eventNamespace, selector.icon, module.event.mouseleave) + .on('click' + eventNamespace, selector.icon, module.event.click) + ; + } + }, + + remove: { + events: function() { + module.verbose('Removing events'); + $module + .off(eventNamespace) + ; + } + }, + enable: function() { module.debug('Setting rating to interactive mode'); - $icon - .on('mouseenter' + eventNamespace, module.event.mouseenter) - .on('mouseleave' + eventNamespace, module.event.mouseleave) - .on('click' + eventNamespace, module.event.click) - ; + module.bind.events(); $module .removeClass(className.disabled) ; @@ -183,9 +197,7 @@ $.fn.rating = function(parameters) { disable: function() { module.debug('Setting rating to read-only mode'); - $icon - .off(eventNamespace) - ; + module.remove.events(); $module .addClass(className.disabled) ;