Add script execution preconditions
In case these scripts are loaded somewhere they are not needed.
This commit is contained in:
parent
4e6c7cd4d0
commit
d08957a0a2
@ -22,10 +22,11 @@ $post_id = get_the_ID();
|
||||
$user = wp_get_current_user();
|
||||
$comments_count = get_comments_number();
|
||||
$logout_url = fictioneer_get_logout_url( get_permalink() );
|
||||
$is_ajax_comments = get_option( 'fictioneer_enable_ajax_comments' );
|
||||
|
||||
?>
|
||||
|
||||
<div id="comments" class="fictioneer-comments scroll-margin-top" data-post-id="<?php echo $post_id; ?>" data-logout-url="<?php echo esc_url( $logout_url ); ?>">
|
||||
<div id="comments" class="fictioneer-comments scroll-margin-top" data-post-id="<?php echo $post_id; ?>" data-logout-url="<?php echo esc_url( $logout_url ); ?>" <?php echo $is_ajax_comments ? 'data-ajax-comments' : ''; ?>>
|
||||
|
||||
<?php
|
||||
|
||||
|
2
js/ajax-bookshelf.min.js
vendored
2
js/ajax-bookshelf.min.js
vendored
@ -1 +1 @@
|
||||
const fcn_bookshelfTarget=_$$$("ajax-bookshelf-target");function fcn_getBookshelfContent(){return fcn_parseJSON(localStorage.getItem("fcnBookshelfContent"))??{html:{},count:{}}}function fcn_updateBookshelfView(e=null,t=null,o=null,n=!1){let a=fcn_getBookshelfContent();const s=(e=e??fcn_bookshelfTarget.dataset.action)+(t=t??fcn_bookshelfTarget.dataset.page)+(o=o??fcn_bookshelfTarget.dataset.order);if(!a.hasOwnProperty("timestamp")||a.timestamp+6e4<Date.now())return localStorage.removeItem("fcnBookshelfContent"),a={html:{},count:{}},void fcn_fetchBookshelfPart(e,t,o,n);a.hasOwnProperty("html")&&a.html.hasOwnProperty(s)?(fcn_bookshelfTarget.innerHTML=a.html[s],fcn_bookshelfTarget.classList.remove("ajax-in-progress"),fcn_bookshelfTarget.dataset.page=t,_$(".item-number").innerHTML=`(${a.count[e]})`,n&&_$$$("main").scrollIntoView({behavior:"smooth"})):fcn_fetchBookshelfPart(e,t,o,n)}function fcn_browseBookshelfPage(e){fcn_bookshelfTarget.classList.add("ajax-in-progress"),fcn_updateBookshelfView(null,e,null,!0),history.pushState({},"",fcn_buildUrl({tab:fcn_bookshelfTarget.dataset.tab,pg:e,order:fcn_bookshelfTarget.dataset.order}).href)}function fcn_fetchBookshelfPart(e,t,o,n=!1){const a=e+t+o,s=fcn_getBookshelfContent();fcn_ajaxGet({action:e,fcn_fast_ajax:1,page:t,order:o}).then((o=>{o.success?(s.timestamp=Date.now(),s.html[a]=o.data.html,s.count[e]=o.data.count,localStorage.setItem("fcnBookshelfContent",JSON.stringify(s)),fcn_bookshelfTarget.innerHTML=o.data.html,fcn_bookshelfTarget.dataset.page=t,_$(".item-number").innerHTML=`(${o.data.count})`):(fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(o.data.error)))})).catch((e=>{_$(".item-number").innerHTML="",fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(`${e.status}: ${e.statusText}`))})).then((()=>{fcn_bookshelfTarget.classList.remove("ajax-in-progress"),n&&_$$$("main").scrollIntoView({behavior:"smooth"})}))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_updateBookshelfView()})):fcn_updateBookshelfView(),_$(".bookshelf__list")?.addEventListener("click",(e=>{const t=e.target.closest(".page-numbers[data-page]");t&&fcn_browseBookshelfPage(t.dataset.page)}));
|
||||
const fcn_bookshelfTarget=_$$$("ajax-bookshelf-target");function fcn_getBookshelfContent(){return fcn_parseJSON(localStorage.getItem("fcnBookshelfContent"))??{html:{},count:{}}}function fcn_updateBookshelfView(e=null,t=null,o=null,n=!1){let a=fcn_getBookshelfContent();const s=(e=e??fcn_bookshelfTarget.dataset.action)+(t=t??fcn_bookshelfTarget.dataset.page)+(o=o??fcn_bookshelfTarget.dataset.order);if(!a.hasOwnProperty("timestamp")||a.timestamp+6e4<Date.now())return localStorage.removeItem("fcnBookshelfContent"),a={html:{},count:{}},void fcn_fetchBookshelfPart(e,t,o,n);a.hasOwnProperty("html")&&a.html.hasOwnProperty(s)?(fcn_bookshelfTarget.innerHTML=a.html[s],fcn_bookshelfTarget.classList.remove("ajax-in-progress"),fcn_bookshelfTarget.dataset.page=t,_$(".item-number").innerHTML=`(${a.count[e]})`,n&&_$$$("main").scrollIntoView({behavior:"smooth"})):fcn_fetchBookshelfPart(e,t,o,n)}function fcn_browseBookshelfPage(e){fcn_bookshelfTarget.classList.add("ajax-in-progress"),fcn_updateBookshelfView(null,e,null,!0),history.pushState({},"",fcn_buildUrl({tab:fcn_bookshelfTarget.dataset.tab,pg:e,order:fcn_bookshelfTarget.dataset.order}).href)}function fcn_fetchBookshelfPart(e,t,o,n=!1){const a=e+t+o,s=fcn_getBookshelfContent();fcn_ajaxGet({action:e,fcn_fast_ajax:1,page:t,order:o}).then((o=>{o.success?(s.timestamp=Date.now(),s.html[a]=o.data.html,s.count[e]=o.data.count,localStorage.setItem("fcnBookshelfContent",JSON.stringify(s)),fcn_bookshelfTarget.innerHTML=o.data.html,fcn_bookshelfTarget.dataset.page=t,_$(".item-number").innerHTML=`(${o.data.count})`):(fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(o.data.error)))})).catch((e=>{_$(".item-number").innerHTML="",fcn_bookshelfTarget.innerHTML="",fcn_bookshelfTarget.appendChild(fcn_buildErrorNotice(`${e.status}: ${e.statusText}`))})).then((()=>{fcn_bookshelfTarget.classList.remove("ajax-in-progress"),n&&_$$$("main").scrollIntoView({behavior:"smooth"})}))}fcn_bookshelfTarget&&(fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_updateBookshelfView()})):fcn_updateBookshelfView()),_$(".bookshelf__list")?.addEventListener("click",(e=>{const t=e.target.closest(".page-numbers[data-page]");t&&fcn_browseBookshelfPage(t.dataset.page)}));
|
2
js/ajax-comments.min.js
vendored
2
js/ajax-comments.min.js
vendored
@ -1 +1 @@
|
||||
const fcn_commentSection=_$$$("comments");function fcn_getCommentSection(e=null,n=null,t=!1){if(!fcn_commentSection)return;let o,c="",m=_$$$("comment");if(m&&(c=m.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),n||(n=fcn_urlParams.pg??1),!fcn_commentSection)return;const a={action:"fictioneer_ajax_get_comment_section",post_id:e??fcn_commentSection.dataset.postId,page:parseInt(n)};fcn_urlParams.commentcode&&(a.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(a).then((e=>{if(e.success){n=e.data.page;const o=document.createElement("div");if(o.innerHTML=e.data.html,o.querySelector("#comment_post_ID")){o.querySelector("#comment_post_ID").value=e.data.postId,o.querySelector("#cancel-comment-reply-link").href="#respond";const n=o.querySelector(".logout-link");n&&(n.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=o.innerHTML,o.remove(),e.data.disabled||(m=_$$$("comment"),m.value=c,fcn_applyCommentStack(m)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const a=location.hash.includes("#comment")?location.hash:".respond",r=document.querySelector(a)??_$$$("respond");t&&r.scrollIntoView({behavior:"smooth"});const i=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";fcn_urlParams.commentcode&&(s+=`?commentcode=${fcn_urlParams.commentcode}`),n>1&&(s+=s.length>1?`&pg=${n}`:`?pg=${n}`),window.history.pushState({path:i},"",i+s+location.hash)}else o=fcn_buildErrorNotice(e.data.error)})).catch((e=>{o=fcn_buildErrorNotice(e)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),o&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(o))}))}function fcn_reloadCommentsPage(e=null){fcn_getCommentSection(null,e,!0)}function fcn_jumpToCommentPage(){const e=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));e>0&&fcn_reloadCommentsPage(e)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(e=>{if(e.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const n=e.target.closest("[data-page]");n&&fcn_reloadCommentsPage(n.dataset.page)}));
|
||||
const fcn_commentSection=_$("#comments[data-ajax-comments]");function fcn_getCommentSection(e=null,n=null,t=!1){if(!fcn_commentSection)return;let o,c="",m=_$$$("comment");if(m&&(c=m.value),fcn_commentSection.classList.contains("ajax-in-progress"))return;if(fcn_commentSection.classList.add("ajax-in-progress"),n||(n=fcn_urlParams.pg??1),!fcn_commentSection)return;const a={action:"fictioneer_ajax_get_comment_section",post_id:e??fcn_commentSection.dataset.postId,page:parseInt(n)};fcn_urlParams.commentcode&&(a.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(a).then((e=>{if(e.success){n=e.data.page;const o=document.createElement("div");if(o.innerHTML=e.data.html,o.querySelector("#comment_post_ID")){o.querySelector("#comment_post_ID").value=e.data.postId,o.querySelector("#cancel-comment-reply-link").href="#respond";const n=o.querySelector(".logout-link");n&&(n.href=fcn_commentSection.dataset.logoutUrl)}fcn_commentSection.innerHTML=o.innerHTML,o.remove(),e.data.disabled||(m=_$$$("comment"),m.value=c,fcn_applyCommentStack(m)),fcn_addCommentMouseleaveEvents(),fcn_addCommentFormEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const a=location.hash.includes("#comment")?location.hash:".respond",r=document.querySelector(a)??_$$$("respond");t&&r.scrollIntoView({behavior:"smooth"});const i=window.location.protocol+"//"+window.location.host+window.location.pathname;let s="";fcn_urlParams.commentcode&&(s+=`?commentcode=${fcn_urlParams.commentcode}`),n>1&&(s+=s.length>1?`&pg=${n}`:`?pg=${n}`),window.history.pushState({path:i},"",i+s+location.hash)}else o=fcn_buildErrorNotice(e.data.error)})).catch((e=>{o=fcn_buildErrorNotice(e)})).then((()=>{fcn_commentSection.classList.remove("ajax-in-progress"),o&&(fcn_commentSection.innerHTML="",fcn_commentSection.appendChild(o))}))}function fcn_reloadCommentsPage(e=null){fcn_getCommentSection(null,e,!0)}function fcn_jumpToCommentPage(){const e=parseInt(window.prompt(fictioneer_tl.notification.enterPageNumber));e>0&&fcn_reloadCommentsPage(e)}var fct_commentSectionObserver;function fcn_setupCommentSectionObserver(){fct_commentSectionObserver=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentSection(),fct_commentSectionObserver.disconnect())}),{rootMargin:"450px",threshold:1}),fcn_commentSection&&fct_commentSectionObserver.observe(fcn_commentSection)}function fcn_loadCommentEarly(){fcn_commentSection&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentSectionObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_setupCommentSectionObserver()})):fcn_setupCommentSectionObserver(),fcn_theRoot.dataset.ajaxAuth?document.addEventListener("fcnAuthReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(e=>{if(e.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const n=e.target.closest("[data-page]");n&&fcn_reloadCommentsPage(n.dataset.page)}));
|
2
js/chapter.min.js
vendored
2
js/chapter.min.js
vendored
File diff suppressed because one or more lines are too long
2
js/tts.min.js
vendored
2
js/tts.min.js
vendored
File diff suppressed because one or more lines are too long
@ -5,12 +5,14 @@
|
||||
const fcn_bookshelfTarget = _$$$('ajax-bookshelf-target');
|
||||
|
||||
// Initialize
|
||||
if (fcn_theRoot.dataset.ajaxAuth) {
|
||||
document.addEventListener('fcnAuthReady', () => {
|
||||
if (fcn_bookshelfTarget) {
|
||||
if (fcn_theRoot.dataset.ajaxAuth) {
|
||||
document.addEventListener('fcnAuthReady', () => {
|
||||
fcn_updateBookshelfView();
|
||||
});
|
||||
} else {
|
||||
fcn_updateBookshelfView();
|
||||
});
|
||||
} else {
|
||||
fcn_updateBookshelfView();
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
@ -2,7 +2,7 @@
|
||||
// SETUP
|
||||
// =============================================================================
|
||||
|
||||
const /** @const {HTMLElement} */ fcn_commentSection = _$$$('comments');
|
||||
const /** @const {HTMLElement} */ fcn_commentSection = _$('#comments[data-ajax-comments]');
|
||||
|
||||
// =============================================================================
|
||||
// REQUEST COMMENTS FORM VIA AJAX
|
||||
@ -29,9 +29,9 @@ function fcn_getCommentSection(post_id = null, page = null, scroll = false) {
|
||||
}
|
||||
|
||||
// Setup
|
||||
let commentText = '',
|
||||
commentTextarea = _$$$('comment'),
|
||||
errorNote;
|
||||
let commentText = '';
|
||||
let commentTextarea = _$$$('comment');
|
||||
let errorNote;
|
||||
|
||||
// Preserve comment text (in case of pagination)
|
||||
if (commentTextarea) {
|
||||
|
@ -391,6 +391,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLInputElement} */ range = _$$$('reader-settings-font-size-range');
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-font-size-reset');
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update font size formatting on chapters.
|
||||
*
|
||||
@ -475,6 +480,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-font-color-reset');
|
||||
const /** @const {HTMLElement} */ select = _$$$('reader-settings-font-color-select');
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update font color on chapters.
|
||||
*
|
||||
@ -543,6 +553,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-font-reset');
|
||||
const /** @const {HTMLElement} */ select = _$$$('reader-settings-font-select');
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update font family on chapters.
|
||||
*
|
||||
@ -628,6 +643,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLInputElement} */ range = _$$$('reader-settings-font-saturation-range');
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-font-saturation-reset');
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update font saturation formatting on chapters.
|
||||
*
|
||||
@ -706,6 +726,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-letter-spacing-reset');
|
||||
const /** @const {Number} */ _default = fcn_defaultFormatting()['letter-spacing'];
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update letter-spacing formatting on chapters.
|
||||
*
|
||||
@ -771,6 +796,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-paragraph-spacing-reset');
|
||||
const /** @const {Number} */ _default = fcn_defaultFormatting()['paragraph-spacing'];
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update paragraph spacing formatting on chapters.
|
||||
*
|
||||
@ -836,6 +866,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-line-height-reset');
|
||||
const /** @const {Number} */ _default = fcn_defaultFormatting()['line-height'];
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update line height formatting on chapters.
|
||||
*
|
||||
@ -901,6 +936,11 @@ function fcn_setFormatting(value) {
|
||||
const /** @const {HTMLElement} */ reset = _$$$('reader-settings-site-width-reset');
|
||||
const /** @const {Number} */ _default = fcn_defaultFormatting()['site-width'];
|
||||
|
||||
// Abort if nothing to do
|
||||
if (!reset) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update site width formatting on chapters.
|
||||
*
|
||||
|
@ -18,7 +18,7 @@ var /** @type {SpeechSynthesis} */ fcn_synth;
|
||||
// =============================================================================
|
||||
|
||||
// Check whether the feature is supported...
|
||||
if (typeof speechSynthesis !== 'undefined') {
|
||||
if (typeof speechSynthesis !== 'undefined' && fcn_ttsInterface) {
|
||||
fcn_synth = window.speechSynthesis;
|
||||
fcn_utter = new SpeechSynthesisUtterance();
|
||||
fcn_utter.lang = fcn_theRoot.lang;
|
||||
@ -297,7 +297,7 @@ function fcn_readTextStack() {
|
||||
// EVENT LISTENERS
|
||||
// =============================================================================
|
||||
|
||||
if (typeof speechSynthesis !== 'undefined') {
|
||||
if (typeof speechSynthesis !== 'undefined' && fcn_ttsInterface) {
|
||||
// Paragraph tools button
|
||||
_$$$('button-tts-set').addEventListener('click', event => {
|
||||
fcn_ttsStack = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user