mirror of
https://github.com/0x1d/esp8266-laser.git
synced 2026-03-22 17:07:32 +01:00
ui
This commit is contained in:
28
frontend/scripts/core/data/DataBinding.js
Normal file
28
frontend/scripts/core/data/DataBinding.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import $ from 'jquery';
|
||||
|
||||
export default class DataBinding {
|
||||
|
||||
inputChange(node, model = {}) {
|
||||
node.on('keyup', function() {
|
||||
model.value = this.value;
|
||||
});
|
||||
return model;
|
||||
}
|
||||
|
||||
inputHandler() {
|
||||
return {
|
||||
set: function(target, prop, newValue) {
|
||||
if (prop == 'value' && target.id) {
|
||||
target[prop] = newValue;
|
||||
$('[data-bind="' + target.id + '"]').val(newValue);
|
||||
return true;
|
||||
} else return false;
|
||||
|
||||
},
|
||||
get: function(target, name) {
|
||||
return target[name];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
23
frontend/scripts/core/data/DataField.js
Normal file
23
frontend/scripts/core/data/DataField.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import DataBinding from './DataBinding';
|
||||
|
||||
export default class DataField {
|
||||
|
||||
constructor(node, data) {
|
||||
this.node = node;
|
||||
this.data = {
|
||||
id: this.node.data('bind')
|
||||
};
|
||||
this.bind();
|
||||
}
|
||||
bind() {
|
||||
this.dataBinding = new DataBinding();
|
||||
this.dataBinding.inputChange(this.node, this.data);
|
||||
this.proxy = new Proxy(this.data, this.dataBinding.inputHandler());
|
||||
}
|
||||
get value() {
|
||||
return this.proxy.value;
|
||||
}
|
||||
set value(newValue) {
|
||||
this.proxy.value = newValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user