hedera-web/web/js/vn/hash-param.js

125 lines
1.8 KiB
JavaScript
Executable File

Vn.HashParam = new Class
({
Extends: Vn.Object
,Tag: 'vn-hash-param'
,Child: 'param'
,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;
}
},
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;
}
}
}
,_lock: false
,_value: undefined
,_key: null
,_type: null
,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);
if (this._type)
switch (this._type)
{
case Boolean:
newValue = (/^(true|1)$/i).test (newValue);
break;
case Number:
newValue = 0 + new Number (newValue);
break;
}
if (this._value != newValue)
{
this._value = newValue;
this.signalEmit ('changed');
this._refreshParam ();
}
}
,_refreshParam: function ()
{
if (this._param && !this._lock)
{
this._lock = true;
this._param.value = this._value;
this._lock = false;
}
}
,_onParamChange: function ()
{
if (this._lock)
return;
var map = {};
map[this.key] = this._param.value;
this._lock = true;
Vn.Hash.add (map);
this._lock = false;
}
});