-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataItem.js
64 lines (55 loc) · 1.5 KB
/
DataItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function($){
var methods = {
init: function(devicesDataItem){
return this.each(function(){
var $this = $(this);
var $item = $(devicesDataItem);
$('<span></span>')
.attr('data-role', 'DataItem.Value')
.text('')
.appendTo($this)
;
$this.addClass('DataItem');
var itm = $item.attr('name') || $item.attr('id')
$this.attr('data-itemid', itm);
$this.attr('data-role', 'DataItem');
$this.data('DataItem', {
probe: $item
});
});
},
update: function(streamsDataItem){
return this.each(function(){
var $this = $(this);
var $item = $(streamsDataItem);
var data = $this.data('DataItem');
var $elem = $this.find('[data-role="DataItem.Value"]');
switch(data.probe.attr('category')){
case 'CONDITION':
$elem.text($item.text()||$item.prop('tagName'));
$this.removeClass('UNAVAILABLE NORMAL WARNING FAULT');
$this.parent().addClass($item.prop('tagName').toUpperCase())
;
break;
case 'EVENT':
case 'SAMPLE':
default:
$elem.text($item.text());
$this.parent().removeClass().addClass($item.text());
break;
}
});
}
};
$.fn.DataItem = function(method){
if(methods[method]){
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}
else if(typeof method === 'object' || !method){
return methods.init.apply(this, arguments);
}
else{
$.error('Method ' + method + ' does not exist on jQuery.DataItem');
}
}
})(jQuery);