diff options
Diffstat (limited to 'p')
| -rw-r--r-- | p/scripts/extra.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/p/scripts/extra.js b/p/scripts/extra.js index 6f896f959..43bbd89f5 100644 --- a/p/scripts/extra.js +++ b/p/scripts/extra.js @@ -395,11 +395,14 @@ function close_slider_listener(ev) { } // </slider> -// overwrites the href attribute from the url input +// updates href from the input value, with optional prefix/encoding function updateHref(ev) { const urlField = document.getElementById(this.getAttribute('data-input')); - const url = urlField.value; - if (url.length > 0) { + const rawUrl = urlField.value; + const prefix = this.getAttribute('data-prefix') || ''; + const shouldEncode = this.getAttribute('data-encode') === '1'; + const url = prefix + (shouldEncode ? encodeURIComponent(rawUrl) : rawUrl); + if (rawUrl.length > 0) { this.href = url; return true; } else { |
