Repository navigation
Expand file tree
/
Copy pathDataItem.js
More file actions
81 lines (72 loc) · 1.92 KB
/
Copy pathDataItem.js
File metadata and controls
81 lines (72 loc) · 1.92 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function($){
var methods = {
init: function(devicesDataItem){
return this.each(function(){
var $this = $(this);
var $item = $(devicesDataItem);
$('<h1></h1>')
.attr('data-role', 'DataItem.Name')
.text($item.attr('name')||$item.attr('id'))
.appendTo($this)
;
if($item.attr('subType')){
$('<span></span>')
.attr('data-role', 'DataItem.Subtype')
.text($item.attr('subType') + ' ')
.appendTo($this)
;
}
$('<span></span>')
.attr('data-role', 'DataItem.Type')
.text($item.attr('type').replace(/_/gi, ' '))
.appendTo($this)
;
$('<br/>').appendTo($this);
$('<span></span>')
.attr('data-role', 'DataItem.Value')
.text('')
.appendTo($this)
;
$this.addClass('DataItem');
$this.attr('data-itemid', $item.attr('id'));
$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')
.addClass($item.prop('tagName').toUpperCase())
;
break;
case 'EVENT':
case 'SAMPLE':
default:
$elem.text($item.text());
$this.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);