-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
131 lines (109 loc) · 4.29 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Automatic Vocabulary Slideshow Generator</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head>
<body>
<form class="main" id="form" onsubmit="event.preventDefault(); handleFormSubmit(this);" style="max-width: 580px;margin: 40px auto;">
<div id="forminner">
<div class="row">
<div class="col s12">
<h5 class="center-align teal-text">Generate a Google Presentation from a vocabulary list</h5>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="titlearea" type="text" name="title">
<label for="titlearea">Presentation title</label>
</div>
</div>
<div class="row">
<div class="input-field col s5">
<textarea id="wordarea" class="materialize-textarea" name="words" style="height: 6rem;"></textarea>
<label for="wordarea" id="wordaralabel">Insert one word/phrase per line</label>
</div>
<div class="input-field col s2">
<p class="center-align">
<a class="waves-effect waves-light btn-small" onclick="updateSearchInfo()">→</a>
</p>
</div>
<div class="input-field col s5">
<textarea id="searchinfoarea" class="materialize-textarea" name="searchinfo" style="height: 6rem;"></textarea>
<label for="searchinfoarea" id="searchinfoarealabel">Edit the search terms for each word (optional)</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<button class="waves-effect waves-light btn submit-btn" type="submit" name="submit">Create slideshow</button>
</div>
</div>
<div class="row">
<div class="input-field col s12" id = "progress">
</div>
</div>
</div>
<div id="success" style="display:none">
<h5 class="left-align teal-text">Done</h5>
<p>Your presentation has been successfully generated.</p>
<a href="#" id="presentationLink" target='_blank'>Link to the presentation</a>
</div>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener('load', preventFormSubmit);
function handleFormSubmit(formObject) {
$('#success').hide();
showMessage("Working...");
$('#progress').show();
google.script.run
.withSuccessHandler(showSuccess)
.processForm(formObject);
}
function addSlideshowURL(id) {
var link = 'https://docs.google.com/presentation/d/' + id;
// $('#success').append("<a href='https://docs.google.com/presentation/d/" + id + "' target='_blank'>Link to the presentation</a>");
$('#presentationLink').attr("href", link)
}
function showSuccess(e) {
if (e[0] === "OK") {
$('#progress').hide();
$('#success').show();
addSlideshowURL(e[1]);
}
else{
showError(e);
}
}
function showError(e) {
$('#progress').addClass('red-text').html(e);
}
function showMessage(e) {
$('#progress').removeClass('red-text').html(e);
}
function removeNumbering(phrase) {
var reg = /[0-9]*(\.|\))\s*/g;
formatted = phrase.replace(reg, "");
return formatted;
}
function updateSearchInfo() {
$('#searchinfoarealabel').addClass('active');
$('#searchinfoarea').val(removeNumbering($('#wordarea').val()));
M.textareaAutoResize($('#searchinfoarea'));
}
</script>
</body>
</html>