0
1
Fork 0
hedera-web-mindshore/web/js/vn/hash-param.js

125 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-08-17 18:02:14 +00:00
Vn.HashParam = new Class
({
Extends: Vn.Object
,Tag: 'vn-hash-param'
2015-10-14 11:51:43 +00:00
,Child: 'param'
2015-08-17 18:02:14 +00:00
,Properties:
{
param:
{
type: Vn.Param
,set: function (x)
{
this.link ({_param: x}, {'changed': this._onParamChange});
this._refreshParam ();
}
,get: function ()
{
return this._param;
}
},
key:
{
type: String
,set: function (x)
{
this._key = x;
this._onHashChange ();
}
,get: function ()
{
return this._key;
}
2015-12-10 13:48:43 +00:00
},
value:
{
type: Object
,set: function (x)
{
this._value = x;
}
,get: function ()
{
return this._value;
}
},
type:
{
type: Object
,set: function (x)
{
this._type = x;
this._onHashChange ();
}
,get: function ()
{
return this._type;
}
2015-08-17 18:02:14 +00:00
}
}
2015-12-10 13:48:43 +00:00
,_lock: false
,_value: undefined
2015-08-17 18:02:14 +00:00
,_key: null
2015-12-10 13:48:43 +00:00
,_type: null
2015-08-17 18:02:14 +00:00
,initialize: function (props)
{
this.parent (props);
var listener = Vn.Hash.getListener ();
this.link ({_listener: listener}, {'changed': this._onHashChange});
this._onHashChange ();
}
,_onHashChange: function ()
{
if (!this._key || !this._listener)
return;
var newValue = Vn.Hash.get (this._key);
2015-12-10 13:48:43 +00:00
if (this._type)
switch (this._type)
{
case Boolean:
newValue = (/^(true|1)$/i).test (newValue);
break;
case Number:
newValue = 0 + new Number (newValue);
break;
}
2015-08-17 18:02:14 +00:00
2015-12-10 13:48:43 +00:00
if (this._value != newValue)
2015-08-17 18:02:14 +00:00
{
2015-12-10 13:48:43 +00:00
this._value = newValue;
2015-08-17 18:02:14 +00:00
this.signalEmit ('changed');
this._refreshParam ();
}
}
,_refreshParam: function ()
{
2015-12-10 13:48:43 +00:00
if (this._param && !this._lock)
2015-08-17 18:02:14 +00:00
{
2015-12-10 13:48:43 +00:00
this._lock = true;
this._param.value = this._value;
this._lock = false;
2015-08-17 18:02:14 +00:00
}
}
,_onParamChange: function ()
{
2015-12-10 13:48:43 +00:00
if (this._lock)
2015-08-17 18:02:14 +00:00
return;
var map = {};
map[this.key] = this._param.value;
2015-12-10 13:48:43 +00:00
this._lock = true;
2015-08-17 18:02:14 +00:00
Vn.Hash.add (map);
2015-12-10 13:48:43 +00:00
this._lock = false;
2015-08-17 18:02:14 +00:00
}
});