]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Minor improvement to code that gets active elements
authoretimberg <evert.timberg@gmail.com>
Sun, 22 Nov 2015 03:44:11 +0000 (22:44 -0500)
committeretimberg <evert.timberg@gmail.com>
Sun, 22 Nov 2015 03:44:11 +0000 (22:44 -0500)
src/core/core.controller.js

index 2758ef2badba3c5a3139f7e1aaa0604c7d3f8cc6..2b78ab2332d6fe59fa9297df84d499af531bc488 100644 (file)
                                this.active = [];
                                this.tooltipActive = [];
                        } else {
-                               this.active = function() {
-                                       switch (this.options.hover.mode) {
-                                               case 'single':
-                                                       return this.getElementAtEvent(e);
-                                               case 'label':
-                                                       return this.getElementsAtEvent(e);
-                                               case 'dataset':
-                                                       return this.getDatasetAtEvent(e);
-                                               default:
-                                                       return e;
-                                       }
-                               }.call(this);
-                               this.tooltipActive = function() {
-                                       switch (this.options.tooltips.mode) {
+
+                               var _this = this;
+                               function getItemsForMode(mode) {
+                                       switch (mode) {
                                                case 'single':
-                                                       return this.getElementAtEvent(e);
+                                                       return _this.getElementAtEvent(e);
                                                case 'label':
-                                                       return this.getElementsAtEvent(e);
+                                                       return _this.getElementsAtEvent(e);
                                                case 'dataset':
-                                                       return this.getDatasetAtEvent(e);
+                                                       return _this.getDatasetAtEvent(e);
                                                default:
                                                        return e;
                                        }
-                               }.call(this);
+                               }
+
+                               this.active = getItemsForMode(this.options.hover.mode);
+                               this.tooltipActive = getItemsForMode(this.options.tooltips.mode);
                        }
 
                        // On Hover hook