-
Notifications
You must be signed in to change notification settings - Fork 90
feature: FAQ section and shortcode (recover #309) #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* DESCRIPTION: Frontend styles for the FAQ shortcode section | ||
| * and the [wedocs_faq] shortcode output. */ | ||
|
|
||
| .wedocs-faq-section { | ||
| margin-top: 40px; | ||
| padding-top: 30px; | ||
| border-top: 1px solid #e5e7eb; | ||
| } | ||
|
|
||
| .wedocs-faq-section__title { | ||
| font-size: 24px; | ||
| font-weight: 600; | ||
| margin-bottom: 24px; | ||
| } | ||
|
|
||
| .wedocs-faq-group { | ||
| margin-bottom: 24px; | ||
| } | ||
|
|
||
| .wedocs-faq-group__title { | ||
| font-size: 18px; | ||
| font-weight: 600; | ||
| margin-bottom: 12px; | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .wedocs-faq-group__icon { | ||
| width: 24px; | ||
| height: 24px; | ||
| object-fit: contain; | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .wedocs-faq-item { | ||
| border: 1px solid #e5e7eb; | ||
| border-radius: 6px; | ||
| margin-bottom: 8px; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .wedocs-faq-item__question { | ||
| padding: 14px 18px; | ||
| cursor: pointer; | ||
| font-weight: 500; | ||
| font-size: 15px; | ||
| list-style: none; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: space-between; | ||
| } | ||
|
|
||
| .wedocs-faq-item__question::-webkit-details-marker { | ||
| display: none; | ||
| } | ||
|
|
||
| .wedocs-faq-item__question::after { | ||
| content: '+'; | ||
| font-size: 20px; | ||
| font-weight: 300; | ||
| color: #6b7280; | ||
| transition: transform 0.3s ease; | ||
| } | ||
|
|
||
| .wedocs-faq-item[open] .wedocs-faq-item__question::after { | ||
| content: '\2212'; | ||
| } | ||
|
|
||
| .wedocs-faq-item__answer { | ||
| display: grid; | ||
| grid-template-rows: 0fr; | ||
| transition: grid-template-rows 0.3s ease; | ||
| } | ||
|
|
||
| .wedocs-faq-item[open] .wedocs-faq-item__answer { | ||
| grid-template-rows: 1fr; | ||
| } | ||
|
|
||
| .wedocs-faq-item__answer-inner { | ||
| overflow: hidden; | ||
| padding: 0 18px; | ||
| font-size: 14px; | ||
| line-height: 1.6; | ||
| color: #4b5563; | ||
| } | ||
|
|
||
| .wedocs-faq-item[open] .wedocs-faq-item__answer-inner { | ||
| padding-bottom: 14px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // DESCRIPTION: Smooth expand/collapse transitions for FAQ <details> | ||
| // elements rendered by the [wedocs_faq] shortcode. | ||
|
|
||
| document.addEventListener( 'DOMContentLoaded', function () { | ||
| document.querySelectorAll( '.wedocs-faq-item' ).forEach( function ( details ) { | ||
| var summary = details.querySelector( '.wedocs-faq-item__question' ); | ||
| var answer = details.querySelector( '.wedocs-faq-item__answer' ); | ||
|
|
||
| // Items open by default need the inline style set so transitions work. | ||
| if ( details.open ) { | ||
| answer.style.gridTemplateRows = '1fr'; | ||
| } | ||
|
|
||
| summary.addEventListener( 'click', function ( e ) { | ||
| e.preventDefault(); | ||
|
|
||
| if ( details.open ) { | ||
| // Closing: let the transition finish before removing open. | ||
| answer.style.gridTemplateRows = '0fr'; | ||
| answer.addEventListener( 'transitionend', function handler() { | ||
| details.open = false; | ||
| answer.removeEventListener( 'transitionend', handler ); | ||
| } ); | ||
| } else { | ||
| // Opening: set open first so content is measurable, then animate. | ||
| details.open = true; | ||
| // Force a reflow so the browser registers the 0fr starting state. | ||
| answer.offsetHeight; // eslint-disable-line no-unused-expressions | ||
| answer.style.gridTemplateRows = '1fr'; | ||
| } | ||
| } ); | ||
| } ); | ||
| } ); | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,8 @@ public function register_scripts() { | |||||||||
| // All scripts goes here | ||||||||||
| wp_register_script( 'wedocs-anchorjs', WEDOCS_ASSETS . '/js/anchor.min.js', [ 'jquery' ], WEDOCS_VERSION, true ); | ||||||||||
| wp_register_script( 'wedocs-scripts', WEDOCS_ASSETS . '/js/frontend.js', [ 'jquery', 'wedocs-anchorjs' ], filemtime( WEDOCS_PATH . '/assets/js/frontend.js' ), true ); | ||||||||||
| wp_register_style( 'wedocs-faq', WEDOCS_ASSETS . '/css/faq.css', [], filemtime( WEDOCS_PATH . '/assets/css/faq.css' ) ); | ||||||||||
| wp_register_script( 'wedocs-faq', WEDOCS_ASSETS . '/js/faq.js', [], filemtime( WEDOCS_PATH . '/assets/js/faq.js' ), true ); | ||||||||||
|
Comment on lines
+76
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for If the CSS or JS files don't exist, 🛡️ Proposed fix with fallback versioning- wp_register_style( 'wedocs-faq', WEDOCS_ASSETS . '/css/faq.css', [], filemtime( WEDOCS_PATH . '/assets/css/faq.css' ) );
- wp_register_script( 'wedocs-faq', WEDOCS_ASSETS . '/js/faq.js', [], filemtime( WEDOCS_PATH . '/assets/js/faq.js' ), true );
+ wp_register_style( 'wedocs-faq', WEDOCS_ASSETS . '/css/faq.css', [], filemtime( WEDOCS_PATH . '/assets/css/faq.css' ) ?: WEDOCS_VERSION );
+ wp_register_script( 'wedocs-faq', WEDOCS_ASSETS . '/js/faq.js', [], filemtime( WEDOCS_PATH . '/assets/js/faq.js' ) ?: WEDOCS_VERSION, true );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| $store_dependencies = require WEDOCS_PATH . '/assets/build/store.asset.php'; | ||||||||||
| wp_register_script( 'wedocs-store-js', WEDOCS_ASSETS . '/build/store.js', $store_dependencies['dependencies'], $store_dependencies['version'], true ); | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add null checks for querySelector results.
If the expected DOM structure is missing,
querySelectorwill returnnulland subsequent property accesses will throwTypeError. Add defensive checks to prevent runtime errors.🛡️ Proposed fix with null checks
document.querySelectorAll( '.wedocs-faq-item' ).forEach( function ( details ) { var summary = details.querySelector( '.wedocs-faq-item__question' ); var answer = details.querySelector( '.wedocs-faq-item__answer' ); + + if ( ! summary || ! answer ) { + return; + } // Items open by default need the inline style set so transitions work. if ( details.open ) {📝 Committable suggestion
🤖 Prompt for AI Agents