This repository was archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
244 lines (233 loc) · 9.5 KB
/
Copy pathfilter.js
File metadata and controls
244 lines (233 loc) · 9.5 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
$(function() {
var data = {
'國小': ['馬克一號', 'Smart'],
'國中': ['馬克一號', 'Smart'],
'高中': ['馬克一號', 'Smart', 'Webduino Fly'],
'大學': ['馬克一號', 'Smart', 'Webduino Fly'],
'研究所': ['馬克一號', 'Smart', 'Webduino Fly'],
'網頁工程師': ['馬克一號', 'Smart'],
'設計師': ['馬克一號', 'Smart'],
'物聯網體驗': ['Smart'],
'程式學習': ['馬克一號', 'Smart'],
'基礎應用': ['馬克一號', 'Smart'],
'進階應用': ['馬克一號', 'Smart', 'Webduino Fly'],
'智慧生活': ['馬克一號', 'Smart', 'Webduino Fly'],
'玩具改造': ['馬克一號', 'Smart'],
'物聯網開發': ['馬克一號', 'Smart', 'Webduino Fly'],
'APP 開發': ['馬克一號', 'Smart']
};
var data2 = {
'國小': ['基本包', 'Dr.Smart', '公仔自走車', '公仔自走車循跡套件', '基礎套件包'],
'國中': ['基本包', 'Dr.Smart', '智慧植栽', '公仔自走車', '公仔自走車循跡套件', '基礎套件包', '進階套件包'],
'高中': ['基本包', '威力加強包', 'Dr.Smart', '智慧植栽', '智慧插座', '公仔自走車', '公仔自走車循跡套件', '豪華套件包', '基礎套件包', '進階套件包', '高階套件包'],
'大學': ['威力加強包', '智慧插座實戰開發包', '智慧植栽', '智慧插座', '智慧插座擴充', '豪華套件包', '進階套件包', '高階套件包'],
'研究所': ['威力加強包', '智慧插座實戰開發包', '智慧植栽', '智慧插座', '智慧插座擴充', '豪華套件包'],
'網頁工程師': ['基本包', '威力加強包', 'Dr.Smart', '基礎套件包'],
'設計師': ['基本包', 'Dr.Smart', '基礎套件包'],
'物聯網體驗': ['Dr.Smart'],
'程式學習': ['基本包', '威力加強包', 'Dr.Smart', '基礎套件包'],
'基礎應用': ['基本包', '威力加強包', 'Dr.Smart', '公仔自走車', '公仔自走車循跡套件', '基礎套件包'],
'進階應用': ['智慧插座實戰開發包', '智慧植栽', '智慧插座', '智慧插座擴充', '豪華套件包', '進階套件包', '高階套件包'],
'智慧生活': ['智慧插座實戰開發包', '智慧植栽', '豪華套件包'],
'玩具改造': ['公仔自走車', '公仔自走車循跡套件', '進階套件包'],
'物聯網開發': ['智慧插座實戰開發包', '智慧植栽', '智慧插座', '智慧插座擴充', '豪華套件包'],
'APP 開發': ['基本包', 'Dr.Smart']
};
var data3 = {
'國小': ['Blockly', '模擬器'],
'國中': ['Blockly', '模擬器'],
'高中': ['Blockly (註冊版)', 'HyProto', '模擬器'],
'大學': ['Blockly (註冊版)', '裝置管理 (註冊版)', 'HyProto (註冊版)', 'Node-RED (註冊版)'],
'研究所': ['Blockly (註冊版)', '裝置管理 (註冊版)', 'HyProto (註冊版)', 'Node-RED (註冊版)'],
'網頁工程師': ['Blockly (註冊版)', 'HyProto (註冊版)', 'Node-RED (註冊版)'],
'設計師': ['Blockly', 'HyProto'],
'物聯網體驗': ['Blockly'],
'程式學習': ['Blockly', 'HyProto'],
'基礎應用': ['Blockly', '模擬器', 'HyProto'],
'進階應用': ['Blockly (註冊版)', '裝置管理 (註冊版)', 'HyProto (註冊版)', 'Node-RED (註冊版)'],
'智慧生活': ['Blockly (註冊版)', '裝置管理 (註冊版)', 'Node-RED (註冊版)'],
'玩具改造': ['Blockly (註冊版)', '裝置管理 (註冊版)', 'HyProto'],
'物聯網開發': ['Blockly (註冊版)', '裝置管理 (註冊版)', 'Node-RED (註冊版)'],
'APP 開發': ['Blockly', 'HyProto (註冊版)', 'Node-RED (註冊版)']
};
var link = {
'馬克一號': 'https://webduino.io/buy/component-webduino-v1.html',
'Smart': 'https://webduino.io/buy/component-webduino-smart.html',
'Webduino Fly': 'https://webduino.io/buy/component-webduino-fly.html',
'基本包': 'https://webduino.io/buy/webduino-developer-a.html',
'威力加強包': 'https://webduino.io/buy/webduino-developer-b.html',
'Dr.Smart': 'https://webduino.io/buy/webduino-developer-drsmart.html',
'智慧植栽': 'https://webduino.io/buy/webduino-package-plant.html',
'智慧插座': 'https://webduino.io/buy/webduino-package-socket.html',
'智慧插座擴充': 'https://webduino.io/buy/webduino-package-socket-extension.html',
'智慧插座實戰開發包': 'https://webduino.io/buy/webduino-developer-smart-socket.html',
'公仔自走車': 'https://webduino.io/buy/webduino-package-toycar.html',
'公仔自走車循跡套件': 'https://webduino.io/buy/webduino-package-line-following.html',
'基礎套件包': 'https://webduino.io/buy/webduino-components-facile-package.html',
'進階套件包': 'https://webduino.io/buy/webduino-components-standard-package.html',
'高階套件包': 'https://webduino.io/buy/webduino-components-excellent-package.html',
'豪華套件包': 'https://webduino.io/buy/webduino-package-all.html',
'Blockly': 'https://blockly.webudino.io',
'模擬器': 'http://simulator.webduino.io/',
'HyProto': 'https://hypro.to'
};
var $checkBox = $('.checkbox');
var $label = $('label');
$label.on('click',function() {
if ($(this).hasClass('checked')) {
$(this).removeClass('checked');
} else {
$(this).addClass('checked');
}
});
$checkBox.on('change', function(event) {
// 一開始先清空顯示區域
$('.a').html('');
var arr = [];
var arr2 = [];
var arr3 = [];
var resultArr = {};
var resultArr2 = {};
var resultArr3 = {};
var counts = {};
var counts2 = {};
var counts3 = {};
// 把 checkbox 的資訊對應到內容,篩選對應的內容放入陣列
$checkBox.each(function() {
var $this = $(this);
var $val = $this.val();
if ($this.is(':checked')) {
for (var i in data) {
if ($val == i) {
arr = arr.concat(data[i]);
}
}
for (var i in data2) {
if ($val == i) {
arr2 = arr2.concat(data2[i]);
}
}
for (var i in data3) {
if ($val == i) {
arr3 = arr3.concat(data3[i]);
}
}
}
});
// 判斷同一種產品出現了幾次
arr.forEach(function(item) {
if (counts[item]) {
counts[item] = counts[item] + 1;
} else {
counts[item] = 1;
}
});
arr2.forEach(function(item) {
if (counts2[item]) {
counts2[item] = counts2[item] + 1;
} else {
counts2[item] = 1;
}
});
arr3.forEach(function(item) {
if (counts3[item]) {
counts3[item] = counts3[item] + 1;
} else {
counts3[item] = 1;
}
});
// 把結果放到結果陣列中
for (var j in counts) {
if (resultArr[counts[j]]) {
resultArr[counts[j]].push(j);
} else {
resultArr[counts[j]] = [j];
}
}
for (var j in counts2) {
if (resultArr2[counts2[j]]) {
resultArr2[counts2[j]].push(j);
} else {
resultArr2[counts2[j]] = [j];
}
}
for (var j in counts3) {
if (resultArr3[counts3[j]]) {
resultArr3[counts3[j]].push(j);
} else {
resultArr3[counts3[j]] = [j];
}
}
// 依據出現結果的次數,產生對應的推薦結果
for (var k in resultArr) {
resultArr[k].forEach(function(item) {
if (k > 3) {
$('.box1 .a3').append('<a href="#">' + item + '</a>');
} else if (k == 3 || k == 2) {
$('.box1 .a2').append('<a href="#">' + item + '</a>');
} else {
$('.box1 .a1').append('<a href="#">' + item + '</a>');
}
});
}
for (var k in resultArr2) {
resultArr2[k].forEach(function(item) {
if (k > 3) {
$('.box2 .a3').append('<a href="#">' + item + '</a>');
} else if (k == 3 || k == 2) {
$('.box2 .a2').append('<a href="#">' + item + '</a>');
} else {
$('.box2 .a1').append('<a href="#">' + item + '</a>');
}
});
}
for (var k in resultArr3) {
resultArr3[k].forEach(function(item) {
if (k > 3) {
$('.box3 .a3').append('<a href="#">' + item + '</a>');
} else if (k == 3 || k == 2) {
$('.box3 .a2').append('<a href="#">' + item + '</a>');
} else {
$('.box3 .a1').append('<a href="#">' + item + '</a>');
}
});
}
// 依據推薦的結果加上 style
$('.a1').removeClass('s1').removeClass('s2');
$('.a1').each(function() {
var p2 = $(this).parent().children('.a2').text();
var p3 = $(this).parent().children('.a3').text();
if (p2.length > 0 && p3.length > 0) {
$(this).addClass('s1');
} else if (p2.length > 0 && p3.length == 0) {
$(this).addClass('s2');
} else if (p2.length == 0 && p3.length > 0) {
$(this).addClass('s2');
}
});
$('.a2').removeClass('s1');
$('.a2').each(function() {
var p3 = $(this).parent().children('.a3').text();
if (p3.length > 0) {
$(this).addClass('s1');
}
});
// 沒有結果的不顯示
$('.a').each(function() {
if ($(this).text().length < 1) {
$(this).hide();
} else {
$(this).show();
};
});
// 篩選出來的結果加上對應的連結
$('a').each(function() {
var $this = $(this);
if (link[$this.text()]) {
$this.attr('href', link[$this.text()]).attr('target', '_blank');
} else {
$this.attr('href', 'https://cloud.webduino.io').attr('target', '_blank');
}
});
});
});