From 92cc48bd18c2df11281fe297237a3bffd705639e Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Thu, 10 Oct 2024 11:55:22 -0700 Subject: [PATCH 1/2] Add persisting class to toggled block on first toggle --- build/view.asset.php | 2 +- build/view.js | 2 +- src/view.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/build/view.asset.php b/build/view.asset.php index 9526b42..30559ac 100644 --- a/build/view.asset.php +++ b/build/view.asset.php @@ -1 +1 @@ - array(), 'version' => '6b7ecb7568166b83bfb7'); + array(), 'version' => 'ce526b75a97af67a6dd1'); diff --git a/build/view.js b/build/view.js index 0ca8f40..20de6f5 100644 --- a/build/view.js +++ b/build/view.js @@ -1 +1 @@ -(()=>{{const t=t=>{const e=t.target.getAttribute("aria-controls");if(!e)return;const a=document.getElementById(e);a&&(t.target.classList.contains("toggle-block-has-toggled")||t.target.classList.add("toggle-block-has-toggled"),a.classList.contains("toggle-block-hidden")?(t.target.setAttribute("aria-pressed","true"),t.target.setAttribute("aria-expanded","true"),a.classList.remove("toggle-block-hidden")):(t.target.setAttribute("aria-pressed","false"),t.target.setAttribute("aria-expanded","false"),a.classList.add("toggle-block-hidden")))};document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll(".wp-block-happyprime-toggle-block").forEach((e=>{const a=e.getAttribute("aria-controls");if(!a)return;const s=document.getElementById(a);s&&(s.classList.contains("toggle-block-hidden")?(e.setAttribute("aria-pressed","false"),e.setAttribute("aria-expanded","false")):(e.setAttribute("aria-pressed","true"),e.setAttribute("aria-expanded","true")),e.addEventListener("click",t))}))}))}})(); \ No newline at end of file +(()=>{{const t=t=>{const e=t.target.getAttribute("aria-controls");if(!e)return;const s=document.getElementById(e);s&&(t.target.classList.contains("toggle-block-has-toggled")||t.target.classList.add("toggle-block-has-toggled"),s.classList.contains("toggle-block-has-been-toggled")||s.classList.add("toggle-block-has-been-toggled"),s.classList.contains("toggle-block-hidden")?(t.target.setAttribute("aria-pressed","true"),t.target.setAttribute("aria-expanded","true"),s.classList.remove("toggle-block-hidden")):(t.target.setAttribute("aria-pressed","false"),t.target.setAttribute("aria-expanded","false"),s.classList.add("toggle-block-hidden")))};document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll(".wp-block-happyprime-toggle-block").forEach((e=>{const s=e.getAttribute("aria-controls");if(!s)return;const a=document.getElementById(s);a&&(a.classList.contains("toggle-block-hidden")?(e.setAttribute("aria-pressed","false"),e.setAttribute("aria-expanded","false")):(e.setAttribute("aria-pressed","true"),e.setAttribute("aria-expanded","true")),e.addEventListener("click",t))}))}))}})(); \ No newline at end of file diff --git a/src/view.js b/src/view.js index b8187a4..6aae422 100644 --- a/src/view.js +++ b/src/view.js @@ -19,6 +19,15 @@ evt.target.classList.add( 'toggle-block-has-toggled' ); } + /** + * Add a persisting class to the toggled block when it is + * toggled for the first time to flag that it has, at one + * point in its history, been toggled. + */ + if ( ! toggledBlock.classList.contains( 'toggle-block-has-been-toggled' ) ) { + toggledBlock.classList.add( 'toggle-block-has-been-toggled' ); + } + if ( toggledBlock.classList.contains( 'toggle-block-hidden' ) ) { evt.target.setAttribute( 'aria-pressed', 'true' ); evt.target.setAttribute( 'aria-expanded', 'true' ); From 54cb2ec650fbb83da835c2d1ae588deaa24967a0 Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Thu, 10 Oct 2024 11:58:43 -0700 Subject: [PATCH 2/2] Bump 0.3.1 --- README.md | 12 ++++++++++++ composer.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- plugin.php | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a109139..a18d8c4 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,15 @@ When the toggle block is selected in the editor, toggle settings appear in the s The "Controls ID" entered in this panel must match the "HTML anchor" assigned to another block through its advanced panel: A screenshot of the sidebar panel in the block editor with a text input for HTML anchor + +## Changelog + +### 0.3.1 + +* Add persisting `toggle-block-has-been-toggled` class to toggled element when first toggled. + +### 0.3.0 + +* Add persisting `toggle-block-has-toggled` class to toggle button when first clicked. +* Update `@wordpress/scripts` to 27.7.0. +* Update project dependencies. diff --git a/composer.json b/composer.json index 208a38f..a254f6f 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "happyprime/toggle-block", "description": "Add a toggle to show and hide another block.", - "version": "0.3.0", + "version": "0.3.1", "type": "wordpress-plugin", "minimum-stability": "stable", "license": "GPLv2-or-later", diff --git a/package-lock.json b/package-lock.json index 26bfc99..806f312 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "toggle-block", - "version": "0.3.0", + "version": "0.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "toggle-block", - "version": "0.3.0", + "version": "0.3.1", "license": "GPL-2.0-or-later", "devDependencies": { "@wordpress/scripts": "^27.8.0" diff --git a/package.json b/package.json index 9ba1bc1..c5c99b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "toggle-block", - "version": "0.3.0", + "version": "0.3.1", "description": "Add a toggle to show and hide another block", "author": "Happy Prime", "license": "GPL-2.0-or-later", diff --git a/plugin.php b/plugin.php index 8c7c490..79d3d12 100644 --- a/plugin.php +++ b/plugin.php @@ -2,7 +2,7 @@ /** * Plugin Name: Toggle Block * Description: Add a toggle to show and hide another block. - * Version: 0.3.0 + * Version: 0.3.1 * Plugin URI: https://github.com/happyprime/toggle-block/ * Author: Happy Prime * Author URI: https://happyprime.co