-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
180 lines (174 loc) · 4.01 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<title>Text Repeater</title>
</head>
<body>
<script type="module">
import { createApp } from 'https://unpkg.com/petite-vue?module'
const states = {
text: '',
repetition: 1,
separator: ' ',
repeatedText: ''
}
const methods = {
repeatText (text, count, { separator }) {
const repeatedText = `${text}${separator}`
return repeatedText.repeat(count)
},
copyToClipboard (text) {
navigator.clipboard.writeText(text)
}
}
const handlers = {
handleRepeatText () {
this.repeatedText = this.repeatText(
this.text,
this.repetition,
{
separator: this.separator
}
)
},
handleCopyToClipboard () {
this.copyToClipboard(this.repeatedText)
alert('Copied succesfully')
}
}
const App = () => ({
...states,
...methods,
...handlers
})
createApp({
App
}).mount()
</script>
<div
class="p-3"
v-scope="App()"
>
<form
class="container"
@submit.prevent="handleRepeatText"
>
<div class="mb-3">
<label
class="form-label"
for="text"
>
<b>Your Text</b>
</label>
<textarea
class="form-control"
id="text"
v-model="text"
></textarea>
</div>
<div class="mb-3">
<label
class="form-label"
for="repetition"
>
<b>Repetitions</b>
</label>
<input
class="form-control"
id="separator"
type="number"
min="1"
v-model="repetition"
>
</div>
<div class="mb-3">
<label
class="form-label"
for="separator"
>
<b>Separator</b>
</label>
<div class="form-check">
<input
class="form-check-input"
id="space"
type="radio"
name="separator"
v-model="separator"
value=" "
>
<label
class="form-check-label"
for="separator-space"
>
Space
</label>
</div>
<div class="form-check">
<input
class="form-check-input"
id="newline"
type="radio"
name="separator"
v-model="separator"
:value="'\n'"
>
<label
class="form-check-label"
for="separator-newline"
>
New line
</label>
</div>
<div class="form-check">
<input
class="form-check-input"
id="space"
type="radio"
name="separator"
v-model="separator"
value=""
>
<label
class="form-check-label"
for="separator-custom"
>
Custom
</label>
<input
class="form-control"
type="text"
v-model="separator"
>
</div>
</div>
<div class="mb-3">
<button
class="btn btn-primary"
type="submit"
>
Generate
</button>
</div>
</form>
<form class="container">
<div>
<button
class="btn btn-secondary"
@click.prevent="handleCopyToClipboard"
>
Copy Result
</button>
</div>
<textarea
class="form-control my-3"
id="repeated-text"
v-model="repeatedText"
></textarea>
</form>
</div>
</body>
</html>