-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.js
More file actions
129 lines (111 loc) · 3.13 KB
/
components.js
File metadata and controls
129 lines (111 loc) · 3.13 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
$(window).bind("load", function() {
// var table = document.getElementById('component_outer_table');
// table.getElementsByTagName('col')[5].style.visibility="collapse";
// set row onclick event:
var rows = document.getElementsByTagName('tr');
for (var i = 1; i < rows.length; i++) {
var data =rows[i].children[5].textContent;
rows[i].onclick = function(data) {
return function() {
if (screen_width() < 1025) {
alert(data);
}
};
}(data);
}
if(!('contains' in String.prototype))
String.prototype.contains = function(str, startIndex) { return -1!==this.indexOf(str, startIndex); };
});
function screen_width() {
var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
return width;
}
// This is the action that is called onKeyUp
function action_filter() {
var filter_criteria = {};
var search = $('#search').val().toLowerCase();
filter_document(search);
return false;
}
function filter_row(row) {
}
// Set the visibility of tables in the document such that only those that match
// the filter criteria are shown
function filter_document(search) {
// There are a few things we can filter by; each is a separate string
// * Component ID (C11101)
// * Short Name (Blue Rock)
// * Long Name (Blue Quartz)
// * Type (Creation)
// * Power (1 or Common)
// console.log("filter_document(" + search + ")");
var filters = search.split(' ');
var power_ary = ['common','uncommon','rare','singular','scarce','1','2','4'];
var power_obj = {
'common':1,
'uncommon':1,
'rare':2,
'singular':4,
'scarce':4,
'1':1,
'2':2,
'4':4
};
var col_max = $('#component_table tr')[0].childNodes.length;
$('#component_table').children().each(function(row_i, row) {
var hidden = false;
for (var i = 0; i < filters.length; i++) {
var crit = filters[i];
var filter_success = false;
if (crit in power_obj) {
// if (row_i == 0)
// console.log('Specifically checking the component power');
if (crit != 'common' && crit != 'uncommon') {// special cases
if (!(row.children[3].textContent == power_obj[crit])) {
hidden = true;
break;
}
} else { // common and uncommon
if (!(row.children[1].textContent[0].toLowerCase() == crit[0])) {
hidden = true;
break;
}
}
} else {
// if (row_i < 10)
// console.log('Checking filter "' + crit + '" in row ' + row_i);
for (var j = 1; j < col_max; j++) {
if (row.children[j].textContent.toLowerCase().contains(crit)) {
filter_success = true;
// if (row_i < 10)
// console.log('filter found in row ' + row_i);
break;
}
}
if (!filter_success) {
hidden = true;
// if (row_i < 10)
// console.log('filter not found in row ' + row_i);
break;
}
}
}
if (hidden) {
// if (row_i < 10)
// console.log('Hiding row ' + row_i);
if (typeof(row.hide) === typeof(Function)) {
row.hide();
} else {
row.style.display = 'none';
}
} else {
// if (row_i < 10)
// console.log('Showing row ' + row_i);
if (typeof(row.show) === typeof(Function)) {
row.show();
} else {
row.style.display = '';
}
}
});
}