|
13 | 13 | background-color: #f66; |
14 | 14 | border-color: #a94442; |
15 | 15 | } |
| 16 | + |
| 17 | + .copied { |
| 18 | + color:#888; |
| 19 | + } |
| 20 | + |
| 21 | + .fresh { |
| 22 | + color:#000; |
| 23 | + } |
| 24 | + |
| 25 | + .notready { |
| 26 | + color:#000; |
| 27 | + } |
16 | 28 | </style> |
17 | 29 | </head> |
18 | 30 | <body> |
|
31 | 43 | <h2 style="margin-top: 0;" id="title"></h2> |
32 | 44 | <div id="variables"></div> |
33 | 45 | <textarea id="text" class="form-control" style="height: 400px;"></textarea> |
| 46 | + <button style="margin-top: 20px;" id="button" class="fresh" onclick="copyText()">Copy Text</button> |
34 | 47 | </div> |
35 | 48 | </div> |
36 | 49 | </div> |
|
75 | 88 | values[v] = $(this).val(); |
76 | 89 | // If the field is empty, show it as errored |
77 | 90 | $(this).toggleClass('error', values[v] === ""); |
| 91 | + refreshButton(); |
78 | 92 | updateText(); |
79 | 93 | }) |
80 | 94 | ) |
|
92 | 106 | if (!(v in values) || values[v] === "") { |
93 | 107 | $('#text').bind('mousedown', preventSelection); |
94 | 108 | $('#text').prop('readonly', true); |
| 109 | + buttonNotReady(); |
95 | 110 | } |
96 | 111 |
|
97 | 112 | // fuck JavaScript |
|
119 | 134 |
|
120 | 135 | $.get('/templates/' + encodeURI(page), function(newText) { |
121 | 136 | text = newText; |
| 137 | + refreshButton(); |
122 | 138 | updateText(); |
123 | 139 | }); |
124 | 140 | } |
|
142 | 158 | }); |
143 | 159 |
|
144 | 160 | $(window).on('hashchange', updatePage); |
| 161 | + refreshButton(); |
145 | 162 | updateText(); |
146 | 163 | updatePage(); |
147 | 164 | }); |
| 165 | + |
| 166 | + const copy_button = document.getElementById("button"); |
| 167 | + |
| 168 | + window.copyText = () => { |
| 169 | + const copy_button = document.getElementById("button"); |
| 170 | + // Copy text to clipboard onclick. |
| 171 | + if (copy_button.className == 'notready') { |
| 172 | + buttonNotReady(); |
| 173 | + } |
| 174 | + else { |
| 175 | + const copyText = document.getElementById("text"); |
| 176 | + const title = document.getElementById("title"); |
| 177 | + navigator.clipboard.writeText(copyText.value); |
| 178 | + |
| 179 | + // Button text change from "Copy Text" to "Copied", and text turns grey. |
| 180 | + copy_button.innerHTML = 'Copied'; |
| 181 | + copy_button.className = 'copied'; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + window.refreshButton = () => { |
| 186 | + copy_button.innerHTML = 'Copy Text'; |
| 187 | + copy_button.className = 'fresh'; |
| 188 | + } |
| 189 | + |
| 190 | + window.buttonNotReady = () => { |
| 191 | + copy_button.innerHTML = 'Not all fields are filled'; |
| 192 | + copy_button.className = 'notready'; |
| 193 | + } |
148 | 194 | })(); |
| 195 | + |
| 196 | + |
149 | 197 | </script> |
150 | 198 | </body> |
151 | 199 | </html> |
0 commit comments