hedera-web/js/hedera/social-bar.js

66 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-06-06 16:19:43 +00:00
require('./social-bar.scss');
2022-05-30 01:30:33 +00:00
module.exports = new Class({
2022-06-06 12:49:18 +00:00
Extends: Vn.Component
,Tag: 'htk-social-bar'
2022-05-30 01:30:33 +00:00
,Properties: {
conn: {
type: Db.Connection
2022-05-30 01:30:33 +00:00
,set: function(x) {
this._conn = x;
2022-05-30 01:30:33 +00:00
this._refresh();
}
2022-05-30 01:30:33 +00:00
,get: function() {
return this._conn;
}
},
2022-05-30 01:30:33 +00:00
priority: {
type: Number
2022-05-30 01:30:33 +00:00
,set: function(x) {
this._priority = x;
2022-05-30 01:30:33 +00:00
this._refresh();
}
2022-05-30 01:30:33 +00:00
,get: function() {
return this._priority;
}
2016-10-14 10:58:35 +00:00
}
}
2016-10-14 10:58:35 +00:00
,_priority: 0
2022-05-30 01:30:33 +00:00
,initialize: function() {
var node = this.createRoot('div');
2016-10-14 10:58:35 +00:00
node.className = 'htk-social-bar';
}
2016-10-14 10:58:35 +00:00
2022-05-30 01:30:33 +00:00
,_refresh: function() {
if (!this._conn || this._priority === null)
return;
2022-05-30 01:30:33 +00:00
const params = {priority: this._priority};
2016-10-14 10:58:35 +00:00
var query = 'SELECT title, link, icon FROM social '
2016-10-14 10:58:35 +00:00
+'WHERE priority >= #priority ORDER BY priority';
2022-05-30 01:30:33 +00:00
this._conn.execQuery(query, this._onQueryDone.bind(this), params);
}
2022-05-30 01:30:33 +00:00
,_onQueryDone: function(resultSet) {
Vn.Node.removeChilds(this._node);
var res = resultSet.fetchResult();
2022-05-30 01:30:33 +00:00
while (res.next()) {
var a = this.createElement('a');
a.href = res.get('link');
a.target = '_blank';
2022-05-30 01:30:33 +00:00
this._node.appendChild(a);
2022-05-30 01:30:33 +00:00
var img = this.createElement('img');
img.src = 'image/social/'+ res.get('icon');
img.alt = res.get('title');
img.title = res.get('title');
a.appendChild(img);
}
}
});