-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.html
More file actions
130 lines (115 loc) · 5.66 KB
/
Copy pathdictionary.html
File metadata and controls
130 lines (115 loc) · 5.66 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bye Bye Oil - Dictionary</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="dict-page">
<div class="dict-left-pane">
<header class="dict-topbar">
<div class="dict-top-left"><a class="dict-perf-link" href="index.html">← Performance</a></div>
<div class="dict-top-center">Dictionary</div>
<div class="dict-top-right"></div>
</header>
<!-- obj -->
<div class="dict-main-content">
<div class="dict-artwork-area">
<div class="dict-artwork-box">
<canvas id="dictCanvas"></canvas>
</div>
</div>
</div>
<!-- info bottom -->
<div class="dict-info-bottom">
<table class="dict-info-table">
<tbody>
<tr class="dict-info-row-1">
<td class="dict-name-cell">
<div class="dict-label">Name:</div>
<div class="dict-value dict-name-value">-</div>
</td>
<td class="dict-price-cell">
<div class="dict-label">Petroleum Material:</div>
<div class="dict-value dict-material-value">-</div>
</td>
<td class="dict-usage-cell">
<div class="dict-label">Usage:</div>
<div class="dict-value dict-usage-value">-</div>
</td>
</tr>
<tr class="dict-info-row-2">
<td class="dict-material-cell">
<div class="dict-label">Price:</div>
<div class="dict-value dict-price-value">-</div>
</td>
<td class="dict-replacement-cell">
<div class="dict-label">Possible Replacement:</div>
<div class="dict-value dict-replacement-value">Replacement object</div>
</td>
<td class="dict-empty-cell"></td>
</tr>
</tbody>
</table>
</div>
</div>
<aside class="dict-catalog" id="catalog" aria-label="Object dictionary">
<div class="dict-catalog-header">Dictionary</div>
</aside>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/OBJLoader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.js"></script>
<script src="petrolum_list.js"></script>
<script src="products.js"></script>
<script src="model_viewer.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const list = (typeof PETROLUM_LIST !== 'undefined') ? PETROLUM_LIST : [];
const details = (typeof PRODUCT_DETAILS !== 'undefined') ? PRODUCT_DETAILS : {};
const detailsLower = {};
Object.keys(details).forEach(k => { detailsLower[k.toLowerCase()] = details[k]; });
const viewer = new ModelViewer(
document.getElementById('dictCanvas'),
document.querySelector('.dict-artwork-area')
);
function findDetails(name) {
return detailsLower[name.toLowerCase()] || null;
}
function selectItem(name, el) {
document.querySelectorAll('.dict-catalog-item').forEach(x => x.classList.remove('selected'));
if (el) el.classList.add('selected');
const d = findDetails(name) || {};
const price = (typeof d.price === 'number') ? `$${d.price.toFixed(2)}` : '-';
const usage = d.usage || '-';
const material = d.petroleum || 'Material - related to petroleum';
const replacement = d.alternative || 'Replacement object';
const nameEl = document.querySelector('.dict-name-value');
const priceEl = document.querySelector('.dict-price-value');
const usageEl = document.querySelector('.dict-usage-value');
const materialEl = document.querySelector('.dict-material-value');
const replacementEl = document.querySelector('.dict-replacement-value');
if (nameEl) nameEl.textContent = name;
if (priceEl) priceEl.textContent = price;
if (usageEl) usageEl.textContent = usage;
if (materialEl) materialEl.textContent = material;
if (replacementEl) replacementEl.textContent = replacement;
viewer.loadProduct(name);
}
const catalog = document.getElementById('catalog');
const sorted = list.slice().sort((a, b) => a.localeCompare(b));
sorted.forEach(name => {
const el = document.createElement('div');
el.className = 'dict-catalog-item';
el.textContent = name;
el.addEventListener('click', () => selectItem(name, el));
catalog.appendChild(el);
});
const first = catalog.querySelector('.dict-catalog-item');
if (first) selectItem(first.textContent, first);
});
</script>
</body>
</html>