Skip to content

Commit b001f0b

Browse files
authored
Ensure that the Expand button is not copied when clicking the copy button (#25)
1 parent b06068f commit b001f0b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `meta-inspector` will be documented in this file.
44

5+
## 1.1.2 - 2024-01-08
6+
7+
- Fix issue with the "Expand" button being copied when clicking the "Copy" button.
8+
59
## 1.1.1 - 2023-06-28
610

711
- Add click to copy functionality to the meta keys and values.

inc/class-table.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ function ( $row ) {
120120
*/
121121
public static function get_max_pre_height(): int {
122122
/**
123-
* Filter the max height of a pre element before it is collapsed (in
124-
* pixels) with a default of 400 and a minimum of 100.
123+
* Filter the max height of a pre element before it is collapsed
124+
* (in pixels) with a default of 400px and a minimum of 100px.
125125
*
126126
* @param int $max_pre_height The max height of a pre element before it is collapsed.
127127
*/
@@ -224,11 +224,13 @@ public static function output_footer(): void {
224224
var copyButtons = document.querySelectorAll('.meta-inspector button.copy-button')
225225
copyButtons.forEach(function(button) {
226226
button.addEventListener('click', function (event) {
227-
navigator.clipboard.writeText(this.parentNode.innerText);
227+
var pre = this.parentNode.querySelector('pre');
228+
229+
navigator.clipboard.writeText(pre ? pre.innerText : this.parentNode.innerText);
228230
this.classList.add('copied');
229231

230232
var previousLabel = this.getAttribute('aria-label');
231-
this.setAttribute('aria-label', <?php echo wp_json_encode( esc_attr__( 'Copied', 'meta-inspector' ) ); ?>);
233+
this.setAttribute('aria-label', <?php echo wp_json_encode( __( 'Copied', 'meta-inspector' ) ); ?>);
232234

233235
setTimeout(function() {
234236
button.classList.remove('copied');
@@ -242,7 +244,7 @@ public static function output_footer(): void {
242244
// Collapse pre elements that are taller than the max height.
243245
document.querySelectorAll('.meta-inspector pre').forEach(function(pre) {
244246
var expandLink = pre.parentNode.querySelector('.expand-link');
245-
console.log('pre', jQuery(pre).height(), maxPreHeight);
247+
246248
if (pre.clientHeight < maxPreHeight) {
247249
// Remove the expand link if the pre element is not tall enough.
248250
if (expandLink) {

meta-inspector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* Plugin Name: Meta Inspector
44
* Description: View various types of meta data about WordPress objects to assist debugging.
55
* Author: alleyinteractive, jameswalterburke
6-
* Author URI: https://alley.com
6+
* Author URI: https://alley.com/
77
* Text Domain: meta-inspector
8-
* Domain Path: /languages
9-
* Version: 1.1.1
8+
* Version: 1.1.2
109
*
1110
* @package Meta_Inspector
1211
*/

0 commit comments

Comments
 (0)