-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.html
More file actions
191 lines (184 loc) · 6.49 KB
/
Copy pathdemo.html
File metadata and controls
191 lines (184 loc) · 6.49 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RetailId SDK Demo</title>
<style>
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
.header {
background: rgb(33, 63, 57);
margin: -20px -20px 24px -20px;
padding: 16px 20px;
display: flex;
align-items: center;
gap: 12px;
}
.header img { height: 32px; }
.header h1 { color: white; margin: 0; font-size: 20px; }
.subtitle { color: #666; margin-bottom: 24px; }
.card {
background: white;
border-radius: 8px;
padding: 20px;
margin-bottom: 16px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
h2 { margin-top: 0; font-size: 16px; color: #333; }
label { display: block; font-size: 13px; color: #666; margin-bottom: 4px; }
input, select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
margin-bottom: 12px;
}
input:focus { outline: none; border-color: rgb(33, 63, 57); }
button {
background: rgb(33, 63, 57);
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
button:hover { background: rgb(23, 53, 47); }
.result {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 4px;
padding: 12px;
font-family: monospace;
font-size: 13px;
word-break: break-all;
margin-top: 12px;
}
.result.error { background: #fff5f5; border-color: #ffcccc; color: #c00; }
.result.success { background: #f0fff4; border-color: #c6f6d5; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; }
.examples { font-size: 12px; color: #888; margin-top: -8px; margin-bottom: 12px; }
.output-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.output-row .value { flex: 1; word-break: break-all; }
.copy-btn {
background: #6c757d;
color: white;
border: none;
padding: 4px 8px;
border-radius: 3px;
cursor: pointer;
font-size: 11px;
white-space: nowrap;
}
.copy-btn:hover { background: #5a6268; }
.copy-btn.copied { background: #28a745; }
</style>
</head>
<body>
<div class="header">
<img src="https://cdn.1a4.com/qr/js/logo-xsmall.png" alt="RetailId">
<h1>SDK Demo</h1>
</div>
<p class="subtitle">Decode and encode RetailId QR code URLs</p>
<div class="card">
<h2>Decode URL → Tag + Index</h2>
<label for="decodeUrl">QR Code URL</label>
<input type="text" id="decodeUrl" placeholder="HTTPS://D.1A4.COM/10NOIEYKAJDG6CF0EXGJL">
<p class="examples">Try: HTTPS://D.1A4.COM/10NOIEYKAJDG6CF0EXGJL (base36) or https://d.1a4.com/q83vASNFZwAAAnGQAQ (base64)</p>
<div class="checkbox-row">
<input type="checkbox" id="strictMode">
<label for="strictMode">Strict mode (require known prefix or valid MongoDB timestamp)</label>
</div>
<button onclick="decodeUrl()">Decode</button>
<div id="decodeResult" class="result" style="display:none;"></div>
</div>
<div class="card">
<h2>Encode Tag + Index → URL</h2>
<label for="encodeTag">Tag (24-char hex)</label>
<input type="text" id="encodeTag" placeholder="ABCDEF012345670000027190">
<div class="row">
<div>
<label for="encodeIndex">Index</label>
<input type="number" id="encodeIndex" placeholder="1" min="0">
</div>
<div>
<label for="encodeFormat">Format</label>
<select id="encodeFormat">
<option value="base36">Base36 (default)</option>
<option value="base64">Base64 (legacy)</option>
</select>
</div>
</div>
<button onclick="encodeUrl()">Encode</button>
<div id="encodeResult" class="result" style="display:none;"></div>
</div>
<script src="https://cdn.1a4.com/qr/js/retailid.min.js"></script>
<script>
function copyToClipboard(text, btn) {
navigator.clipboard.writeText(text).then(() => {
btn.textContent = 'Copied!';
btn.classList.add('copied');
setTimeout(() => {
btn.textContent = 'Copy';
btn.classList.remove('copied');
}, 1500);
});
}
function outputRow(label, value) {
return `<div class="output-row">
<strong>${label}:</strong>
<span class="value">${value}</span>
<button class="copy-btn" onclick="copyToClipboard('${value}', this)">Copy</button>
</div>`;
}
function decodeUrl() {
const input = document.getElementById('decodeUrl').value.trim();
const strict = document.getElementById('strictMode').checked;
const result = document.getElementById('decodeResult');
result.style.display = 'block';
try {
const pair = new RetailId.RetailIdPair(input, strict);
const tag = pair.batchId.toHexString();
const index = pair.index;
result.className = 'result success';
result.innerHTML = outputRow('Tag', tag) + outputRow('Index', index);
} catch (e) {
result.className = 'result error';
result.textContent = 'Error: ' + e.message;
}
}
function encodeUrl() {
const tag = document.getElementById('encodeTag').value.trim();
const index = parseInt(document.getElementById('encodeIndex').value, 10);
const format = document.getElementById('encodeFormat').value;
const result = document.getElementById('encodeResult');
result.style.display = 'block';
try {
const objectId = new RetailId.ObjectId(tag);
const url = RetailId.getShortUrl(objectId, index, { base64: format === 'base64' });
result.className = 'result success';
result.innerHTML = outputRow('URL', url);
} catch (e) {
result.className = 'result error';
result.textContent = 'Error: ' + e.message;
}
}
// Pre-fill with example
document.getElementById('decodeUrl').value = 'HTTPS://D.1A4.COM/10NOIEYKAJDG6CF0EXGJL';
document.getElementById('encodeTag').value = 'ABCDEF012345670000027190';
document.getElementById('encodeIndex').value = '1';
</script>
</body>
</html>