Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a handler for model and value attributes
- Loading branch information
Showing
27 changed files
with
340 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
require("./doubleTap"); | ||
require("./drag"); | ||
require("./longPress"); | ||
require("./pinch"); | ||
require("./singleTap"); | ||
require("./swipe"); | ||
require("./tap"); | ||
var doubleTap = require("./doubleTap"); | ||
var drag = require("./drag"); | ||
var longPress = require("./longPress"); | ||
var pinch = require("./pinch"); | ||
var singleTap = require("./singleTap"); | ||
var swipe = require("./swipe"); | ||
var tap = require("./tap"); | ||
|
||
module.exports.register = function() { | ||
doubleTap.register(); | ||
drag.register(); | ||
longPress.register(); | ||
pinch.register(); | ||
singleTap.register(); | ||
swipe.register(); | ||
tap.register(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var klass = require("../../klass"); | ||
|
||
var ModelValueHandler = klass({ | ||
$constructor : function (nodeInstance) { | ||
this.nodeInstance = nodeInstance; | ||
this.node = nodeInstance.node; | ||
this._lastValues = {}; | ||
// note: when the input event is properly implemented we don't need to listen to keyup | ||
// but IE8 and IE9 don't implement it completely - thus the need for keyup | ||
this._inputEvents = ["click", "focus", "input", "keyup"]; | ||
nodeInstance.registerEventListeners(this._inputEvents); | ||
}, | ||
|
||
setValue: function (name, value) { | ||
if (name === "value") { | ||
// value attribute must be changed directly as the node attribute is only used for the default value | ||
if (this.node.type === "radio") { | ||
this.node.value = value; | ||
} | ||
} | ||
this._lastValues[name] = value; | ||
}, | ||
|
||
afterRefreshAttributes: function() { | ||
var lastValue = typeof this._lastValues["model"] === "undefined"? this._lastValues["value"]: this._lastValues["model"]; | ||
var lastValueAsString = '' + lastValue; | ||
if (this.node.type === "radio") { | ||
var currentValueAsString = '' + this.node.value; | ||
this.node.checked = (lastValueAsString === currentValueAsString); | ||
} else if (this.node.type === "checkbox") { | ||
var currentValueAsString = '' + this.node.checked; | ||
if (lastValueAsString !== currentValueAsString) { | ||
this.node.checked = !this.node.checked; | ||
} | ||
} else if (lastValueAsString != this.node.value) { | ||
//only update if value is changing | ||
this.node.value = lastValue; | ||
} | ||
}, | ||
|
||
handleEvent : function (evt) { | ||
if (this._inputEvents.indexOf(evt.type) > -1) { | ||
// push the field value to the data model | ||
var value = this.node.value; | ||
var type = this.node.type; | ||
if (type === "checkbox") { | ||
value = this.node.checked; | ||
} | ||
var isSet = this.nodeInstance.setAttributeValueInDataModel("model", value); | ||
if (!isSet) { | ||
this.nodeInstance.setAttributeValueInDataModel("value", value); | ||
} | ||
} | ||
}, | ||
|
||
$dispose: function() { | ||
this._inputEvents.length = 0; | ||
} | ||
}); | ||
|
||
module.exports = ModelValueHandler; |
Oops, something went wrong.