|
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | 5 | var forEach = Array.prototype.forEach, |
6 | | - filter = Array.prototype.filter; |
| 6 | + filter = Array.prototype.filter, |
| 7 | + sections = document.querySelectorAll('.section'), |
| 8 | + url = require('url'), |
| 9 | + Clipboard = require('clipboard'); |
7 | 10 |
|
8 | 11 | function expandAll() { |
9 | 12 | loadLazyImages(document, '.section_collapsed img'); |
10 | | - forEach.call(document.querySelectorAll('.section'), function(section) { |
| 13 | + forEach.call(sections, function(section) { |
11 | 14 | section.classList.remove('section_collapsed'); |
12 | 15 | }); |
13 | 16 | } |
14 | 17 |
|
15 | 18 | function collapseAll() { |
16 | | - forEach.call(document.querySelectorAll('.section'), function(section) { |
| 19 | + forEach.call(sections, function(section) { |
17 | 20 | section.classList.add('section_collapsed'); |
18 | 21 | }); |
19 | 22 | } |
20 | 23 |
|
21 | 24 | function expandErrors() { |
22 | 25 | loadLazyImages(document, '.section_status_fail > .section__body > .image-box img'); |
23 | 26 | loadLazyImages(document, '.section_status_warning > .section__body > .image-box img'); |
24 | | - forEach.call(document.querySelectorAll('.section'), function(section) { |
| 27 | + forEach.call(sections, function(section) { |
25 | 28 | if (section.classList.contains('section_status_fail') || |
26 | 29 | section.classList.contains('section_status_warning')) { |
27 | 30 | section.classList.remove('section_collapsed'); |
|
33 | 36 |
|
34 | 37 | function expandRetries() { |
35 | 38 | loadLazyImages(document, '.has-retries > .section__body > .image-box img'); |
36 | | - forEach.call(document.querySelectorAll('.section'), function(section) { |
| 39 | + forEach.call(sections, function(section) { |
37 | 40 | if (section.classList.contains('has-retries')) { |
38 | 41 | section.classList.remove('section_collapsed'); |
39 | 42 | } else { |
|
125 | 128 | document.getElementById('skippedList').classList.toggle('collapsed'); |
126 | 129 | } |
127 | 130 |
|
| 131 | + function handleHostChange() { |
| 132 | + var textInput = document.getElementById('viewHostInput'); |
| 133 | + var viewButtons = document.querySelectorAll('.section__icon_view-local'); |
| 134 | + |
| 135 | + textInput.addEventListener('change', function() { |
| 136 | + setViewLinkHost(textInput.value); |
| 137 | + // will save host to local storage |
| 138 | + if (window.localStorage) { |
| 139 | + window.localStorage.setItem('_gemini-replace-host', textInput.value); |
| 140 | + } |
| 141 | + }); |
| 142 | + |
| 143 | + // read saved host from local storage |
| 144 | + if (window.localStorage) { |
| 145 | + var host = window.localStorage.getItem('_gemini-replace-host'); |
| 146 | + if (host) { |
| 147 | + setViewLinkHost(host); |
| 148 | + textInput.value = host; |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + function setViewLinkHost(host) { |
| 153 | + viewButtons.forEach(function(item) { |
| 154 | + var href = item.dataset.suiteViewLink, |
| 155 | + parsedHost; |
| 156 | + |
| 157 | + if (host) { |
| 158 | + parsedHost = url.parse(host, false, true); |
| 159 | + // extending current url from entered host |
| 160 | + href = url.format(Object.assign( |
| 161 | + url.parse(href), |
| 162 | + { |
| 163 | + host: parsedHost.slashes ? parsedHost.host : host, |
| 164 | + protocol: parsedHost.slashes ? parsedHost.protocol : null, |
| 165 | + hostname: null, |
| 166 | + port: null |
| 167 | + } |
| 168 | + )); |
| 169 | + } |
| 170 | + item.setAttribute('href', href); |
| 171 | + }); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + function handleClipboard() { |
| 176 | + forEach.call(document.querySelectorAll('.section__icon_copy-to-clipboard'), function(clipboard) { |
| 177 | + /* eslint-disable no-new */ |
| 178 | + new Clipboard(clipboard); |
| 179 | + }); |
| 180 | + } |
| 181 | + |
128 | 182 | document.addEventListener('DOMContentLoaded', function() { |
129 | 183 | document.getElementById('expandAll').addEventListener('click', expandAll); |
130 | 184 | document.getElementById('collapseAll').addEventListener('click', collapseAll); |
|
140 | 194 | section.classList.toggle('section_collapsed'); |
141 | 195 | }); |
142 | 196 | }); |
| 197 | + |
| 198 | + // turning off event bubbling when click button |
| 199 | + forEach.call(document.querySelectorAll('.button'), function(button) { |
| 200 | + button.addEventListener('click', function(e) { |
| 201 | + e.stopPropagation(); |
| 202 | + }); |
| 203 | + }); |
143 | 204 | }); |
144 | 205 |
|
| 206 | + handleClipboard(); |
| 207 | + handleHostChange(); |
145 | 208 | expandErrors(); |
146 | 209 | }()); |
0 commit comments