From 6b7d4e3ebc5b777012261e03f70e0cc331b965bc Mon Sep 17 00:00:00 2001 From: smadapathi Date: Mon, 15 Sep 2014 13:01:35 +0530 Subject: [PATCH] Improve mousewheel event callback sample --- samples/utils/domevents/mousewheel/MouseWheel.tpl | 7 ++++--- .../domevents/mousewheel/MouseWheelScript.js | 15 +++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/samples/utils/domevents/mousewheel/MouseWheel.tpl b/samples/utils/domevents/mousewheel/MouseWheel.tpl index a2180ee..7257c55 100644 --- a/samples/utils/domevents/mousewheel/MouseWheel.tpl +++ b/samples/utils/domevents/mousewheel/MouseWheel.tpl @@ -4,9 +4,9 @@ } } {macro main ( )} -

This sample demonstrates the usage of onwheel

+

This sample demonstrates the usage of mosuewheel event callback

- Use the mouse wheel on the field below. + Use the mouse scroll on the div below. One mouse scroll down is -120 and one mouse scroll up is +120.

- The last roll amount: + Below field shows the sum of scrolled value +
{@aria:NumberField {bind:{value:{to:"rolled",inside:data}}}/} diff --git a/samples/utils/domevents/mousewheel/MouseWheelScript.js b/samples/utils/domevents/mousewheel/MouseWheelScript.js index 580672a..77c72ef 100644 --- a/samples/utils/domevents/mousewheel/MouseWheelScript.js +++ b/samples/utils/domevents/mousewheel/MouseWheelScript.js @@ -2,16 +2,11 @@ Aria.tplScriptDefinition({ $classpath : "samples.utils.domevents.mousewheel.MouseWheelScript", $implements : ["aria.core.Browser", "aria.utils.Dom"], $prototype : { - onMouseScroll : function (event) { - var rolled = 0; - if ('wheelDelta' in event && !aria.core.Browser.isFirefox) { - rolled = event.wheelDelta; - } else { // Firefox - // The measurement units of the detail and wheelDelta properties are different. - rolled = -40 * event.detail; - } - - this.$json.setValue(this.data, "rolled", rolled); + sumRolledVal : 0, + onMouseScroll : function (evt) { + this.sumRolledVal += (evt.detail) ? evt.detail * (-40) : evt.wheelDelta; + this.sumRolledVal = this.sumRolledVal > 0 ? 0 : this.sumRolledVal; + this.$json.setValue(this.data, "rolled", this.sumRolledVal); } } });