Improve chapter index menu
This commit is contained in:
parent
7a7ea992d3
commit
eb988ac551
25
CUSTOMIZE.md
25
CUSTOMIZE.md
@ -171,12 +171,12 @@ add_filter( 'fictioneer_filter_safe_title', 'child_modify_chapter_list_title', 1
|
||||
Or change them completely, if you want even depending on the chapter or associated story. Related to [this issue](https://github.com/Tetrakern/fictioneer/issues/31). Using a filter, you can rebuild the list item HTML to your liking. In the following example, the chapter prefix has been prepended (if there is one).
|
||||
|
||||
**References**
|
||||
* Filter: [fictioneer_filter_simple_chapter_list_item](https://github.com/Tetrakern/fictioneer/blob/main/FILTERS.md#apply_filters-fictioneer_filter_simple_chapter_list_item-item-post-args-)
|
||||
* Filter: [fictioneer_filter_chapter_index_item](https://github.com/Tetrakern/fictioneer/blob/main/FILTERS.md#apply_filters-fictioneer_filter_chapter_index_item-item-post-args-)
|
||||
* Include: [_helpers-templates.php](https://github.com/Tetrakern/fictioneer/blob/main/includes/functions/_helpers-templates.php)
|
||||
|
||||
```php
|
||||
/**
|
||||
* Overwrites the simple chapter list item string with a prefixed title
|
||||
* Overwrites the chapter index list item string with a prefixed title
|
||||
*
|
||||
* Note: Warning, this replaces the complete string and should be
|
||||
* executed early in case there are more, less extreme filters.
|
||||
@ -194,8 +194,9 @@ function child_prefix_simple_chapter_list_item( $item, $post, $args ) {
|
||||
$prefix = get_post_meta( $post->ID, 'fictioneer_chapter_prefix', true );
|
||||
|
||||
return sprintf(
|
||||
'<li class="%1$s" data-id="%2$s"><a href="%3$s">%4$s<span>%5$s%6$s</span></a></li>',
|
||||
'<li class="%1$s" data-position="%2$s" data-id="%3$s"><a href="%4$s">%5$s<span>%6$s%7$s</span></a></li>'
|
||||
implode( ' ', $args['classes'] ),
|
||||
$args['position'],
|
||||
$post->ID,
|
||||
get_the_permalink( $post->ID ),
|
||||
$args['icon'],
|
||||
@ -205,7 +206,7 @@ function child_prefix_simple_chapter_list_item( $item, $post, $args ) {
|
||||
}
|
||||
|
||||
// Priority 1 to execute the filter early
|
||||
add_filter( 'fictioneer_filter_simple_chapter_list_item', 'child_prefix_simple_chapter_list_item', 1, 3 );
|
||||
add_filter( 'fictioneer_filter_chapter_index_item', 'child_prefix_simple_chapter_list_item', 1, 3 );
|
||||
```
|
||||
|
||||
## Only show a specific advanced meta field
|
||||
@ -363,7 +364,7 @@ If the "Next Chapter" note above the chapter list is not enough and you want to
|
||||
*
|
||||
* @since x.x.x
|
||||
*
|
||||
* @param array $statuses Statuses that are queried. Default ['publish].
|
||||
* @param string[] $statuses Statuses that are queried. Default ['publish].
|
||||
*
|
||||
* @return array The updated array of statuses.
|
||||
*/
|
||||
@ -414,6 +415,10 @@ add_action( 'wp', 'child_remove_scheduled_chapter', 11 ); // The action is added
|
||||
* Note: Hidden chapters are still ignored.
|
||||
*
|
||||
* @since x.x.x
|
||||
*
|
||||
* @param string[] $statuses Statuses that are queried. Default ['publish].
|
||||
*
|
||||
* @return array The updated array of statuses.
|
||||
*/
|
||||
|
||||
function child_consider_scheduled_chapters_as_update( $statuses ) {
|
||||
@ -423,16 +428,16 @@ function child_consider_scheduled_chapters_as_update( $statuses ) {
|
||||
}
|
||||
add_action( 'fictioneer_filter_chapters_added_statuses', 'child_consider_scheduled_chapters_as_update' );
|
||||
|
||||
// If you want scheduled chapters to be treated like published ones;
|
||||
// you still need a function or plugin to make them accessible or
|
||||
// they will lead to a 404 error page. Yes, that's a lot of filters.
|
||||
// If you want scheduled chapters to be treated like published ones,
|
||||
// also add the following filters; you still need a function or plugin
|
||||
// to make them accessible or they will lead to a 404 error page.
|
||||
|
||||
/**
|
||||
* Adds the 'future' post status to an allowed statuses array
|
||||
*
|
||||
* @since x.x.x
|
||||
*
|
||||
* @param array $statuses Statuses that are queried. Default ['publish].
|
||||
* @param string[] $statuses Statuses that are queried. Default ['publish].
|
||||
*
|
||||
* @return array The updated array of statuses.
|
||||
*/
|
||||
@ -442,7 +447,7 @@ function child_treat_scheduled_chapters_as_published( $statuses ) {
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
add_filter( 'fictioneer_filter_simple_chapter_list_items_statuses', 'child_treat_scheduled_chapters_as_published' );
|
||||
add_filter( 'fictioneer_filter_chapter_index_list_statuses', 'child_treat_scheduled_chapters_as_published' );
|
||||
add_filter( 'fictioneer_filter_chapter_nav_buttons_allowed_statuses', 'child_treat_scheduled_chapters_as_published' );
|
||||
add_filter( 'fictioneer_filter_get_story_data_indexed_chapter_statuses', 'child_treat_scheduled_chapters_as_published' );
|
||||
add_filter( 'fictioneer_filter_allowed_chapter_permalinks', 'child_treat_scheduled_chapters_as_published' );
|
||||
|
22
FILTERS.md
22
FILTERS.md
@ -321,8 +321,8 @@ Filters the intermediate output array in the `_chapter-header.php` partial befor
|
||||
---
|
||||
|
||||
### `apply_filters( 'fictioneer_filter_chapter_list_statuses', $statuses, $story_id )`
|
||||
### `apply_filters( 'fictioneer_filter_simple_chapter_list_items_statuses', $statuses, $story_id )`
|
||||
Filters the array of allowed chapter statuses when building the simple chapter list items in the `function fictioneer_get_simple_chapter_list_items()` function. By default, only `['publish']` chapters are shown.
|
||||
### `apply_filters( 'fictioneer_filter_chapter_index_list_statuses', $statuses, $story_id )`
|
||||
Filters the array of allowed chapter statuses when building the simple chapter list items in the `function fictioneer_get_chapter_list_data()` function. By default, only `['publish']` chapters are shown.
|
||||
|
||||
**Note:** `fictioneer_filter_chapter_list_statuses` is deprecated as of 5.25.0.
|
||||
|
||||
@ -332,18 +332,18 @@ Filters the array of allowed chapter statuses when building the simple chapter l
|
||||
|
||||
**Example:**
|
||||
```php
|
||||
function child_add_scheduled_chapters_to_simple_list_items( $statuses ) {
|
||||
function child_add_scheduled_chapters_to_chapter_index_list( $statuses ) {
|
||||
$statuses[] = 'future';
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
add_filter( 'fictioneer_filter_simple_chapter_list_items_statuses', 'child_add_scheduled_chapters_to_simple_list_items' );
|
||||
add_filter( 'fictioneer_filter_chapter_index_list_statuses', 'child_add_scheduled_chapters_to_chapter_index_list' );
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `apply_filters( 'fictioneer_filter_chapter_list_item', $item, $post, $args )`
|
||||
### `apply_filters( 'fictioneer_filter_simple_chapter_list_item', $item, $post, $args )`
|
||||
### `apply_filters( 'fictioneer_filter_chapter_index_item', $item, $post, $args )`
|
||||
Filters each list item HTML string used in the chapter index popup and mobile menu section (only visible on chapter pages), build inside the `fictioneer_get_simple_chapter_list_items()` function. Not to be confused with the chapter list shown on story pages. You can either modify the string or build a new one from the given parameters.
|
||||
|
||||
**Note:** `fictioneer_filter_chapter_list_item` is deprecated as of 5.25.0.
|
||||
@ -353,10 +353,12 @@ Filters each list item HTML string used in the chapter index popup and mobile me
|
||||
* $post (WP_Post) - The chapter post object.
|
||||
|
||||
**$args:**
|
||||
* $title (string) – HTML for the regular title.
|
||||
* $list_title (string) – HTML for the list title or empty.
|
||||
* $icon (string) – HTML for the (text) icon or empty.
|
||||
* $classes (array) – Array of CSS classes or empty.
|
||||
* `title` (string) – Regular title.
|
||||
* `list_title` (string) – List title or empty (precedence over title).
|
||||
* `icon` (string) – HTML for the (text) icon or empty.
|
||||
* `group` (string) – Name of the chapter group or empty.
|
||||
* `classes` (array) – Array of CSS classes or empty.
|
||||
* `position` (int) – Position in the chapter list, starting at 1.
|
||||
|
||||
**Example:**
|
||||
```php
|
||||
@ -373,7 +375,7 @@ function child_prefix_simple_chapter_list_item( $item, $post, $args ) {
|
||||
$args['list_title'] ?: $args['title']
|
||||
);
|
||||
}
|
||||
add_filter( 'fictioneer_filter_simple_chapter_list_item', 'child_prefix_simple_chapter_list_item', 1, 3 );
|
||||
add_filter( 'fictioneer_filter_chapter_index_item', 'child_prefix_simple_chapter_list_item', 1, 3 );
|
||||
```
|
||||
|
||||
---
|
||||
|
@ -1259,75 +1259,42 @@ if ( ! function_exists( 'fictioneer_get_chapter_micro_menu' ) ) {
|
||||
// GET SIMPLE CHAPTER LIST
|
||||
// =============================================================================
|
||||
|
||||
if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) {
|
||||
/**
|
||||
* Returns the HTML for chapter list items with icon and link
|
||||
*
|
||||
* @deprecated 5.25.0
|
||||
*
|
||||
* @since 5.0.0
|
||||
* @since 5.9.3 - Added meta field caching.
|
||||
* @since 5.9.4 - Removed output buffer.
|
||||
* @since 5.12.2 - Use permalinks instead of page ID.
|
||||
* @since 5.16.0 - Clean up and add filter.
|
||||
*
|
||||
* @param int $story_id ID of the story.
|
||||
* @param array $data Prepared data of the story.
|
||||
* @param int $current_index Index in chapter ID array.
|
||||
*
|
||||
* @return string HTML list of chapters.
|
||||
*/
|
||||
|
||||
function fictioneer_get_chapter_list_items( $story_id, $data, $current_index ) {
|
||||
return fictioneer_get_simple_chapter_list_items( $story_id, $data, $current_index );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'fictioneer_get_simple_chapter_list_items' ) ) {
|
||||
/**
|
||||
* Returns the HTML for chapter list items with icon and link
|
||||
*
|
||||
* Alias: For legacy purposes, the fictioneer_get_chapter_list_items()
|
||||
* is kept as alias for now but should no longer be used.
|
||||
*
|
||||
* @since 5.25.0 - Replaces fictioneer_get_chapter_list_items()
|
||||
*
|
||||
* @param int $story_id ID of the story.
|
||||
* @param array $data Prepared data of the story.
|
||||
* @param int $current_index Index in chapter ID array.
|
||||
*
|
||||
* @return string HTML list of chapters.
|
||||
*/
|
||||
|
||||
function fictioneer_get_simple_chapter_list_items( $story_id, $data, $current_index ) {
|
||||
|
||||
|
||||
function fictioneer_get_chapter_index_array( $story_id ) {
|
||||
// Meta cache?
|
||||
$cache_plugin_active = fictioneer_caching_active( 'chapter_list_items' );
|
||||
$cache_plugin_active = fictioneer_caching_active( 'chapter_get_index_array' );
|
||||
|
||||
if ( ! $cache_plugin_active ) {
|
||||
$last_story_update = get_post_modified_time( 'U', true, $story_id );
|
||||
$meta_cache = get_post_meta( $story_id, 'fictioneer_story_chapter_index_html', true );
|
||||
|
||||
if ( $meta_cache && is_array( $meta_cache ) && array_key_exists( 'html', $meta_cache ) ) {
|
||||
if ( is_array( $meta_cache ) && is_array( $meta_cache['items'] ?? 0 ) ) {
|
||||
// ... still up-to-date and valid?
|
||||
if (
|
||||
( $meta_cache['timestamp'] ?? 0 ) == $last_story_update &&
|
||||
( $meta_cache['valid_until'] ?? 0 ) > time()
|
||||
) {
|
||||
return $meta_cache['html'];
|
||||
return $meta_cache['items'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup
|
||||
$chapters = fictioneer_get_story_chapter_posts( $story_id );
|
||||
$hide_icons = get_post_meta( $story_id, 'fictioneer_story_hide_chapter_icons', true ) || get_option( 'fictioneer_hide_chapter_icons' );
|
||||
$allowed_statuses = apply_filters( 'fictioneer_filter_chapter_list_statuses', ['publish'], $story_id ); // Legacy
|
||||
$allowed_statuses = apply_filters( 'fictioneer_filter_chapter_index_list_statuses', $allowed_statuses, $story_id );
|
||||
$hide_icons = get_post_meta( $story_id, 'fictioneer_story_hide_chapter_icons', true ) ||
|
||||
get_option( 'fictioneer_hide_chapter_icons' );
|
||||
$html = '';
|
||||
$allowed_statuses = apply_filters( 'fictioneer_filter_chapter_list_statuses', ['publish'], $story_id );
|
||||
$allowed_statuses = apply_filters( 'fictioneer_filter_simple_chapter_list_items_statuses', $allowed_statuses, $story_id );
|
||||
$position = 0;
|
||||
|
||||
// Loop chapters...
|
||||
foreach ( $chapters as $chapter ) {
|
||||
// Skip unpublished (in case of filtered query params)
|
||||
// Skip hidden chapters (in case of filtered query params)
|
||||
if (
|
||||
! in_array( $chapter->post_status, $allowed_statuses ) ||
|
||||
get_post_meta( $chapter->ID, 'fictioneer_chapter_hidden', true )
|
||||
@ -1355,40 +1322,32 @@ if ( ! function_exists( 'fictioneer_get_simple_chapter_list_items' ) ) {
|
||||
$icon = '<span class="text-icon">' . $text_icon . '</span>';
|
||||
}
|
||||
|
||||
// HTML
|
||||
// Compile args
|
||||
$args = array(
|
||||
'title' => $title,
|
||||
'list_title' => $list_title,
|
||||
'icon' => $icon,
|
||||
'group' => get_post_meta( $chapter->ID, 'fictioneer_chapter_group', true ),
|
||||
'classes' => $classes,
|
||||
'position' => ++$position
|
||||
);
|
||||
|
||||
// Build list item
|
||||
$item = sprintf(
|
||||
'<li class="%1$s" data-id="%2$s"><a href="%3$s">%4$s<span>%5$s</span></a></li>',
|
||||
'<li class="%1$s" data-position="%2$s" data-id="%3$s"><a href="%4$s">%5$s<span>%6$s</span></a></li>',
|
||||
implode( ' ', $classes ),
|
||||
$position,
|
||||
$chapter->ID,
|
||||
get_the_permalink( $chapter->ID ),
|
||||
$icon,
|
||||
$list_title ?: $title
|
||||
);
|
||||
|
||||
// Deprecated
|
||||
$item = apply_filters(
|
||||
'fictioneer_filter_chapter_list_item',
|
||||
$item,
|
||||
$chapter,
|
||||
array(
|
||||
'title' => $title,
|
||||
'list_title' => $list_title,
|
||||
'icon' => $icon,
|
||||
'classes' => $classes
|
||||
)
|
||||
);
|
||||
// Legacy filter
|
||||
$item = apply_filters( 'fictioneer_filter_chapter_list_item', $item, $chapter, $args );
|
||||
|
||||
$html .= apply_filters(
|
||||
'fictioneer_filter_simple_chapter_list_item',
|
||||
$item,
|
||||
$chapter,
|
||||
array(
|
||||
'title' => $title,
|
||||
'list_title' => $list_title,
|
||||
'icon' => $icon,
|
||||
'classes' => $classes
|
||||
)
|
||||
);
|
||||
// Append
|
||||
$items[ $position ] = apply_filters( 'fictioneer_filter_chapter_index_item', $item, $chapter, $args );
|
||||
}
|
||||
|
||||
// Update meta cache
|
||||
@ -1396,13 +1355,12 @@ if ( ! function_exists( 'fictioneer_get_simple_chapter_list_items' ) ) {
|
||||
update_post_meta(
|
||||
$story_id,
|
||||
'fictioneer_story_chapter_index_html',
|
||||
array( 'html' => $html, 'timestamp' => $last_story_update, 'valid_until' => time() + HOUR_IN_SECONDS )
|
||||
array( 'items' => $items, 'timestamp' => $last_story_update, 'valid_until' => time() + HOUR_IN_SECONDS )
|
||||
);
|
||||
}
|
||||
|
||||
// Return
|
||||
return $html;
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
@ -455,7 +455,7 @@ function fictioneer_chapter_index_popup_menu( $args ) {
|
||||
<i class="fa-solid fa-caret-left"></i>
|
||||
<span><?php _e( 'Back to Story', 'fictioneer' ); ?></span>
|
||||
</a>
|
||||
<div class="popup-menu__section" data-target="popup-chapter-list"></div>
|
||||
<div class="popup-menu__section"><ul data-target="popup-chapter-list" data-current-id="<?php the_ID(); ?>"></ul></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php // <--- End HTML
|
||||
|
@ -240,7 +240,9 @@ function fictioneer_mobile_chapters_frame() {
|
||||
<i class="fa-solid fa-caret-left mobile-menu__item-icon"></i> <?php _e( 'Back', 'fictioneer' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div id="mobile-menu-chapters-list" class="mobile-menu__list _chapters"></div>
|
||||
<div class="mobile-menu__list _chapters">
|
||||
<ul id="mobile-menu-chapters-list" data-current-id="<?php the_ID(); ?>"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php // <--- End HTML
|
||||
|
3
js/application.min.js
vendored
3
js/application.min.js
vendored
File diff suppressed because one or more lines are too long
2
js/chapter.min.js
vendored
2
js/chapter.min.js
vendored
File diff suppressed because one or more lines are too long
8
js/complete.min.js
vendored
8
js/complete.min.js
vendored
File diff suppressed because one or more lines are too long
2
js/mobile-menu.min.js
vendored
2
js/mobile-menu.min.js
vendored
@ -1 +1 @@
|
||||
function fcn_toggleMobileMenu(e){_$(".mobile-menu._advanced-mobile-menu")?fcn_toggleAdvancedMobileMenu(e):fcn_toggleSimpleMobileMenu(e)}function fcn_toggleSimpleMobileMenu(e){e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down"),fcn_theBody.classList.remove("scrolling-up")):(fcn_theBody.classList.remove("mobile-menu-open"),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),_$$$("mobile-menu-toggle").checked=!1)}function fcn_toggleAdvancedMobileMenu(e){const n=_$$$("wpadminbar")?.offsetHeight??0,t=window.scrollY,o=fcn_theSite.scrollTop;e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down","scrolled-to-top"),fcn_theBody.classList.remove("scrolling-up"),fcn_theSite.classList.add("transformed-scroll","transformed-site"),fcn_theSite.scrollTop=t-n,fcn_updateThemeColor()):(fcn_theSite.classList.remove("transformed-site","transformed-scroll"),fcn_theBody.classList.remove("mobile-menu-open"),fcn_updateThemeColor(),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),fcn_theRoot.style.scrollBehavior="auto",window.scroll(0,o+n),fcn_theRoot.style.scrollBehavior="",_$$$("mobile-menu-toggle").checked=!1,"function"==typeof fcn_trackProgress&&fcn_trackProgress())}function fcn_setupMobileJumpButton(e,n){const t=_$(e);t&&t.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const e=n();e&&fcn_scrollTo(e)}),200)}))}function fcn_openMobileFrame(e){fcn_closeMobileFrames(),_$(`.mobile-menu__frame[data-frame="${e}"]`)?.classList.add("_active")}function fcn_closeMobileFrames(){_$$(".mobile-menu__frame._active").forEach((e=>{e.classList.remove("_active")}));const e=_$(".mobile-menu__bookmarks-panel");e&&(e.dataset.editing="false")}function fcn_appendChapterList(){const e=_$$$("mobile-menu-chapters-list");fcn_chapterList&&!e.hasChildNodes()&&e.appendChild(fcn_chapterList.cloneNode(!0))}_$$$("mobile-menu-toggle")?.addEventListener("change",(e=>{fcn_toggleMobileMenu(e.currentTarget.checked)})),fcn_theSite.addEventListener("click",(e=>{fcn_theBody.classList.contains("mobile-menu-open")&&(e.preventDefault(),fcn_toggleMobileMenu(!1))})),fcn_setupMobileJumpButton("#mobile-menu-comment-jump",(()=>_$$$("comments"))),fcn_setupMobileJumpButton("#mobile-menu-bookmark-jump",(()=>_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`))),_$$(".button-change-lightness").forEach((e=>{e.addEventListener("click",(e=>{fcn_updateDarken(fcn_siteSettings.darken+parseFloat(e.currentTarget.value))}))})),_$$(".mobile-menu__frame-button").forEach((e=>{e.addEventListener("click",(e=>{fcn_openMobileFrame(e.currentTarget.dataset.frameTarget)}))})),_$$(".mobile-menu__back-button").forEach((e=>{e.addEventListener("click",(()=>{fcn_openMobileFrame("main")}))})),_$('.mobile-menu__frame-button[data-frame-target="chapters"]')?.addEventListener("click",(()=>{fcn_appendChapterList()}),{once:!0}),_$$$("micro-menu-label-open-chapter-list")?.addEventListener("click",(()=>{fcn_appendChapterList(),fcn_openMobileFrame("chapters")})),_$$$("button-mobile-menu-toggle-bookmarks-edit")?.addEventListener("click",(e=>{const n=e.currentTarget.closest(".mobile-menu__bookmarks-panel");n.dataset.editing="false"==n.dataset.editing?"true":"false"})),_$('.mobile-menu__frame-button[data-frame-target="bookmarks"]')?.addEventListener("click",(()=>{fcn_setMobileMenuBookmarks()}),{once:!0});
|
||||
function fcn_toggleMobileMenu(e){_$(".mobile-menu._advanced-mobile-menu")?fcn_toggleAdvancedMobileMenu(e):fcn_toggleSimpleMobileMenu(e)}function fcn_toggleSimpleMobileMenu(e){e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down"),fcn_theBody.classList.remove("scrolling-up")):(fcn_theBody.classList.remove("mobile-menu-open"),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),_$$$("mobile-menu-toggle").checked=!1)}function fcn_toggleAdvancedMobileMenu(e){const o=_$$$("wpadminbar")?.offsetHeight??0,n=window.scrollY,t=fcn_theSite.scrollTop;e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down","scrolled-to-top"),fcn_theBody.classList.remove("scrolling-up"),fcn_theSite.classList.add("transformed-scroll","transformed-site"),fcn_theSite.scrollTop=n-o,fcn_updateThemeColor()):(fcn_theSite.classList.remove("transformed-site","transformed-scroll"),fcn_theBody.classList.remove("mobile-menu-open"),fcn_updateThemeColor(),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),fcn_theRoot.style.scrollBehavior="auto",window.scroll(0,t+o),fcn_theRoot.style.scrollBehavior="",_$$$("mobile-menu-toggle").checked=!1,"function"==typeof fcn_trackProgress&&fcn_trackProgress())}function fcn_setupMobileJumpButton(e,o){const n=_$(e);n&&n.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const e=o();e&&fcn_scrollTo(e)}),200)}))}function fcn_openMobileFrame(e){fcn_closeMobileFrames(),_$(`.mobile-menu__frame[data-frame="${e}"]`)?.classList.add("_active")}function fcn_closeMobileFrames(){_$$(".mobile-menu__frame._active").forEach((e=>{e.classList.remove("_active")}));const e=_$(".mobile-menu__bookmarks-panel");e&&(e.dataset.editing="false")}_$$$("mobile-menu-toggle")?.addEventListener("change",(e=>{fcn_toggleMobileMenu(e.currentTarget.checked)})),fcn_theSite.addEventListener("click",(e=>{fcn_theBody.classList.contains("mobile-menu-open")&&(e.preventDefault(),fcn_toggleMobileMenu(!1))})),fcn_setupMobileJumpButton("#mobile-menu-comment-jump",(()=>_$$$("comments"))),fcn_setupMobileJumpButton("#mobile-menu-bookmark-jump",(()=>_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`))),_$$(".button-change-lightness").forEach((e=>{e.addEventListener("click",(e=>{fcn_updateDarken(fcn_siteSettings.darken+parseFloat(e.currentTarget.value))}))})),_$$(".mobile-menu__frame-button").forEach((e=>{e.addEventListener("click",(e=>{fcn_openMobileFrame(e.currentTarget.dataset.frameTarget)}))})),_$$(".mobile-menu__back-button").forEach((e=>{e.addEventListener("click",(()=>{fcn_openMobileFrame("main")}))})),_$$$("button-mobile-menu-toggle-bookmarks-edit")?.addEventListener("click",(e=>{const o=e.currentTarget.closest(".mobile-menu__bookmarks-panel");o.dataset.editing="false"==o.dataset.editing?"true":"false"})),_$('.mobile-menu__frame-button[data-frame-target="bookmarks"]')?.addEventListener("click",(()=>{fcn_setMobileMenuBookmarks()}),{once:!0});
|
@ -88,17 +88,11 @@ get_header(
|
||||
'prev_index' => $prev_index >= 0 ? $prev_index : false,
|
||||
'next_index' => isset( $indexed_chapters[ $next_index ] ) ? $next_index : false
|
||||
);
|
||||
?>
|
||||
|
||||
<?php if ( $story_post && $indexed_chapters ): ?>
|
||||
<div id="story-chapter-list" class="hidden" data-story-id="<?php echo $story_id; ?>">
|
||||
<ul data-current-id="<?php echo $post_id; ?>"><?php
|
||||
echo fictioneer_get_simple_chapter_list_items( $story_id, $story_data, $current_index );
|
||||
?></ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
if ( $story_post && $indexed_chapters ) {
|
||||
echo '<script>const fcn_storyChapterListData = ' . json_encode( fictioneer_get_chapter_index_array( $story_id ) ) . ';</script>';
|
||||
}
|
||||
|
||||
<?php
|
||||
if ( get_option( 'fictioneer_enable_bookmarks' ) ) {
|
||||
// Bookmark data
|
||||
$bookmark_story_title = '';
|
||||
|
@ -10,17 +10,6 @@ const /** @const {Number} */ fcn_pageLoadTimestamp = Date.now();
|
||||
const /** @const {Number} */ fcn_ajaxLimitThreshold = Date.now() - parseInt(fictioneer_ajax.ttl); // Default: 60 seconds
|
||||
|
||||
var /** @type {Boolean} */ fcn_isLoggedIn = fcn_theBody.classList.contains('logged-in');
|
||||
var /** @type {HTMLElement} */ fcn_chapterList = _$('#story-chapter-list > ul');
|
||||
|
||||
// =============================================================================
|
||||
// CHAPTER INDEX
|
||||
// =============================================================================
|
||||
|
||||
if (fcn_chapterList) {
|
||||
fcn_chapterList = fcn_chapterList.cloneNode(true);
|
||||
_$$$('story-chapter-list').remove();
|
||||
fcn_chapterList.querySelector(`[data-id="${fcn_chapterList.dataset.currentId}"]`)?.classList.add('current-chapter');
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// STARTUP CLEANUP
|
||||
|
@ -1251,16 +1251,44 @@ function fcn_readingProgress() {
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// SETUP INDEX POPUP MENU
|
||||
// SETUP CHAPTER INDEX MENU
|
||||
// =============================================================================
|
||||
|
||||
// Append cloned chapter list once when the popup menu is opened
|
||||
/**
|
||||
* Builds and appends the chapter index list to the target element.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @param {HTMLElement} target - Target to append the list elements to.
|
||||
*/
|
||||
|
||||
function fcn_appendChapterList(target) {
|
||||
if (fcn_storyChapterListData && target && !target.querySelector('li')) {
|
||||
for (const number in fcn_storyChapterListData) {
|
||||
target.innerHTML += fcn_storyChapterListData[number];
|
||||
}
|
||||
|
||||
target.querySelector(`[data-id="${target.dataset.currentId}"]`)?.classList.add('current-chapter');
|
||||
}
|
||||
}
|
||||
|
||||
// Append chapters when popup menu is opened, once
|
||||
_$$('.chapter-list-popup-toggle').forEach(element => {
|
||||
element.addEventListener('click', () => {
|
||||
element.querySelector('[data-target="popup-chapter-list"]')?.appendChild(fcn_chapterList.cloneNode(true));
|
||||
fcn_appendChapterList(element.querySelector('[data-target="popup-chapter-list"]'));
|
||||
}, { once: true });
|
||||
});
|
||||
|
||||
// Append chapters when chapter frame is opened, once
|
||||
_$('.mobile-menu__frame-button[data-frame-target="chapters"]')?.addEventListener('click', () => {
|
||||
fcn_appendChapterList(_$$$('mobile-menu-chapters-list'));
|
||||
}, { once: true });
|
||||
|
||||
// Listen for click on chapter list in the micro menu, once
|
||||
_$$$('micro-menu-label-open-chapter-list')?.addEventListener('click', () => {
|
||||
fcn_appendChapterList(_$$$('mobile-menu-chapters-list'));
|
||||
fcn_openMobileFrame('chapters');
|
||||
}, { once: true });
|
||||
|
||||
// =============================================================================
|
||||
// KEYBOARD NAVIGATION
|
||||
// =============================================================================
|
||||
|
@ -208,30 +208,7 @@ _$$('.mobile-menu__back-button').forEach(element => {
|
||||
// CHAPTERS FRAME
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Appends a cloned chapter list to the mobile menu.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
|
||||
function fcn_appendChapterList() {
|
||||
const target = _$$$('mobile-menu-chapters-list');
|
||||
|
||||
if (fcn_chapterList && !target.hasChildNodes()) {
|
||||
target.appendChild(fcn_chapterList.cloneNode(true));
|
||||
}
|
||||
}
|
||||
|
||||
// Append chapters when chapter frame is opened, once
|
||||
_$('.mobile-menu__frame-button[data-frame-target="chapters"]')?.addEventListener('click', () => {
|
||||
fcn_appendChapterList();
|
||||
}, { once: true });
|
||||
|
||||
// Listen for click on chapter list in the micro menu
|
||||
_$$$('micro-menu-label-open-chapter-list')?.addEventListener('click', () => {
|
||||
fcn_appendChapterList();
|
||||
fcn_openMobileFrame('chapters');
|
||||
});
|
||||
/* See chapters.js */
|
||||
|
||||
// =============================================================================
|
||||
// FOLLOWS FRAME
|
||||
|
Loading…
x
Reference in New Issue
Block a user