-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
81 lines (69 loc) · 2.26 KB
/
main.js
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
// default global variables
var rows = 2;
var columns = 3;
var spacing = 3;
var htmlTable = '';
var ampTable = '';
var templateType = 'HTML';
// click event for the generate template button
$('#generateTemplate').click((e) => {
// this code will execute once generate template is clicked
e.preventDefault();
htmlTable = `<table class="dh-gallery-table">`;
ampTable = `<table class="dh-gallery-table">`;
for (var i = 0; i < rows; i++) {
htmlTable = htmlTable + `<tr>`;
ampTable = ampTable + `<tr>`;
for (var j = 0; j < columns; j++) {
htmlTable = htmlTable + `
<td style="padding:` + spacing + `px;">
<a href="https://hackett.dev">
<img src="https://placeimg.com/150/150/animals" height="150" />
</a>
</td>`;
ampTable = ampTable + `
<td style="padding:` + spacing + `px;">
<a href="https://hackett.dev" target="_blank">
<amp-img src="https://placeimg.com/150/150/animals" height="150" width="150">
</amp-img>
</a>
</td>`;
}
htmlTable = htmlTable + `</tr>`;
ampTable = ampTable + `</tr>`;
}
htmlTable = htmlTable + `</table>`;
ampTable = ampTable + `
</table>`;
if (templateType === 'AMP') {
$('#formControlTextarea').text(ampTable);
} else {
$('#formControlTextarea').text(htmlTable);
}
// AMP tables won't render in HTML, so showing HTML preview
document.getElementById('table-preview').innerHTML = htmlTable;
});
// radio button click event
$('.form-check-input').click((e) => {
var value = e.currentTarget.value.slice(-1);
if (e.currentTarget.value.startsWith('row')) {
rows = value;
document.getElementById('rowsValue').innerHTML = rows;
} else {
columns = value
document.getElementById('columnsValue').innerHTML = columns;
};
});
$('#formControlTextarea').click(() => {
document.getElementById("formControlTextarea").select();
});
// click event for HTML/AMP Toggle
$('.btn-group-toggle').change((e) => {
templateType = e.target.value;
document.getElementById('templateValue').innerHTML = e.target.value;
});
// slider change event
$(".custom-range").change((e) => {
spacing = e.currentTarget.value;
document.getElementById('spacingValue').innerHTML = e.currentTarget.value + 'px';
});