This update replaces the horrible text based copy script buttons on the Linux package
download pages with nice icons, add a variant that copies the code without the sudo
prefixes, and tidies up the styling in general.
position: relative;
}
+.pg-script-container pre.code {
+ padding-right: 4rem;
+ min-height: 3.5rem;
+ display: flex;
+ align-items: center;
+}
+
.pg-script-copy-btn {
position: absolute;
- top: 8px;
- right: 8px;
+ top: 0.5rem;
+ right: 0.5rem;
+ background: transparent;
+ border: none;
+ font-size: 1rem;
+ padding: 4px 6px;
+ cursor: pointer;
+ transition: color 0.2s;
+}
+
+.pg-script-copy-btn-root {
+ right: 2rem;
+}
+
+.pg-script-copy-btn i {
+ color: #555 !important;
+ margin: 0 !important;
+ transition: color 0.2s;
+}
+
+.pg-script-copy-btn:hover i {
+ color: #336791 !important;
+}
+
+.pg-script-copy-btn.copied i {
+ color: #28a745 !important;
+}
+
+[data-theme="dark"] .pg-script-copy-btn i {
+ color: #ccc !important;
+}
+
+[data-theme="dark"] .pg-script-copy-btn:hover i {
+ color: #fff !important;
+}
+
+[data-theme="dark"] .pg-script-copy-btn.copied i {
+ color: #7dff7d !important;
}
.nobr {
copyScript(this, 'script-box');
});
}
+ if (document.getElementById("copy-btn-root") && document.getElementById("script-box")) {
+ document.getElementById('copy-btn-root').addEventListener('click', function () {
+ copyScript(this, 'script-box', true);
+ });
+ }
if (document.getElementById("copy-btn2") && document.getElementById("script-box2")) {
document.getElementById('copy-btn2').addEventListener('click', function () {
copyScript(this, 'script-box2');
});
}
+ if (document.getElementById("copy-btn2-root") && document.getElementById("script-box2")) {
+ document.getElementById('copy-btn2-root').addEventListener('click', function () {
+ copyScript(this, 'script-box2', true);
+ });
+ }
if (document.getElementById("copy-btn3") && document.getElementById("script-box3")) {
document.getElementById('copy-btn3').addEventListener('click', function () {
copyScript(this, 'script-box3');
});
}
+ if (document.getElementById("copy-btn3-root") && document.getElementById("script-box3")) {
+ document.getElementById('copy-btn3-root').addEventListener('click', function () {
+ copyScript(this, 'script-box3', true);
+ });
+ }
}
document.addEventListener("DOMContentLoaded", setupHandlers);
/* Copy a script from an HTML element to the clipboard,
* removing comments and blank lines.
* Arguments:
- * trigger: The button calling the function, whose label will be updated
+ * trigger: The button calling the function, whose icon will be updated
* elem: The element containing the script to copy
+ * stripSudo: If true, remove 'sudo ' from the start of lines
*/
-function copyScript(trigger, elem) {
- var raw = document.getElementById(elem).innerHTML;
+function copyScript(trigger, elem, stripSudo = false) {
+ const raw = document.getElementById(elem).innerHTML;
// Create a scratch div to copy from
- var scratch = document.createElement("div");
+ const scratch = document.createElement("div");
document.body.appendChild(scratch);
// Copy the contents of the script box into the scratch div, removing
- // comments and blank lines
- var lines = raw.split("\n");
- var output = '';
- for (var l = 0; l < lines.length; l++) {
- if (lines[l][0] != '#' && lines[l].trim() != '')
- output += lines[l] + '<br />';
+ // comments and blank lines, and optionally stripping sudo
+ const lines = raw.split("\n");
+ let output = '';
+ for (let l = 0; l < lines.length; l++) {
+ if (lines[l][0] != '#' && lines[l].trim() != '') {
+ let line = lines[l];
+ if (stripSudo) {
+ line = line.replace(/^(\s*)sudo /, '$1');
+ }
+ output += line + '<br />';
+ }
}
scratch.innerHTML = output.trim();
// Perform the copy
if(document.body.createTextRange) {
// IE 11
- var range = document.body.createTextRange();
+ const range = document.body.createTextRange();
range.moveToElementText(scratch);
range.select();
document.execCommand("Copy");
}
else if(window.getSelection) {
// Sane browsers
- var selection = window.getSelection();
- var range = document.createRange();
+ const selection = window.getSelection();
+ const range = document.createRange();
range.selectNodeContents(scratch);
selection.removeAllRanges();
selection.addRange(range);
scratch.parentNode.removeChild(scratch);
// Indicate to the user that the script was copied
- var label = trigger.innerHTML;
- trigger.innerHTML = 'Copied!';
+ const icon = trigger.querySelector('i');
+ const originalClass = stripSudo ? 'fa-terminal' : 'fa-copy';
+ icon.classList.remove(originalClass);
+ icon.classList.add('fa-check');
+ trigger.classList.add('copied');
setTimeout(function() {
- trigger.innerHTML = label;
+ icon.classList.remove('fa-check');
+ icon.classList.add(originalClass);
+ trigger.classList.remove('copied');
}, 3000);
}
if (!ver || ver === "-1") {
document.getElementById('copy-btn').style.display = 'none';
+ document.getElementById('copy-btn-root').style.display = 'none';
scriptBox.innerHTML = 'Select platform, architecture, and version above';
return;
}
}
document.getElementById('copy-btn').style.display = 'block';
+ document.getElementById('copy-btn-root').style.display = 'block';
}
/* Event handlers */
document.getElementById('copy-btn').addEventListener('click', function () {
copyScript(this, 'script-box');
});
+ document.getElementById('copy-btn-root').addEventListener('click', function () {
+ copyScript(this, 'script-box', true);
+ });
document.getElementById('version').addEventListener('change', verChanged);
document.getElementById('platform').addEventListener('change', platChanged);
document.getElementById('arch').addEventListener('change', archChanged);
<div class="pg-script-container">
<pre id="script-box" class="code">sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh</pre>
- <button id="copy-btn" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
<p>
# Update the package lists:
sudo apt update</pre>
- <button id="copy-btn2" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn2-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn2" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
Install PostgreSQL: (replace "18" by the version you want)
<div class="pg-script-container">
<pre id="script-box3" class="code">sudo apt install postgresql-18</pre>
- <button id="copy-btn3" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn3-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn3" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
<p>
<li>Copy, paste and run the relevant parts of the setup script:
<div class="pg-script-container">
<pre id="script-box" class="code"></pre>
- <button id="copy-btn" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
</li>
</ol>
<div class="pg-script-container">
<pre id="script-box" class="code">sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh</pre>
- <button id="copy-btn" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
<p>
# Update the package lists:
sudo apt update</pre>
- <button id="copy-btn2" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn2-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn2" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
Install PostgreSQL: (replace "18" by the version you want)
<div class="pg-script-container">
<pre id="script-box3" class="code">sudo apt install postgresql-18</pre>
- <button id="copy-btn3" class="pg-script-copy-btn">Copy Script</button>
+ <button id="copy-btn3-root" class="pg-script-copy-btn pg-script-copy-btn-root" title="Copy to clipboard (without sudo, for root)"><i class="fas fa-terminal"></i></button>
+ <button id="copy-btn3" class="pg-script-copy-btn" title="Copy to clipboard"><i class="far fa-copy"></i></button>
</div>
<p>