Attempt at listen fix

checks dom.isactive & allows displayUpdate(force), set true for by default for setValue
fixes isactive problems
allows drag events, and re-added key up/down
This commit is contained in:
AARON WELLES 2019-06-26 23:18:41 -04:00
parent 743a16b398
commit 5212bd428e
3 changed files with 27 additions and 14 deletions

View File

@ -17,6 +17,7 @@
* @param {Object} object The object to be manipulated
* @param {string} property The name of the property to be manipulated
*/
class Controller {
constructor(object, property) {
this.initialValue = object[property];
@ -92,7 +93,7 @@ class Controller {
this.__onChange.call(this, newValue);
}
this.updateDisplay();
this.updateDisplay(true);
return this;
}
@ -110,7 +111,7 @@ class Controller {
* with the object's current value.
* @returns {Controller} this
*/
updateDisplay() {
updateDisplay(force) {
return this;
}

View File

@ -94,11 +94,22 @@ class NumberControllerBox extends NumberController {
dom.bind(this.__input, 'mousedown', onMouseDown);
dom.bind(this.__input, 'keydown', function(e) {
// When pressing enter, you can be as precise as you want.
if (e.keyCode === 13) {
_this.__truncationSuspended = true;
this.blur();
_this.__truncationSuspended = false;
onFinish();
const step = _this.__step || 1;
switch (e.keyCode) {
case 13:
_this.__truncationSuspended = true;
this.blur();
_this.__truncationSuspended = false;
onFinish();
break;
case 38:
var newVal = _this.getValue() + step;
_this.setValue(newVal);
break;
case 40: // down
var newVal = _this.getValue() - step;
_this.setValue(newVal);
break;
}
});
@ -107,10 +118,11 @@ class NumberControllerBox extends NumberController {
this.domElement.appendChild(this.__input);
}
updateDisplay() {
updateDisplay(force) {
if (!force && dom.isActive(this.__input)) return this;
this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);
return super.updateDisplay();
}
}
export default NumberControllerBox;
export default NumberControllerBox;

View File

@ -24,7 +24,7 @@ import common from '../utils/common';
* @param {Object} object The object to be manipulated
* @param {string} property The name of the property to be manipulated
* @param {Object|string[]} options A map of labels to acceptable values, or
* a list of acceptable string values.
* a list of acceptable string values.
*/
class OptionController extends Controller {
constructor(object, property, opts) {
@ -75,11 +75,11 @@ class OptionController extends Controller {
return toReturn;
}
updateDisplay() {
if (dom.isActive(this.__select)) return this; // prevent number from updating if user is trying to manually update
updateDisplay(force) {
if (!force && dom.isActive(this.__select)) return this; // prevent number from updating if user is trying to manually update
this.__select.value = this.getValue();
return super.updateDisplay();
return super.updateDisplay(force);
}
}
export default OptionController;
export default OptionController;