diff options
author | Olivier Hallot <olivier.hallot@libreoffice.org> | 2019-04-25 11:34:05 -0300 |
---|---|---|
committer | Olivier Hallot <olivier.hallot@libreoffice.org> | 2019-04-26 20:46:16 +0200 |
commit | 3c494b6e6db198099f4641aaef3f608842d53faa (patch) | |
tree | 363947b39315cb4dfd6ac284fe46b36c4c517fb3 /help3xsl/help.js | |
parent | c1053ceff3ede558b858a30270324430c940311c (diff) |
tdf#122548 copy bascode and pycode to clipboard
This will allow easy testing of coding examples.
Change-Id: I30fc53642b1579744591f2de0c84a615d1755352
Reviewed-on: https://gerrit.libreoffice.org/71385
Tested-by: Jenkins
Reviewed-by: Olivier Hallot <olivier.hallot@libreoffice.org>
Diffstat (limited to 'help3xsl/help.js')
-rw-r--r-- | help3xsl/help.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/help3xsl/help.js b/help3xsl/help.js index 7789c17aea..59dd378c73 100644 --- a/help3xsl/help.js +++ b/help3xsl/help.js @@ -79,6 +79,41 @@ function debounce(fn, wait) { }; } search.addEventListener('keyup', debounce(filter, 100)); + +// copy pycode and bascode to clipboard on mouse click +// Show border when copy is done +divcopyable(document.getElementsByClassName("bascode")); +divcopyable(document.getElementsByClassName("pycode")); + +function divcopyable(itemcopyable){ +for (var i = 0, len = itemcopyable.length; i < len; i++) { + (function() { + var item = itemcopyable[i]; + + function changeBorder(item, color, colorToChangeBackTo) { + var saveBorder = item.style.border; + item.style.border = "solid 5px"; + item.style.borderColor = color; + + setTimeout(function() { + item.style.border = saveBorder; + item.style.borderColor = colorToChangeBackTo; + }, 150); + } + item.onclick = function() { + document.execCommand("copy"); + changeBorder(item, "#18A303", "transparent"); + }; + item.addEventListener("copy", function(event) { + event.preventDefault(); + if (event.clipboardData) { + event.clipboardData.setData("text/plain", item.textContent); + } + }); + }()); +} +} + // copy useful content to clipboard on mouse click var copyable = document.getElementsByClassName("input"); for (var i = 0, len = copyable.length; i < len; i++) { |