-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe51ea8
commit 822b36b
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
$(document).ready(function () { | ||
// Copy a string to the clipboard | ||
function copyToClipboard(string) { | ||
const $temp = $('<input type="text" value="' + string + '">'); | ||
$("body").append($temp); | ||
$temp.select(); | ||
document.execCommand("copy"); | ||
$temp.remove(); | ||
} | ||
|
||
// When InputfieldHeader is clicked | ||
$(document).on("click", ".InputfieldHeader", function (event) { | ||
let text = ""; | ||
if (!event.shiftKey) return; | ||
|
||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
text = $(this).attr("for"); | ||
if (!text) text = $(this).parent().attr("id"); | ||
text = text.replace(/^Inputfield_|wrap_Inputfield_|wrap_/, "").trim(); | ||
if (!text) return; | ||
|
||
copyToClipboard(text); | ||
$(this).effect("highlight", {}, 500); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace RockMigrations\Tweaks; | ||
|
||
use ProcessWire\HookEvent; | ||
|
||
class CopyFieldNames extends Tweak | ||
{ | ||
public $description = "Copy field names on shift-click by SuperUsers " | ||
. "<a href=https://processwire.com/talk/topic/29071-using-javascript-to-copy-page-ids-from-page-list-and-field-nameslabels-from-inputfields/ target=_blank><i class='fa fa-info-circle'></i></a>"; | ||
|
||
public function init() | ||
{ | ||
// Add custom JS file to $config->scripts FilenameArray | ||
// This adds the custom JS fairly early in the FilenameArray which allows for stopping | ||
// event propagation so clicks on InputfieldHeader do not also expand/collapse InputfieldContent | ||
$this->wire->addHookBefore('ProcessController::execute', function (HookEvent $event) { | ||
if (!$event->wire->user->isSuperuser()) return; | ||
$rm = $this->rockmigrations(); | ||
$url = $rm->toUrl(__DIR__ . "/CopyFieldNames.js", true); | ||
$this->wire->config->scripts->add($url); | ||
}); | ||
} | ||
} |