Skip to content

Commit

Permalink
feat: add copy to clipboard for pagelist id+tpl
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jan 6, 2024
1 parent 7dd15de commit 2e4a077
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
46 changes: 32 additions & 14 deletions RockMigrations.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
// // fix language tabs sometimes not having the correct language
// // todo make that a selectable tweak
// $(window).on("load", () => {
// if (typeof ProcessWire == "undefined") return;
// if (typeof ProcessWire.config == "undefined") return;
// if (typeof ProcessWire.config.rmUserLang == "undefined") return;
// let lang = ProcessWire.config.rmUserLang;
// setTimeout(() => {
// let tabs = $(".langTab" + lang);
// if (!tabs.length) return;
// tabs.trigger("click");
// console.log("LanguageTabs set via RockMigrations");
// }, 200);
// });
/**
* This file is loaded in the PW backend
*/

// add tooltips in the backend
$(document).ready(() => {
Expand All @@ -30,3 +19,32 @@ $(document).ready(() => {
addTooltip(el);
});
});

// copy page id and template name on click (if tweaks are enabled)
$(document).on("mousedown", ".PageListTemplate, .PageListId", (e) => {
if (!e.shiftKey) return;
let el = e.target;

// trim content
let contentToCopy = $(el).text().trim();
if (contentToCopy.startsWith("#")) {
contentToCopy = contentToCopy.substring(1);
}
if (contentToCopy.startsWith("[") && contentToCopy.endsWith("]")) {
contentToCopy = contentToCopy.substring(1, contentToCopy.length - 1);
}

// copy to clipboard
const textarea = document.createElement("textarea");
textarea.value = contentToCopy;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);

// show notification
UIkit.tooltip(el).hide();
UIkit.notification("Copied " + contentToCopy + " to clipboard", {
status: "success",
});
});
2 changes: 1 addition & 1 deletion tweaks/PageListShowIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function hookPageLabel(HookEvent $event)

// regular page list
$page = $event->arguments('page');
$event->return .= "<span class='PageListId'>#$page</span>";
$event->return .= "<span class='PageListId' title='Shift-Click to copy' uk-tooltip>#$page</span>";
}
}
2 changes: 1 addition & 1 deletion tweaks/PageListShowTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public function hookPageLabel(HookEvent $event)

// regular page list
$page = $event->arguments('page');
$event->return .= "<span class='PageListTemplate'>[{$page->template}]</span>";
$event->return .= "<span class='PageListTemplate' title='Shift-Click to copy' uk-tooltip>[{$page->template}]</span>";
}
}

0 comments on commit 2e4a077

Please sign in to comment.