-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
195 additions
and
71 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
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
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,17 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "create-block/example-static", | ||
"version": "0.1.0", | ||
"title": "Example Static", | ||
"category": "widgets", | ||
"icon": "smiley", | ||
"description": "Example block scaffolded with Create Block tool.", | ||
"supports": { | ||
"html": false | ||
}, | ||
"textdomain": "example-static", | ||
"editorScript": "file:./index.js", | ||
"editorStyle": "file:./index.css", | ||
"style": "file:./style-index.css" | ||
} |
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,38 @@ | ||
/** | ||
* Retrieves the translation of text. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/ | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* React hook that is used to mark the block wrapper element. | ||
* It provides all the necessary props like the class name. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | ||
* Those files can contain any CSS code that gets applied to the editor. | ||
* | ||
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | ||
*/ | ||
import './editor.scss'; | ||
|
||
/** | ||
* The edit function describes the structure of your block in the context of the | ||
* editor. This represents what the editor will render when the block is used. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit | ||
* | ||
* @return {WPElement} Element to render. | ||
*/ | ||
export default function Edit() { | ||
return ( | ||
<p { ...useBlockProps() }> | ||
{ __( 'Example Static – hello from the editor!', 'example-static' ) } | ||
</p> | ||
); | ||
} |
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,9 @@ | ||
/** | ||
* The following styles get applied inside the editor only. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-create-block-example-static { | ||
border: 1px dotted #f00; | ||
} |
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,39 @@ | ||
/** | ||
* Registers a new block provided a unique name and an object defining its behavior. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | ||
* All files containing `style` keyword are bundled together. The code used | ||
* gets applied both to the front of your site and to the editor. | ||
* | ||
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | ||
*/ | ||
import './style.scss'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Edit from './edit'; | ||
import save from './save'; | ||
import metadata from './block.json'; | ||
|
||
/** | ||
* Every block starts by registering a new block type definition. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ | ||
*/ | ||
registerBlockType( metadata.name, { | ||
/** | ||
* @see ./edit.js | ||
*/ | ||
edit: Edit, | ||
|
||
/** | ||
* @see ./save.js | ||
*/ | ||
save, | ||
} ); |
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 @@ | ||
/** | ||
* React hook that is used to mark the block wrapper element. | ||
* It provides all the necessary props like the class name. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* The save function defines the way in which the different attributes should | ||
* be combined into the final markup, which is then serialized by the block | ||
* editor into `post_content`. | ||
* | ||
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save | ||
* | ||
* @return {WPElement} Element to render. | ||
*/ | ||
export default function save() { | ||
return ( | ||
<p { ...useBlockProps.save() }> | ||
{ 'Example Static – hello from the saved content!' } | ||
</p> | ||
); | ||
} |
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,12 @@ | ||
/** | ||
* The following styles get applied both on the front of your site | ||
* and in the editor. | ||
* | ||
* Replace them with your own styles or remove the file completely. | ||
*/ | ||
|
||
.wp-block-create-block-example-static { | ||
background-color: #21759b; | ||
color: #fff; | ||
padding: 2px; | ||
} |
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 |
---|---|---|
@@ -1,63 +1,24 @@ | ||
const expandCollapses = document.querySelectorAll( '.expand-collapse' ); | ||
if ( expandCollapses ) | ||
expandCollapses.forEach( ( expandCollapse ) => { | ||
expandCollapse.addEventListener( 'click', () => { | ||
const currentAction = expandCollapse.getAttribute( 'id' ); | ||
if ( currentAction === 'expand' ) { | ||
expandCollapse.setAttribute( 'id', 'collapse' ); | ||
const expandCollapses = document.querySelectorAll('.expand-collapse'); | ||
if (expandCollapses) | ||
expandCollapses.forEach((expandCollapse) => { | ||
expandCollapse.addEventListener('click', () => { | ||
const currentAction = expandCollapse.getAttribute('id'); | ||
if (currentAction === 'expand') { | ||
expandCollapse.setAttribute('id', 'collapse'); | ||
expandCollapse.innerHTML = 'Collapse All'; | ||
} else { | ||
expandCollapse.setAttribute( 'id', 'expand' ); | ||
expandCollapse.setAttribute('id', 'expand'); | ||
expandCollapse.innerHTML = 'Expand All'; | ||
} | ||
|
||
expandCollapse.parentElement | ||
.querySelectorAll( 'details' ) | ||
.forEach( ( accItem, i ) => { | ||
if ( currentAction === 'expand' ) { | ||
accItem.setAttribute( 'open', true ); | ||
expandCollapse.parentElement.parentElement | ||
.querySelectorAll('details') | ||
.forEach((accItem, i) => { | ||
if (currentAction === 'expand') { | ||
accItem.setAttribute('open', true); | ||
} else { | ||
accItem.removeAttribute( 'open' ); | ||
accItem.removeAttribute('open'); | ||
} | ||
} ); | ||
} ); | ||
} ); | ||
|
||
const details = document.querySelectorAll( '.accordion-wrapper details' ); | ||
if ( details ) | ||
details.forEach( ( detail ) => { | ||
detail.addEventListener( 'toggle', ( e ) => { | ||
const currentAccWrapper = e.target.parentElement.parentElement; | ||
const expandCollapse = | ||
currentAccWrapper.querySelector( '.expand-collapse' ); | ||
const currentAction = expandCollapse.getAttribute( 'id' ); | ||
|
||
if ( currentAction === 'expand' ) { | ||
if ( allOpen( currentAccWrapper ) ) { | ||
expandCollapse.setAttribute( 'id', 'collapse' ); | ||
expandCollapse.innerHTML = 'Collapse All'; | ||
} | ||
} else { | ||
if ( allClosed( currentAccWrapper ) ) { | ||
expandCollapse.setAttribute( 'id', 'expand' ); | ||
expandCollapse.innerHTML = 'Expand All'; | ||
} | ||
} | ||
} ); | ||
} ); | ||
|
||
function allOpen( currentAccWrapper ) { | ||
let allOpenRet = true; | ||
currentAccWrapper.querySelectorAll( 'details' ).forEach( ( detail ) => { | ||
if ( ! detail.open ) allOpenRet = false; | ||
} ); | ||
return allOpenRet; | ||
} | ||
|
||
function allClosed( currentAccWrapper ) { | ||
let allClosedRet = true; | ||
currentAccWrapper.querySelectorAll( 'details' ).forEach( ( detail ) => { | ||
if ( detail.open ) allClosedRet = false; | ||
} ); | ||
return allClosedRet; | ||
} | ||
}); | ||
}); | ||
}); |