From 8f201a5371090eefe285f851ede487d181e0b697 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:34:57 +0200 Subject: [PATCH] Improve search form No more checkbox toggle and the simple form does no longer query all taxonomies and authors. --- js/application.min.js | 2 +- searchform.php | 111 +++++++++++++++++++++--------------------- src/js/application.js | 4 +- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/js/application.min.js b/js/application.min.js index 39112e64..8918edf9 100644 --- a/js/application.min.js +++ b/js/application.min.js @@ -1 +1 @@ -const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,fcn_inlineStorage=_$$$("inline-storage").dataset,fcn_mainNavigation=_$$$("full-navigation"),fcn_urlSearchParams=new URLSearchParams(window.location.search),fcn_urlParams=Object.fromEntries(fcn_urlSearchParams.entries()),fcn_pageLoadTimestamp=Date.now(),fcn_ajaxLimitThreshold=Date.now()-parseInt(fictioneer_ajax.ttl),fcn_eventNonceReady=new Event("nonceReady"),fcn_isAjaxAuth=fcn_theRoot.dataset.ajaxAuth;var fcn_viewportWidth,fcn_mediaMinTablet,fcn_cssVars=getComputedStyle(document.documentElement),fcn_isLoggedIn=fcn_theBody.classList.contains("logged-in"),fcn_chapterList=_$("#story-chapter-list > ul")?.cloneNode(!0);const{__:__,_x:_x,_n:_n,sprintf:sprintf}=wp.i18n;function fcn_cleanupWebStorage(e=!1){localStorage.removeItem("fcnProfileAvatar"),localStorage.removeItem("fcnStoryFollows"),localStorage.removeItem("fcnStoryReminders"),localStorage.removeItem("fcnCheckmarks"),localStorage.removeItem("fcnFingerprint"),localStorage.removeItem("fcnLoginState"),localStorage.removeItem("fcnBookshelfContent"),e||localStorage.removeItem("fcnChapterBookmarks");let t=localStorage.getItem("fcnNonce");t=!(!t||!fcn_isValidJSONString(t))&&JSON.parse(t),t&&t.loggedIn&&localStorage.removeItem("fcnNonce")}function fcn_cleanupGuestView(){fcn_isLoggedIn=!1,fcn_theBody.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))}function fcn_fetchNonce(){let e=localStorage.getItem("fcnNonce");e=!(!e||!fcn_isValidJSONString(e))&&JSON.parse(e),e&&!e.loggedIn&&fcn_isLoggedIn&&(localStorage.removeItem("fcnNonce"),e=!1),e&&(fcn_addNonceAndAuth(e.nonceHtml),fcn_ajaxLimitThreshold{_$$$("fictioneer-ajax-nonce")?.remove(),e.success?(fcn_addNonceAndAuth(e.data.nonceHtml),localStorage.setItem("fcnNonce",JSON.stringify({lastLoaded:Date.now(),nonceHtml:e.data.nonceHtml,loggedIn:fcn_isLoggedIn}))):(_$$$("fictioneer-ajax-nonce")?.remove(),fcn_cleanupGuestView())})).catch((()=>{localStorage.removeItem("fcnNonce"),_$$$("fictioneer-ajax-nonce")?.remove(),fcn_cleanupGuestView()}))}function fcn_addNonceAndAuth(e){const t=document.createElement("div");t.innerHTML+=e,fcn_theBody.appendChild(t.firstChild),fcn_theRoot.dispatchEvent(fcn_eventNonceReady),!fcn_isLoggedIn&&fcn_isAjaxAuth&&fcn_fetchLoginState()}function fcn_fetchLoginState(){let e=localStorage.getItem("fcnLoginState");e=!(!e||!fcn_isValidJSONString(e))&&JSON.parse(e),e&&e.loggedIn&&(fcn_setLoggedInState(e,!1),Date.now()-fictioneer_ajax.login_ttl{t.success&&t.data.loggedIn?(fcn_setLoggedInState(t.data,!e.loggedIn),localStorage.setItem("fcnLoginState",JSON.stringify({lastLoaded:Date.now(),loggedIn:t.data.loggedIn,isAdmin:t.data.isAdmin,isModerator:t.data.isModerator,isAuthor:t.data.isAuthor,isEditor:t.data.isEditor}))):(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView())})).catch((()=>{fcn_cleanupWebStorage(),fcn_cleanupGuestView()}))}function fcn_setLoggedInState(e,t=!0){fcn_isLoggedIn=e.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",e.isAdmin),fcn_theBody.classList.toggle("is-moderator",e.isModerator),fcn_theBody.classList.toggle("is-author",e.isAuthor),fcn_theBody.classList.toggle("is-editor",e.isEditor),e.isAdmin||_$$(".only-admins").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-moderators").forEach((e=>{e.remove()})),e.isAuthor||e.isAdmin||_$$(".only-authors").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-editors").forEach((e=>{e.remove()})),_$$('label[for="modal-login-toggle"], #modal-login-toggle, #login-modal').forEach((e=>{e.remove()})),t&&("function"==typeof fcn_initializeCheckmarks&&fcn_initializeCheckmarks(),"function"==typeof fcn_initializeFollows&&fcn_initializeFollows(),"function"==typeof fcn_initializeReminders&&fcn_initializeReminders(),"function"==typeof fcn_getBookmarksForUser&&fcn_getBookmarksForUser(),"function"==typeof fcn_showChapterBookmark&&fcn_showChapterBookmark(),fcn_initializeFingerprint(),fcn_getProfileImage())}function fcn_updateViewportVariables(){fcn_viewportWidth=Math.max(document.documentElement.clientWidth??0,window.innerWidth??0),fcn_mediaMinTablet=fcn_viewportWidth>=768}function fcn_loadEmbed(e){e.target.parentNode.querySelectorAll("iframe, script")[0].src=e.target.dataset.src,e.target.parentElement.querySelector(".embed-logo")?.remove(),e.target.remove()}fcn_chapterList&&_$("#story-chapter-list > ul").remove(),fcn_isLoggedIn||fcn_isAjaxAuth||(fcn_cleanupWebStorage(!0),_$$(".chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))),"function"==typeof fcn_removeQueryArgs&&fcn_removeQueryArgs(),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{fcn_cleanupWebStorage()})),fcn_theRoot.dataset.ajaxNonce&&fcn_fetchNonce(),fcn_isLoggedIn||void 0===fcn_isAjaxAuth||fcn_theRoot.dataset.ajaxNonce||fcn_fetchLoginState(),fcn_bindEventToAnimationFrame("scroll","scroll.rAF"),fcn_bindEventToAnimationFrame("resize","resize.rAF"),fcn_updateViewportVariables(),window.addEventListener("resize.rAF",fcn_throttle(fcn_updateViewportVariables,125)),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest(".toggle-last-clicked");if(t&&(!["BUTTON","A","INPUT","SELECT"].includes(e.target.tagName)||e.target.classList.contains("toggle-last-clicked")))return"function"==typeof fcn_toggleLastClicked&&fcn_toggleLastClicked(t),"function"==typeof fcn_popupPosition&&fcn_popupPosition(),void e.stopPropagation();const n=e.target.closest(".page-numbers.dots:not(button)");if(n)return void fcn_jumpPage(n);const o=e.target.closest(".spoiler");if(o)return void("function"==typeof fct_spoiler&&fct_spoiler(o));const i=e.target.closest("[data-click]"),s=i?.dataset.click;if(s)switch(s){case"copy-to-clipboard":i.select(),fcn_copyToClipboard(i.value,i.dataset.message);break;case"reset-consent":fcn_deleteCookie("fcn_cookie_consent"),location.reload();break;case"clear-cookies":fcn_deleteAllCookies(),alert(i.dataset.message);break;case"logout":fcn_cleanupWebStorage();break;case"card-toggle-follow":fcn_inlineToggleFollow(i.dataset.storyId);break;case"card-toggle-reminder":fcn_inlineToggleReminder(i.dataset.storyId);break;case"card-toggle-checkmarks":fcn_inlineToggleCheckmark(parseInt(i.dataset.storyId),i.dataset.type,parseInt(i.dataset.chapterId),i.dataset.mode);break;case"toggle-obfuscation":i.closest("[data-obfuscation-target]").classList.toggle("_obfuscated")}})),_$$(".iframe-consent, .twitter-consent").forEach((e=>{e.onclick=e=>{fcn_loadEmbed(e)}}));var fcn_lastScrollTop=0;function fcn_scrollDirection(){if(fcn_theSite.classList.contains("transformed-scroll"))return;const e=window.scrollY??document.documentElement.scrollTop;Math.abs(fcn_lastScrollTop-e)>=5&&(fcn_theBody.classList.toggle("scrolling-down",e>fcn_lastScrollTop),fcn_theBody.classList.toggle("scrolling-up",!(e>fcn_lastScrollTop)),fcn_lastScrollTop=Math.max(e,0))}window.addEventListener("scroll.rAF",fcn_throttle(fcn_scrollDirection,200));const fcn_mainObserver=new IntersectionObserver((([e])=>{fcn_theBody.classList.toggle("is-inside-main",e.intersectionRatio<1&&e.boundingClientRect.top<=0)}),{threshold:[1]});(observer=_$(".main-observer"))&&fcn_mainObserver.observe(observer);const fcn_endOfChapterObserver=new IntersectionObserver((([e])=>{fcn_theBody.classList.toggle("is-end-of-chapter",e.isIntersecting||e.boundingClientRect.top<0)}),{root:null,threshold:0});(observer=_$(".chapter-end"))&&fcn_endOfChapterObserver.observe(observer);const fct_navStickyObserver=new IntersectionObserver((([e])=>{fcn_mainNavigation.classList.toggle("is-sticky",e.intersectionRatio<1)}),{threshold:[1]});function fcn_dragElement(e){const t=e.querySelector(".drag-anchor")??e;let n,o;function i(t){t.preventDefault(),e.style.top=e.offsetTop-(o-t.clientY)+"px",e.style.left=e.offsetLeft-(n-t.clientX)+"px",n=t.clientX,o=t.clientY}function s(){t.onmouseup=null,t.onmousemove=null}t.onmousedown=function(e){e.preventDefault(),n=e.clientX,o=e.clientY,t.onmousemove=i,t.onmouseup=s}}function fcn_showNotification(e,t=3,n="base"){const o=_$("#notifications"),i=document.createElement("div");i.innerHTML=e,i.classList.add("notifications__message",`_${n}`),i.style.opacity=1,i.style.transitionDelay=`${t}s`,o.prepend(i),i.addEventListener("transitionend",(e=>{o.removeChild(e.target)})),i.addEventListener("click",(e=>{o.removeChild(e.currentTarget)})),setTimeout((()=>{i.style.opacity=0}),100)}if((observer=_$$$("nav-observer-sticky"))&&fct_navStickyObserver.observe(observer),setTimeout((()=>{fcn_theRoot.scrollTop>40&&fcn_mainNavigation?.classList.add("is-sticky")}),50),_$$(".modal__header.drag-anchor").forEach((e=>{fcn_dragElement(e.closest(".modal__wrapper"))})),"oauth_email_taken"===fcn_urlParams.failure&&fcn_showNotification(__("The associated email address is already taken. You can link additional accounts in your profile.","fictioneer"),5,"warning"),"oauth_already_linked"===fcn_urlParams.failure&&fcn_showNotification(__("Account already linked to another profile.","fictioneer"),5,"warning"),"oauth_new_subscriber"===fcn_urlParams.success&&fcn_showNotification(__("Your account has been successfully linked. Hint: You can change your display name in your profile and link additional accounts.","fictioneer"),10),fcn_urlParams.success?.includes("oauth_merged_")&&fcn_showNotification(__("Account has been successfully linked.","fictioneer"),3,"success"),fcn_urlParams["fictioneer-notice"]&&""!==fcn_urlParams["fictioneer-notice"]){let e="1"===fcn_urlParams.failure?"warning":"base";e="1"===fcn_urlParams.success?"success":e,fcn_showNotification(__(fcn_sanitizeHTML(fcn_urlParams["fictioneer-notice"]),"fictioneer"),3,e)}const fcn_settingMinimal=_$$$("site-setting-minimal"),fcn_settingChapterProgressBar=_$$$("site-setting-chapter-progress-bar"),fcn_settingHueRotateRange=_$$$("site-setting-hue-rotate-range"),fcn_settingHueRotateText=_$$$("site-setting-hue-rotate-text"),fcn_settingHueRotateReset=_$$$("site-setting-hue-rotate-reset"),fcn_settingDarkenRanges=_$$(".setting-darken-range"),fcn_settingDarkenTexts=_$$(".setting-darken-text"),fcn_settingDarkenResets=_$$(".setting-darken-reset"),fcn_settingSaturationRanges=_$$(".setting-saturation-range"),fcn_settingSaturationTexts=_$$(".setting-saturation-text"),fcn_settingSaturationResets=_$$(".setting-saturation-resets"),fcn_settingEvents=["nav-sticky","background-textures","polygons","covers","text-shadows","minimal","chapter-progress-bar"];var fcn_siteSettings=fcn_getSiteSettings();function fcn_updateSiteSetting(e,t,n){e.checked=n,fcn_siteSettings[t]=n,fcn_applySiteSettings(fcn_siteSettings)}function fcn_toggleLightMode(){fcn_setLightMode(!(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault))}function fcn_setLightMode(e,t=!1){localStorage.setItem("fcnLightmode",e),fcn_theRoot.dataset.mode=e?"light":"";const n=_$$$("reader-settings-lightmode-toggle");n&&(n.checked=e,n.closest("label").ariaChecked=e),_$$(".toggle-light-mode").forEach((t=>{t.ariaChecked=e})),t||fcn_updateThemeColor()}function fcn_updateFontWeight(){const e="default"!=fcn_siteSettings["font-weight"];_$$(".site-setting-font-weight").forEach((e=>{e.value=fcn_siteSettings["font-weight"]})),_$$(".font-weight-reset").forEach((t=>{t.classList.toggle("_modified",e)}))}function fcn_resetFontWeight(){fcn_siteSettings["font-weight"]="default",fcn_theRoot.dataset.fontWeight="default",fcn_applySiteSettings(fcn_siteSettings)}function fcn_updateHueRotate(e){e=fcn_clamp(0,360,e??0),fcn_settingHueRotateText.value=e,fcn_settingHueRotateRange.value=e,fcn_settingHueRotateReset.classList.toggle("_modified",0!=e),fcn_theRoot.style.setProperty("--hue-rotate",`${e}deg + var(--hue-offset)`),fcn_siteSettings["hue-rotate"]=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setHueRotate(){fcn_updateHueRotate(this.value)}function fcn_updateDarken(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.darken),e=Math.round(100*(e+Number.EPSILON))/100,fcn_settingDarkenResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingDarkenRanges.forEach((t=>{t.value=e})),fcn_settingDarkenTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--darken",`(${t} + var(--lightness-offset))`),fcn_siteSettings.darken=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setDarkenFromRange(){fcn_updateDarken(this.value)}function fcn_setDarkenFromText(){"-"!=this.value&&""!=this.value&&fcn_updateDarken((parseInt(this.value)??0)/100)}function fcn_updateSaturation(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.saturation),fcn_settingSaturationResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingSaturationRanges.forEach((t=>{t.value=e})),fcn_settingSaturationTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--saturation",`(${t} + var(--saturation-offset))`),fcn_siteSettings.saturation=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setSaturationFromRange(){fcn_updateSaturation(this.value)}function fcn_setSaturationFromText(){"-"!=this.value&&""!=this.value&&fcn_updateSaturation((parseInt(this.value)??0)/100)}function fcn_defaultSiteSettings(){return{"nav-sticky":!0,"background-textures":!0,polygons:!0,covers:!0,"text-shadows":!1,minimal:!1,"chapter-progress-bar":!0,"site-theme":"default","font-weight":"default",darken:0,saturation:0,"font-saturation":0,"hue-rotate":0}}function fcn_getSiteSettings(){let e=localStorage.getItem("fcnSiteSettings");return e=e&&fcn_isValidJSONString(e)?JSON.parse(e):fcn_defaultSiteSettings(),fcn_setSiteSettings(e),e}function fcn_setSiteSettings(e=null){"object"==typeof(e=e||fcn_siteSettings)&&(fcn_siteSettings=e,localStorage.setItem("fcnSiteSettings",JSON.stringify(e)))}function fcn_applySiteSettings(e){e="object"!=typeof e?fcn_defaultSiteSettings():e,Object.entries(e).forEach((e=>{const t=_$$$(`site-setting-${e[0]}`);switch(t&&(t.checked=e[1]),e[0]){case"minimal":fcn_theRoot.classList.toggle("minimal",e[1]);break;case"darken":fcn_updateDarken();break;case"saturation":fcn_updateSaturation();break;case"font-saturation":break;case"hue-rotate":fcn_updateHueRotate(e[1]);break;case"font-weight":fcn_updateFontWeight();break;default:fcn_theRoot.classList.toggle(`no-${e[0]}`,!e[1])}})),fcn_setSiteSettings(e)}function fcn_updateSiteTheme(e){fcn_siteSettings["site-theme"]=e,fcn_theRoot.dataset.theme=e,_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e),fcn_applySiteSettings(fcn_siteSettings),fcn_updateThemeColor()}function fcn_resetSiteTheme(){fcn_updateSiteTheme("default"),_$$(".site-setting-site-theme").forEach((e=>{e.value="default"}))}function fcn_inlineToggleReminder(e){if(!fcn_isLoggedIn){const e=_$$$("modal-login-toggle");return fcn_showNotification(__("You need to be logged in.","fictioneer")),void(e&&(e.checked=!0))}fcn_toggleReminder(e)}function fcn_inlineToggleFollow(e){if(!fcn_isLoggedIn){const e=_$$$("modal-login-toggle");return fcn_showNotification(__("You need to be logged in.","fictioneer")),void(e&&(e.checked=!0))}fcn_toggleFollow(e)}function fcn_inlineToggleCheckmark(e,t="story",n=null,o="toggle"){if(!fcn_isLoggedIn){const e=_$$$("modal-login-toggle");return fcn_showNotification(__("You need to be logged in.","fictioneer")),void(e&&(e.checked=!0))}fcn_toggleCheckmark(e,t,n,null,o),fcn_updateCheckmarksView()}function fcn_jumpPage(e){if(fcn_theRoot.dataset.disablePageJump)return;const t=parseInt(window.prompt(_x("Enter page number:","Pagination jump prompt.","fictioneer")));if(t>0){const n=e.nextElementSibling.getAttribute("href"),o=["page=","paged=","comment-page-","pg="];for(const e of o)if(n.includes(e))return void(window.location.href=n.replace(new RegExp(`${e}\\d+`),e+t));window.location.href=n.replace(/page\/\d+/,`page/${t}`)}}fcn_settingEvents.forEach((e=>{_$$$(`site-setting-${e}`).onchange=t=>{fcn_updateSiteSetting(t.currentTarget,e,t.currentTarget.checked)}})),fcn_setLightMode(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault,!0),_$$(".toggle-light-mode").forEach((e=>{e.onclick=()=>fcn_toggleLightMode()})),_$$(".font-weight-reset").forEach((e=>{e.addEventListener("click",fcn_resetFontWeight)})),_$$(".site-setting-font-weight").forEach((e=>{e.onchange=e=>{fcn_siteSettings["font-weight"]=e.target.value,fcn_theRoot.dataset.fontWeight=e.target.value,fcn_applySiteSettings(fcn_siteSettings),fcn_updateFontWeight()}})),fcn_settingHueRotateReset?.addEventListener("click",(()=>{fcn_updateHueRotate(0)})),fcn_settingHueRotateRange?.addEventListener("input",fcn_throttle(fcn_setHueRotate,1e3/24)),fcn_settingHueRotateText?.addEventListener("input",fcn_setHueRotate),fcn_settingDarkenResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateDarken(0)}))})),fcn_settingDarkenRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setDarkenFromRange,1e3/24))})),fcn_settingDarkenTexts.forEach((e=>{e.addEventListener("input",fcn_setDarkenFromText)})),fcn_settingSaturationResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateSaturation(0)}))})),fcn_settingSaturationRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setSaturationFromRange,1e3/24))})),fcn_settingSaturationTexts.forEach((e=>{e.addEventListener("input",fcn_setSaturationFromText)})),fcn_applySiteSettings(fcn_siteSettings),_$$(".site-setting-site-theme").forEach((e=>{e.value=fcn_siteSettings.hasOwnProperty("site-theme")?fcn_siteSettings["site-theme"]:"default",_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e.value),e.addEventListener("change",(e=>{fcn_updateSiteTheme(e.target.value)}))})),_$$$("site-setting-theme-reset")?.addEventListener("click",fcn_resetSiteTheme),fcn_updateThemeColor();const fcn_cardLists=_$$(".card-list:not(._no-mutation-observer)");var fcn_cardListMutationObserver=new MutationObserver((e=>{e[0].addedNodes&&("function"==typeof fcn_updateFollowsView&&fcn_updateFollowsView(),"function"==typeof fcn_updateCheckmarksView&&fcn_updateCheckmarksView(),"function"==typeof fcn_updateRemindersView&&fcn_updateRemindersView())}));function fct_spoiler(e){e.classList.toggle("_open")}function fcn_revealCommentImage(e){const t=e.parentElement.querySelector("img");t.src=t.dataset.src,e.remove()}function fcn_contactFormSubmit(e){const t=e.closest("form"),n=new FormData(t),o={action:"fictioneer_ajax_submit_contact_form"};if(t.reportValidity()&&(e.disabled=!0,e.innerHTML=e.dataset.disabled,!(Date.now(){n.success?(t.querySelector("textarea").value="",e.innerHTML=e.dataset.done,fcn_showNotification(n.data.success,3,"success")):n.data.error&&(e.disabled=!1,e.innerHTML=e.dataset.enabled,fcn_showNotification(n.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),e.disabled=!1,e.innerHTML=e.dataset.enabled)})).then((()=>{t.classList.remove("ajax-in-progress")}))}}fcn_cardLists.length&&fcn_cardLists.forEach((e=>{fcn_cardListMutationObserver.observe(e,{childList:!0,subtree:!0})})),_$$(".chapter-group__name").forEach((e=>{e.addEventListener("click",(e=>{var t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list"),o=!t.classList.contains("_closed");n.style.height=`${n.scrollHeight}px`,setTimeout((()=>{t.classList.toggle("_closed",o)}),10)})),e.closest(".chapter-group").querySelector(".chapter-group__list").addEventListener("transitionend",(e=>{const t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list");n.style.height="",n.querySelectorAll("a, button, label, input:not([hidden])").forEach((e=>{e.tabIndex=t.classList.contains("_closed")?"-1":"0"}))}))})),_$(".fictioneer-comments")?.addEventListener("click",(e=>{e.target?.classList.contains("consent-button")&&fcn_revealCommentImage(e.target)})),_$$(".fcn-contact-form").forEach((e=>{e.querySelector(".fcn-contact-form__submit").addEventListener("click",(e=>{fcn_contactFormSubmit(e.currentTarget)}))})),fcn_theBody.querySelectorAll(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{if(e.currentTarget.checked){const t=e.currentTarget.nextElementSibling.querySelector('[tabindex="0"]');t?.focus(),t?.blur()}else fcn_theBody.classList.contains("user-is-tabbing")&&fcn_theSite.querySelector(`label[for="${e.currentTarget.id}"]`)?.focus()}))})),fcn_theBody.addEventListener("keydown",(e=>{let t=document.activeElement.closest('[tabindex="0"]:not(a, input, button, select)');if(["BUTTON","A","INPUT","SELECT"].includes(document.activeElement.tagName)&&(t=null),t&&(32!=e.keyCode&&13!=e.keyCode||(e.preventDefault(),t.click())),27==e.keyCode){_$$(".modal-toggle:checked").forEach((e=>{e.checked=!1,e.dispatchEvent(new Event("change"))}));const e=_$(".lightbox.show");if(e)return void e.querySelector(".lightbox__close").click();const t=_$(".selected-paragraph #button-close-paragraph-tools");if(t)return void t.click();const n=_$("#tts-interface:not(.hidden)");if(n){if(n.classList.contains("playing")){const e=_$$$("button-tts-pause");e?.click(),e?.focus(),e?.blur()}else _$$$("button-tts-stop").click();return}}}));class FCN_KeywordInput{constructor(e){this.input=e,this.operator=e.closest(".keyword-input").querySelector(".keyword-input__operator input"),this.inputWrapper=e.closest(".keyword-input__input-wrapper"),this.block=e.closest(".keyword-input"),this.form=this.block.closest(".search-form"),this.collection=this.block.querySelector(".keyword-input__collection"),this.suggestionList=this.block.querySelector(".keyword-input__suggestion-list"),this.tabSuggestion=this.block.querySelector(".keyword-input__tab-suggestion"),this.allowText=this.form.querySelector(".allow-list")?.innerText??"{}",this.allowList=JSON.parse(this.allowText),this.hints=this.block.querySelector(".keyword-input__hints"),this.noHint=this.block.querySelector(".keyword-input__no-suggestions"),this.keywords=this.collection.value.length>0?this.collection.value.split(","):[],this.bindEvents(),this.resize(),this.filterSuggestions()}resize(){fcn_resizeInput(this.input,this.tabSuggestion.innerText.length>0?this.tabSuggestion.innerText.length:this.input.value.length)}reset(){this.keywords=[],this.block.querySelectorAll(".node").forEach((e=>{e.remove()})),this.block.querySelectorAll(".keyword-input__operator > input").forEach((e=>{e.checked=!1})),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}encode(e){return encodeURIComponent(e.toLowerCase()).replace(/'/g,"%27")}filterSuggestions(){const e=this.input.value.toLowerCase();let t=0,n="";""==e?this.suggestionList.querySelectorAll(".keyword-button").forEach((e=>{e.hidden=!0})):this.suggestionList.querySelectorAll(".keyword-button").forEach((o=>{const i=o.innerText.toLowerCase();i.includes(e)&&this.keywords.indexOf(i)<0?(o.hidden=!1,t++,""==n&&i.startsWith(e)&&(n=i)):o.hidden=!0})),this.hints.querySelectorAll(".keyword-button").forEach((e=>{this.keywords.indexOf(e.value.toLowerCase())>-1?e.hidden=!0:e.hidden=!1})),this.tabSuggestion.innerHTML=n,this.hints.hidden=!(""==e),this.noHint.hidden=!(""!=e&&t<1)}addNode(e=null){const t=e??this.input.value.replace(",",""),n=this.allowList[this.encode(t)];if(!n||this.keywords.indexOf(n)>-1)return;this.keywords.push(n);const o=document.createElement("div");o.innerHTML=`${t}`,o.classList.add("node"),o.dataset.value=n,this.inputWrapper.parentNode.insertBefore(o,this.inputWrapper),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}removeNodeByValue(e){this.block.querySelector(`[data-value="${e}"]`)?.remove(),this.keywords.splice(this.keywords.indexOf(e),1),this.updateCollection(),this.filterSuggestions(),this.resize()}updateCollection(){this.collection.value=this.keywords.join(","),this.block.classList.toggle("_empty",""===this.collection.value),this.form.querySelector(".search-form__current").innerHTML=""}bindEvents(){this.operator&&this.operator.addEventListener("change",(e=>{e.currentTarget.closest("label").ariaChecked=e.currentTarget.checked})),this.input.addEventListener("input",(e=>{e.currentTarget.value.includes(",")&&this.addNode(),this.block.classList.toggle("_empty",""===e.currentTarget.value),this.filterSuggestions(),this.resize()})),this.input.addEventListener("keydown",(e=>{9!=e.keyCode&&13!=e.keyCode||""!=this.tabSuggestion.innerText&&(e.preventDefault(),this.input.value=this.tabSuggestion.innerText,this.addNode()),27==e.keyCode&&(this.input.value="",this.tabSuggestion.innerHTML="",document.activeElement.blur()),8==e.keyCode&&""==this.input.value&&this.keywords.length>0&&this.removeNodeByValue(this.keywords.slice(-1))})),this.input.addEventListener("blur",(()=>{const e=this.allowList[this.encode(this.input.value)];this.blurTimeout=e?setTimeout((()=>{this.addNode()}),150):setTimeout((()=>{this.input.value="",this.tabSuggestion.innerHTML="",this.filterSuggestions(),this.resize()}),150)})),this.block.addEventListener("click",(e=>{e.target.closest(".node-delete")&&(e.preventDefault(),this.removeNodeByValue(e.target.closest(".node").dataset.value))})),this.block.querySelectorAll(".keyword-button").forEach((e=>{e.addEventListener("click",(e=>{clearTimeout(this.blurTimeout),this.addNode(e.currentTarget.innerText)}))}))}}function fcn_handleTabInput(e){9==e.keyCode&&(fcn_theBody.classList.add("user-is-tabbing"),window.removeEventListener("keydown",fcn_handleTabInput),window.addEventListener("mousedown",fcn_handleMouseInput))}function fcn_handleMouseInput(){fcn_theBody.classList.remove("user-is-tabbing"),window.removeEventListener("mousedown",fcn_handleMouseInput),window.addEventListener("keydown",fcn_handleTabInput)}function fcn_popupPosition(){_$$(".popup-menu-toggle.last-clicked .popup-menu:not(._fixed-position)").forEach((e=>{if("none"===window.getComputedStyle(e).display)return;const t=fcn_detectScreenCollision(e);t&&0===t.length||(t.includes("top")?(e.classList.remove("_top"),e.classList.add("_bottom")):t.includes("bottom")&&(e.classList.remove("_bottom"),e.classList.add("_top")))}))}function fcn_markCurrentMenuItem(){_$$(`.menu-item > [data-nav-object-id="${fcn_theBody.dataset.postId}"]`).forEach((e=>{e.setAttribute("aria-current","page"),e.closest(".menu-item").classList.add("current-menu-item")}))}_$$(".search-form").forEach((e=>{const t=[];e.classList.contains("_simple")||(e.querySelectorAll(".keyword-input__input").forEach((e=>{t.push(new FCN_KeywordInput(e))})),e.querySelector(".allow-list")?.remove(),e.addEventListener("change",(t=>{t.target.classList.contains("search-form__advanced-control")||t.target.classList.contains("search-form__string")||(e.querySelector(".search-form__current").innerHTML="")})),e.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(o=>{t.forEach((e=>{e.reset()})),e.querySelector("input[name=s]").value="",e.querySelector("select[name=post_type]").value="any",e.querySelector("select[name=sentence]").value="0",e.querySelector("select[name=orderby]").value="modified",e.querySelector("select[name=order]").value="desc",e.querySelector(".search-form__current").innerHTML="",fcn_showNotification(n.dataset.reset,2)}))})))})),_$$(".search-form__advanced-control").forEach((e=>{e.addEventListener("change",(e=>{const t=e.currentTarget.closest("form");t.dataset.advanced="true"==t.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",fcn_throttle(fcn_popupPosition,250)),_$$(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{const t=_$$$(e.currentTarget.dataset.target);t.classList.toggle("_open",e.currentTarget.checked);const n=t.querySelector(".close");n?.focus(),n?.blur()}))})),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest("[href]"),n=t?.getAttribute("href");if(t&&"A"===t.tagName&&n.startsWith("#")&&n.length>1&&"#respond"!==n){const o=n.replace("#",""),i=_$$(`[name="${o}"], #${o}`)[0],s=t.closest(".comment._story-comment");if(s){const e=s.querySelector(".fictioneer-comment__link").href+n;e&&(window.location.href=e)}i&&(e.preventDefault(),i.scrollIntoView({behavior:"smooth",block:t.dataset?.block??"start"}))}})),fcn_markCurrentMenuItem(); \ No newline at end of file +const fcn_theSite=_$$$("site"),fcn_theBody=_$("body"),fcn_theRoot=document.documentElement,fcn_inlineStorage=_$$$("inline-storage").dataset,fcn_mainNavigation=_$$$("full-navigation"),fcn_urlSearchParams=new URLSearchParams(window.location.search),fcn_urlParams=Object.fromEntries(fcn_urlSearchParams.entries()),fcn_pageLoadTimestamp=Date.now(),fcn_ajaxLimitThreshold=Date.now()-parseInt(fictioneer_ajax.ttl),fcn_eventNonceReady=new Event("nonceReady"),fcn_isAjaxAuth=fcn_theRoot.dataset.ajaxAuth;var fcn_viewportWidth,fcn_mediaMinTablet,fcn_cssVars=getComputedStyle(document.documentElement),fcn_isLoggedIn=fcn_theBody.classList.contains("logged-in"),fcn_chapterList=_$("#story-chapter-list > ul")?.cloneNode(!0);const{__:__,_x:_x,_n:_n,sprintf:sprintf}=wp.i18n;function fcn_cleanupWebStorage(e=!1){localStorage.removeItem("fcnProfileAvatar"),localStorage.removeItem("fcnStoryFollows"),localStorage.removeItem("fcnStoryReminders"),localStorage.removeItem("fcnCheckmarks"),localStorage.removeItem("fcnFingerprint"),localStorage.removeItem("fcnLoginState"),localStorage.removeItem("fcnBookshelfContent"),e||localStorage.removeItem("fcnChapterBookmarks");let t=localStorage.getItem("fcnNonce");t=!(!t||!fcn_isValidJSONString(t))&&JSON.parse(t),t&&t.loggedIn&&localStorage.removeItem("fcnNonce")}function fcn_cleanupGuestView(){fcn_isLoggedIn=!1,fcn_theBody.classList.remove("logged-in","is-admin","is-moderator","is-editor","is-author"),_$$(".only-moderators, .only-admins, .only-authors, .only-editors, .chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))}function fcn_fetchNonce(){let e=localStorage.getItem("fcnNonce");e=!(!e||!fcn_isValidJSONString(e))&&JSON.parse(e),e&&!e.loggedIn&&fcn_isLoggedIn&&(localStorage.removeItem("fcnNonce"),e=!1),e&&(fcn_addNonceAndAuth(e.nonceHtml),fcn_ajaxLimitThreshold{_$$$("fictioneer-ajax-nonce")?.remove(),e.success?(fcn_addNonceAndAuth(e.data.nonceHtml),localStorage.setItem("fcnNonce",JSON.stringify({lastLoaded:Date.now(),nonceHtml:e.data.nonceHtml,loggedIn:fcn_isLoggedIn}))):(_$$$("fictioneer-ajax-nonce")?.remove(),fcn_cleanupGuestView())})).catch((()=>{localStorage.removeItem("fcnNonce"),_$$$("fictioneer-ajax-nonce")?.remove(),fcn_cleanupGuestView()}))}function fcn_addNonceAndAuth(e){const t=document.createElement("div");t.innerHTML+=e,fcn_theBody.appendChild(t.firstChild),fcn_theRoot.dispatchEvent(fcn_eventNonceReady),!fcn_isLoggedIn&&fcn_isAjaxAuth&&fcn_fetchLoginState()}function fcn_fetchLoginState(){let e=localStorage.getItem("fcnLoginState");e=!(!e||!fcn_isValidJSONString(e))&&JSON.parse(e),e&&e.loggedIn&&(fcn_setLoggedInState(e,!1),Date.now()-fictioneer_ajax.login_ttl{t.success&&t.data.loggedIn?(fcn_setLoggedInState(t.data,!e.loggedIn),localStorage.setItem("fcnLoginState",JSON.stringify({lastLoaded:Date.now(),loggedIn:t.data.loggedIn,isAdmin:t.data.isAdmin,isModerator:t.data.isModerator,isAuthor:t.data.isAuthor,isEditor:t.data.isEditor}))):(fcn_cleanupWebStorage(!0),fcn_cleanupGuestView())})).catch((()=>{fcn_cleanupWebStorage(),fcn_cleanupGuestView()}))}function fcn_setLoggedInState(e,t=!0){fcn_isLoggedIn=e.loggedIn,fcn_theBody.classList.add("logged-in"),fcn_theBody.classList.toggle("is-admin",e.isAdmin),fcn_theBody.classList.toggle("is-moderator",e.isModerator),fcn_theBody.classList.toggle("is-author",e.isAuthor),fcn_theBody.classList.toggle("is-editor",e.isEditor),e.isAdmin||_$$(".only-admins").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-moderators").forEach((e=>{e.remove()})),e.isAuthor||e.isAdmin||_$$(".only-authors").forEach((e=>{e.remove()})),e.isModerator||e.isAdmin||_$$(".only-editors").forEach((e=>{e.remove()})),_$$('label[for="modal-login-toggle"], #modal-login-toggle, #login-modal').forEach((e=>{e.remove()})),t&&("function"==typeof fcn_initializeCheckmarks&&fcn_initializeCheckmarks(),"function"==typeof fcn_initializeFollows&&fcn_initializeFollows(),"function"==typeof fcn_initializeReminders&&fcn_initializeReminders(),"function"==typeof fcn_getBookmarksForUser&&fcn_getBookmarksForUser(),"function"==typeof fcn_showChapterBookmark&&fcn_showChapterBookmark(),fcn_initializeFingerprint(),fcn_getProfileImage())}function fcn_updateViewportVariables(){fcn_viewportWidth=Math.max(document.documentElement.clientWidth??0,window.innerWidth??0),fcn_mediaMinTablet=fcn_viewportWidth>=768}function fcn_loadEmbed(e){e.target.parentNode.querySelectorAll("iframe, script")[0].src=e.target.dataset.src,e.target.parentElement.querySelector(".embed-logo")?.remove(),e.target.remove()}fcn_chapterList&&_$("#story-chapter-list > ul").remove(),fcn_isLoggedIn||fcn_isAjaxAuth||(fcn_cleanupWebStorage(!0),_$$(".chapter-group__list-item-checkmark").forEach((e=>{e.remove()}))),"function"==typeof fcn_removeQueryArgs&&fcn_removeQueryArgs(),_$("#wp-admin-bar-logout a")?.addEventListener("click",(()=>{fcn_cleanupWebStorage()})),fcn_theRoot.dataset.ajaxNonce&&fcn_fetchNonce(),fcn_isLoggedIn||void 0===fcn_isAjaxAuth||fcn_theRoot.dataset.ajaxNonce||fcn_fetchLoginState(),fcn_bindEventToAnimationFrame("scroll","scroll.rAF"),fcn_bindEventToAnimationFrame("resize","resize.rAF"),fcn_updateViewportVariables(),window.addEventListener("resize.rAF",fcn_throttle(fcn_updateViewportVariables,125)),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest(".toggle-last-clicked");if(t&&(!["BUTTON","A","INPUT","SELECT"].includes(e.target.tagName)||e.target.classList.contains("toggle-last-clicked")))return"function"==typeof fcn_toggleLastClicked&&fcn_toggleLastClicked(t),"function"==typeof fcn_popupPosition&&fcn_popupPosition(),void e.stopPropagation();const n=e.target.closest(".page-numbers.dots:not(button)");if(n)return void fcn_jumpPage(n);const o=e.target.closest(".spoiler");if(o)return void("function"==typeof fct_spoiler&&fct_spoiler(o));const i=e.target.closest("[data-click]"),s=i?.dataset.click;if(s)switch(s){case"copy-to-clipboard":i.select(),fcn_copyToClipboard(i.value,i.dataset.message);break;case"reset-consent":fcn_deleteCookie("fcn_cookie_consent"),location.reload();break;case"clear-cookies":fcn_deleteAllCookies(),alert(i.dataset.message);break;case"logout":fcn_cleanupWebStorage();break;case"card-toggle-follow":fcn_inlineToggleFollow(i.dataset.storyId);break;case"card-toggle-reminder":fcn_inlineToggleReminder(i.dataset.storyId);break;case"card-toggle-checkmarks":fcn_inlineToggleCheckmark(parseInt(i.dataset.storyId),i.dataset.type,parseInt(i.dataset.chapterId),i.dataset.mode);break;case"toggle-obfuscation":i.closest("[data-obfuscation-target]").classList.toggle("_obfuscated")}})),_$$(".iframe-consent, .twitter-consent").forEach((e=>{e.onclick=e=>{fcn_loadEmbed(e)}}));var fcn_lastScrollTop=0;function fcn_scrollDirection(){if(fcn_theSite.classList.contains("transformed-scroll"))return;const e=window.scrollY??document.documentElement.scrollTop;Math.abs(fcn_lastScrollTop-e)>=5&&(fcn_theBody.classList.toggle("scrolling-down",e>fcn_lastScrollTop),fcn_theBody.classList.toggle("scrolling-up",!(e>fcn_lastScrollTop)),fcn_lastScrollTop=Math.max(e,0))}window.addEventListener("scroll.rAF",fcn_throttle(fcn_scrollDirection,200));const fcn_mainObserver=new IntersectionObserver((([e])=>{fcn_theBody.classList.toggle("is-inside-main",e.intersectionRatio<1&&e.boundingClientRect.top<=0)}),{threshold:[1]});(observer=_$(".main-observer"))&&fcn_mainObserver.observe(observer);const fcn_endOfChapterObserver=new IntersectionObserver((([e])=>{fcn_theBody.classList.toggle("is-end-of-chapter",e.isIntersecting||e.boundingClientRect.top<0)}),{root:null,threshold:0});(observer=_$(".chapter-end"))&&fcn_endOfChapterObserver.observe(observer);const fct_navStickyObserver=new IntersectionObserver((([e])=>{fcn_mainNavigation.classList.toggle("is-sticky",e.intersectionRatio<1)}),{threshold:[1]});function fcn_dragElement(e){const t=e.querySelector(".drag-anchor")??e;let n,o;function i(t){t.preventDefault(),e.style.top=e.offsetTop-(o-t.clientY)+"px",e.style.left=e.offsetLeft-(n-t.clientX)+"px",n=t.clientX,o=t.clientY}function s(){t.onmouseup=null,t.onmousemove=null}t.onmousedown=function(e){e.preventDefault(),n=e.clientX,o=e.clientY,t.onmousemove=i,t.onmouseup=s}}function fcn_showNotification(e,t=3,n="base"){const o=_$("#notifications"),i=document.createElement("div");i.innerHTML=e,i.classList.add("notifications__message",`_${n}`),i.style.opacity=1,i.style.transitionDelay=`${t}s`,o.prepend(i),i.addEventListener("transitionend",(e=>{o.removeChild(e.target)})),i.addEventListener("click",(e=>{o.removeChild(e.currentTarget)})),setTimeout((()=>{i.style.opacity=0}),100)}if((observer=_$$$("nav-observer-sticky"))&&fct_navStickyObserver.observe(observer),setTimeout((()=>{fcn_theRoot.scrollTop>40&&fcn_mainNavigation?.classList.add("is-sticky")}),50),_$$(".modal__header.drag-anchor").forEach((e=>{fcn_dragElement(e.closest(".modal__wrapper"))})),"oauth_email_taken"===fcn_urlParams.failure&&fcn_showNotification(__("The associated email address is already taken. You can link additional accounts in your profile.","fictioneer"),5,"warning"),"oauth_already_linked"===fcn_urlParams.failure&&fcn_showNotification(__("Account already linked to another profile.","fictioneer"),5,"warning"),"oauth_new_subscriber"===fcn_urlParams.success&&fcn_showNotification(__("Your account has been successfully linked. Hint: You can change your display name in your profile and link additional accounts.","fictioneer"),10),fcn_urlParams.success?.includes("oauth_merged_")&&fcn_showNotification(__("Account has been successfully linked.","fictioneer"),3,"success"),fcn_urlParams["fictioneer-notice"]&&""!==fcn_urlParams["fictioneer-notice"]){let e="1"===fcn_urlParams.failure?"warning":"base";e="1"===fcn_urlParams.success?"success":e,fcn_showNotification(__(fcn_sanitizeHTML(fcn_urlParams["fictioneer-notice"]),"fictioneer"),3,e)}const fcn_settingMinimal=_$$$("site-setting-minimal"),fcn_settingChapterProgressBar=_$$$("site-setting-chapter-progress-bar"),fcn_settingHueRotateRange=_$$$("site-setting-hue-rotate-range"),fcn_settingHueRotateText=_$$$("site-setting-hue-rotate-text"),fcn_settingHueRotateReset=_$$$("site-setting-hue-rotate-reset"),fcn_settingDarkenRanges=_$$(".setting-darken-range"),fcn_settingDarkenTexts=_$$(".setting-darken-text"),fcn_settingDarkenResets=_$$(".setting-darken-reset"),fcn_settingSaturationRanges=_$$(".setting-saturation-range"),fcn_settingSaturationTexts=_$$(".setting-saturation-text"),fcn_settingSaturationResets=_$$(".setting-saturation-resets"),fcn_settingEvents=["nav-sticky","background-textures","polygons","covers","text-shadows","minimal","chapter-progress-bar"];var fcn_siteSettings=fcn_getSiteSettings();function fcn_updateSiteSetting(e,t,n){e.checked=n,fcn_siteSettings[t]=n,fcn_applySiteSettings(fcn_siteSettings)}function fcn_toggleLightMode(){fcn_setLightMode(!(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault))}function fcn_setLightMode(e,t=!1){localStorage.setItem("fcnLightmode",e),fcn_theRoot.dataset.mode=e?"light":"";const n=_$$$("reader-settings-lightmode-toggle");n&&(n.checked=e,n.closest("label").ariaChecked=e),_$$(".toggle-light-mode").forEach((t=>{t.ariaChecked=e})),t||fcn_updateThemeColor()}function fcn_updateFontWeight(){const e="default"!=fcn_siteSettings["font-weight"];_$$(".site-setting-font-weight").forEach((e=>{e.value=fcn_siteSettings["font-weight"]})),_$$(".font-weight-reset").forEach((t=>{t.classList.toggle("_modified",e)}))}function fcn_resetFontWeight(){fcn_siteSettings["font-weight"]="default",fcn_theRoot.dataset.fontWeight="default",fcn_applySiteSettings(fcn_siteSettings)}function fcn_updateHueRotate(e){e=fcn_clamp(0,360,e??0),fcn_settingHueRotateText.value=e,fcn_settingHueRotateRange.value=e,fcn_settingHueRotateReset.classList.toggle("_modified",0!=e),fcn_theRoot.style.setProperty("--hue-rotate",`${e}deg + var(--hue-offset)`),fcn_siteSettings["hue-rotate"]=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setHueRotate(){fcn_updateHueRotate(this.value)}function fcn_updateDarken(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.darken),e=Math.round(100*(e+Number.EPSILON))/100,fcn_settingDarkenResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingDarkenRanges.forEach((t=>{t.value=e})),fcn_settingDarkenTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--darken",`(${t} + var(--lightness-offset))`),fcn_siteSettings.darken=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setDarkenFromRange(){fcn_updateDarken(this.value)}function fcn_setDarkenFromText(){"-"!=this.value&&""!=this.value&&fcn_updateDarken((parseInt(this.value)??0)/100)}function fcn_updateSaturation(e=null){e=fcn_clamp(-1,1,e??fcn_siteSettings.saturation),fcn_settingSaturationResets.forEach((t=>{t.classList.toggle("_modified",0!=e)})),fcn_settingSaturationRanges.forEach((t=>{t.value=e})),fcn_settingSaturationTexts.forEach((t=>{t.value=parseInt(100*e)}));const t=e>=0?1+Math.pow(e,2):1-Math.pow(e,2);fcn_theRoot.style.setProperty("--saturation",`(${t} + var(--saturation-offset))`),fcn_siteSettings.saturation=e,fcn_setSiteSettings(),fcn_updateThemeColor()}function fcn_setSaturationFromRange(){fcn_updateSaturation(this.value)}function fcn_setSaturationFromText(){"-"!=this.value&&""!=this.value&&fcn_updateSaturation((parseInt(this.value)??0)/100)}function fcn_defaultSiteSettings(){return{"nav-sticky":!0,"background-textures":!0,polygons:!0,covers:!0,"text-shadows":!1,minimal:!1,"chapter-progress-bar":!0,"site-theme":"default","font-weight":"default",darken:0,saturation:0,"font-saturation":0,"hue-rotate":0}}function fcn_getSiteSettings(){let e=localStorage.getItem("fcnSiteSettings");return e=e&&fcn_isValidJSONString(e)?JSON.parse(e):fcn_defaultSiteSettings(),fcn_setSiteSettings(e),e}function fcn_setSiteSettings(e=null){"object"==typeof(e=e||fcn_siteSettings)&&(fcn_siteSettings=e,localStorage.setItem("fcnSiteSettings",JSON.stringify(e)))}function fcn_applySiteSettings(e){e="object"!=typeof e?fcn_defaultSiteSettings():e,Object.entries(e).forEach((e=>{const t=_$$$(`site-setting-${e[0]}`);switch(t&&(t.checked=e[1]),e[0]){case"minimal":fcn_theRoot.classList.toggle("minimal",e[1]);break;case"darken":fcn_updateDarken();break;case"saturation":fcn_updateSaturation();break;case"font-saturation":break;case"hue-rotate":fcn_updateHueRotate(e[1]);break;case"font-weight":fcn_updateFontWeight();break;default:fcn_theRoot.classList.toggle(`no-${e[0]}`,!e[1])}})),fcn_setSiteSettings(e)}function fcn_updateSiteTheme(e){fcn_siteSettings["site-theme"]=e,fcn_theRoot.dataset.theme=e,_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e),fcn_applySiteSettings(fcn_siteSettings),fcn_updateThemeColor()}function fcn_resetSiteTheme(){fcn_updateSiteTheme("default"),_$$(".site-setting-site-theme").forEach((e=>{e.value="default"}))}function fcn_inlineToggleReminder(e){if(!fcn_isLoggedIn){const e=_$$$("modal-login-toggle");return fcn_showNotification(__("You need to be logged in.","fictioneer")),void(e&&(e.checked=!0))}fcn_toggleReminder(e)}function fcn_inlineToggleFollow(e){if(!fcn_isLoggedIn){const e=_$$$("modal-login-toggle");return fcn_showNotification(__("You need to be logged in.","fictioneer")),void(e&&(e.checked=!0))}fcn_toggleFollow(e)}function fcn_inlineToggleCheckmark(e,t="story",n=null,o="toggle"){if(!fcn_isLoggedIn){const e=_$$$("modal-login-toggle");return fcn_showNotification(__("You need to be logged in.","fictioneer")),void(e&&(e.checked=!0))}fcn_toggleCheckmark(e,t,n,null,o),fcn_updateCheckmarksView()}function fcn_jumpPage(e){if(fcn_theRoot.dataset.disablePageJump)return;const t=parseInt(window.prompt(_x("Enter page number:","Pagination jump prompt.","fictioneer")));if(t>0){const n=e.nextElementSibling.getAttribute("href"),o=["page=","paged=","comment-page-","pg="];for(const e of o)if(n.includes(e))return void(window.location.href=n.replace(new RegExp(`${e}\\d+`),e+t));window.location.href=n.replace(/page\/\d+/,`page/${t}`)}}fcn_settingEvents.forEach((e=>{_$$$(`site-setting-${e}`).onchange=t=>{fcn_updateSiteSetting(t.currentTarget,e,t.currentTarget.checked)}})),fcn_setLightMode(localStorage.getItem("fcnLightmode")?"true"==localStorage.getItem("fcnLightmode"):"light"==fcn_theRoot.dataset.modeDefault,!0),_$$(".toggle-light-mode").forEach((e=>{e.onclick=()=>fcn_toggleLightMode()})),_$$(".font-weight-reset").forEach((e=>{e.addEventListener("click",fcn_resetFontWeight)})),_$$(".site-setting-font-weight").forEach((e=>{e.onchange=e=>{fcn_siteSettings["font-weight"]=e.target.value,fcn_theRoot.dataset.fontWeight=e.target.value,fcn_applySiteSettings(fcn_siteSettings),fcn_updateFontWeight()}})),fcn_settingHueRotateReset?.addEventListener("click",(()=>{fcn_updateHueRotate(0)})),fcn_settingHueRotateRange?.addEventListener("input",fcn_throttle(fcn_setHueRotate,1e3/24)),fcn_settingHueRotateText?.addEventListener("input",fcn_setHueRotate),fcn_settingDarkenResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateDarken(0)}))})),fcn_settingDarkenRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setDarkenFromRange,1e3/24))})),fcn_settingDarkenTexts.forEach((e=>{e.addEventListener("input",fcn_setDarkenFromText)})),fcn_settingSaturationResets.forEach((e=>{e.addEventListener("click",(()=>{fcn_updateSaturation(0)}))})),fcn_settingSaturationRanges.forEach((e=>{e.addEventListener("input",fcn_throttle(fcn_setSaturationFromRange,1e3/24))})),fcn_settingSaturationTexts.forEach((e=>{e.addEventListener("input",fcn_setSaturationFromText)})),fcn_applySiteSettings(fcn_siteSettings),_$$(".site-setting-site-theme").forEach((e=>{e.value=fcn_siteSettings.hasOwnProperty("site-theme")?fcn_siteSettings["site-theme"]:"default",_$$$("site-setting-theme-reset").classList.toggle("_modified","default"!=e.value),e.addEventListener("change",(e=>{fcn_updateSiteTheme(e.target.value)}))})),_$$$("site-setting-theme-reset")?.addEventListener("click",fcn_resetSiteTheme),fcn_updateThemeColor();const fcn_cardLists=_$$(".card-list:not(._no-mutation-observer)");var fcn_cardListMutationObserver=new MutationObserver((e=>{e[0].addedNodes&&("function"==typeof fcn_updateFollowsView&&fcn_updateFollowsView(),"function"==typeof fcn_updateCheckmarksView&&fcn_updateCheckmarksView(),"function"==typeof fcn_updateRemindersView&&fcn_updateRemindersView())}));function fct_spoiler(e){e.classList.toggle("_open")}function fcn_revealCommentImage(e){const t=e.parentElement.querySelector("img");t.src=t.dataset.src,e.remove()}function fcn_contactFormSubmit(e){const t=e.closest("form"),n=new FormData(t),o={action:"fictioneer_ajax_submit_contact_form"};if(t.reportValidity()&&(e.disabled=!0,e.innerHTML=e.dataset.disabled,!(Date.now(){n.success?(t.querySelector("textarea").value="",e.innerHTML=e.dataset.done,fcn_showNotification(n.data.success,3,"success")):n.data.error&&(e.disabled=!1,e.innerHTML=e.dataset.enabled,fcn_showNotification(n.data.error,5,"warning"))})).catch((t=>{t.status&&t.statusText&&(fcn_showNotification(`${t.status}: ${t.statusText}`,5,"warning"),e.disabled=!1,e.innerHTML=e.dataset.enabled)})).then((()=>{t.classList.remove("ajax-in-progress")}))}}fcn_cardLists.length&&fcn_cardLists.forEach((e=>{fcn_cardListMutationObserver.observe(e,{childList:!0,subtree:!0})})),_$$(".chapter-group__name").forEach((e=>{e.addEventListener("click",(e=>{var t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list"),o=!t.classList.contains("_closed");n.style.height=`${n.scrollHeight}px`,setTimeout((()=>{t.classList.toggle("_closed",o)}),10)})),e.closest(".chapter-group").querySelector(".chapter-group__list").addEventListener("transitionend",(e=>{const t=e.currentTarget.closest(".chapter-group"),n=t.querySelector(".chapter-group__list");n.style.height="",n.querySelectorAll("a, button, label, input:not([hidden])").forEach((e=>{e.tabIndex=t.classList.contains("_closed")?"-1":"0"}))}))})),_$(".fictioneer-comments")?.addEventListener("click",(e=>{e.target?.classList.contains("consent-button")&&fcn_revealCommentImage(e.target)})),_$$(".fcn-contact-form").forEach((e=>{e.querySelector(".fcn-contact-form__submit").addEventListener("click",(e=>{fcn_contactFormSubmit(e.currentTarget)}))})),fcn_theBody.querySelectorAll(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{if(e.currentTarget.checked){const t=e.currentTarget.nextElementSibling.querySelector('[tabindex="0"]');t?.focus(),t?.blur()}else fcn_theBody.classList.contains("user-is-tabbing")&&fcn_theSite.querySelector(`label[for="${e.currentTarget.id}"]`)?.focus()}))})),fcn_theBody.addEventListener("keydown",(e=>{let t=document.activeElement.closest('[tabindex="0"]:not(a, input, button, select)');if(["BUTTON","A","INPUT","SELECT"].includes(document.activeElement.tagName)&&(t=null),t&&(32!=e.keyCode&&13!=e.keyCode||(e.preventDefault(),t.click())),27==e.keyCode){_$$(".modal-toggle:checked").forEach((e=>{e.checked=!1,e.dispatchEvent(new Event("change"))}));const e=_$(".lightbox.show");if(e)return void e.querySelector(".lightbox__close").click();const t=_$(".selected-paragraph #button-close-paragraph-tools");if(t)return void t.click();const n=_$("#tts-interface:not(.hidden)");if(n){if(n.classList.contains("playing")){const e=_$$$("button-tts-pause");e?.click(),e?.focus(),e?.blur()}else _$$$("button-tts-stop").click();return}}}));class FCN_KeywordInput{constructor(e){this.input=e,this.operator=e.closest(".keyword-input").querySelector(".keyword-input__operator input"),this.inputWrapper=e.closest(".keyword-input__input-wrapper"),this.block=e.closest(".keyword-input"),this.form=this.block.closest(".search-form"),this.collection=this.block.querySelector(".keyword-input__collection"),this.suggestionList=this.block.querySelector(".keyword-input__suggestion-list"),this.tabSuggestion=this.block.querySelector(".keyword-input__tab-suggestion"),this.allowText=this.form.querySelector(".allow-list")?.innerText??"{}",this.allowList=JSON.parse(this.allowText),this.hints=this.block.querySelector(".keyword-input__hints"),this.noHint=this.block.querySelector(".keyword-input__no-suggestions"),this.keywords=this.collection.value.length>0?this.collection.value.split(","):[],this.bindEvents(),this.resize(),this.filterSuggestions()}resize(){fcn_resizeInput(this.input,this.tabSuggestion.innerText.length>0?this.tabSuggestion.innerText.length:this.input.value.length)}reset(){this.keywords=[],this.block.querySelectorAll(".node").forEach((e=>{e.remove()})),this.block.querySelectorAll(".keyword-input__operator > input").forEach((e=>{e.checked=!1})),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}encode(e){return encodeURIComponent(e.toLowerCase()).replace(/'/g,"%27")}filterSuggestions(){const e=this.input.value.toLowerCase();let t=0,n="";""==e?this.suggestionList.querySelectorAll(".keyword-button").forEach((e=>{e.hidden=!0})):this.suggestionList.querySelectorAll(".keyword-button").forEach((o=>{const i=o.innerText.toLowerCase();i.includes(e)&&this.keywords.indexOf(i)<0?(o.hidden=!1,t++,""==n&&i.startsWith(e)&&(n=i)):o.hidden=!0})),this.hints.querySelectorAll(".keyword-button").forEach((e=>{this.keywords.indexOf(e.value.toLowerCase())>-1?e.hidden=!0:e.hidden=!1})),this.tabSuggestion.innerHTML=n,this.hints.hidden=!(""==e),this.noHint.hidden=!(""!=e&&t<1)}addNode(e=null){const t=e??this.input.value.replace(",",""),n=this.allowList[this.encode(t)];if(!n||this.keywords.indexOf(n)>-1)return;this.keywords.push(n);const o=document.createElement("div");o.innerHTML=`${t}`,o.classList.add("node"),o.dataset.value=n,this.inputWrapper.parentNode.insertBefore(o,this.inputWrapper),this.input.value="",this.updateCollection(),this.filterSuggestions(),this.resize()}removeNodeByValue(e){this.block.querySelector(`[data-value="${e}"]`)?.remove(),this.keywords.splice(this.keywords.indexOf(e),1),this.updateCollection(),this.filterSuggestions(),this.resize()}updateCollection(){this.collection.value=this.keywords.join(","),this.block.classList.toggle("_empty",""===this.collection.value),this.form.querySelector(".search-form__current").innerHTML=""}bindEvents(){this.operator&&this.operator.addEventListener("change",(e=>{e.currentTarget.closest("label").ariaChecked=e.currentTarget.checked})),this.input.addEventListener("input",(e=>{e.currentTarget.value.includes(",")&&this.addNode(),this.block.classList.toggle("_empty",""===e.currentTarget.value),this.filterSuggestions(),this.resize()})),this.input.addEventListener("keydown",(e=>{9!=e.keyCode&&13!=e.keyCode||""!=this.tabSuggestion.innerText&&(e.preventDefault(),this.input.value=this.tabSuggestion.innerText,this.addNode()),27==e.keyCode&&(this.input.value="",this.tabSuggestion.innerHTML="",document.activeElement.blur()),8==e.keyCode&&""==this.input.value&&this.keywords.length>0&&this.removeNodeByValue(this.keywords.slice(-1))})),this.input.addEventListener("blur",(()=>{const e=this.allowList[this.encode(this.input.value)];this.blurTimeout=e?setTimeout((()=>{this.addNode()}),150):setTimeout((()=>{this.input.value="",this.tabSuggestion.innerHTML="",this.filterSuggestions(),this.resize()}),150)})),this.block.addEventListener("click",(e=>{e.target.closest(".node-delete")&&(e.preventDefault(),this.removeNodeByValue(e.target.closest(".node").dataset.value))})),this.block.querySelectorAll(".keyword-button").forEach((e=>{e.addEventListener("click",(e=>{clearTimeout(this.blurTimeout),this.addNode(e.currentTarget.innerText)}))}))}}function fcn_handleTabInput(e){9==e.keyCode&&(fcn_theBody.classList.add("user-is-tabbing"),window.removeEventListener("keydown",fcn_handleTabInput),window.addEventListener("mousedown",fcn_handleMouseInput))}function fcn_handleMouseInput(){fcn_theBody.classList.remove("user-is-tabbing"),window.removeEventListener("mousedown",fcn_handleMouseInput),window.addEventListener("keydown",fcn_handleTabInput)}function fcn_popupPosition(){_$$(".popup-menu-toggle.last-clicked .popup-menu:not(._fixed-position)").forEach((e=>{if("none"===window.getComputedStyle(e).display)return;const t=fcn_detectScreenCollision(e);t&&0===t.length||(t.includes("top")?(e.classList.remove("_top"),e.classList.add("_bottom")):t.includes("bottom")&&(e.classList.remove("_bottom"),e.classList.add("_top")))}))}function fcn_markCurrentMenuItem(){_$$(`.menu-item > [data-nav-object-id="${fcn_theBody.dataset.postId}"]`).forEach((e=>{e.setAttribute("aria-current","page"),e.closest(".menu-item").classList.add("current-menu-item")}))}_$$(".search-form").forEach((e=>{const t=[];e.classList.contains("_simple")||(e.querySelectorAll(".keyword-input__input").forEach((e=>{t.push(new FCN_KeywordInput(e))})),e.querySelector(".allow-list")?.remove(),e.addEventListener("change",(t=>{t.target.classList.contains("search-form__advanced-control")||t.target.classList.contains("search-form__string")||(e.querySelector(".search-form__current").innerHTML="")})),e.querySelectorAll(".reset").forEach((n=>{n.addEventListener("click",(o=>{t.forEach((e=>{e.reset()})),e.querySelector("input[name=s]").value="",e.querySelector("select[name=post_type]").value="any",e.querySelector("select[name=sentence]").value="0",e.querySelector("select[name=orderby]").value="modified",e.querySelector("select[name=order]").value="desc",e.querySelector(".search-form__current").innerHTML="",fcn_showNotification(n.dataset.reset,2)}))})))})),_$$(".search-form__advanced-toggle").forEach((e=>{e.addEventListener("click",(e=>{const t=e.currentTarget.closest("form");t.dataset.advanced="true"==t.dataset.advanced?"false":"true"}))})),window.addEventListener("keydown",fcn_handleTabInput),window.addEventListener("scroll.rAF",fcn_throttle(fcn_popupPosition,250)),_$$(".modal-toggle").forEach((e=>{e.addEventListener("change",(e=>{const t=_$$$(e.currentTarget.dataset.target);t.classList.toggle("_open",e.currentTarget.checked);const n=t.querySelector(".close");n?.focus(),n?.blur()}))})),fcn_theBody.addEventListener("click",(e=>{const t=e.target.closest("[href]"),n=t?.getAttribute("href");if(t&&"A"===t.tagName&&n.startsWith("#")&&n.length>1&&"#respond"!==n){const o=n.replace("#",""),i=_$$(`[name="${o}"], #${o}`)[0],s=t.closest(".comment._story-comment");if(s){const e=s.querySelector(".fictioneer-comment__link").href+n;e&&(window.location.href=e)}i&&(e.preventDefault(),i.scrollIntoView({behavior:"smooth",block:t.dataset?.block??"start"}))}})),fcn_markCurrentMenuItem(); \ No newline at end of file diff --git a/searchform.php b/searchform.php index 4096b708..093c3df7 100644 --- a/searchform.php +++ b/searchform.php @@ -17,63 +17,70 @@ // Setup $no_params = empty( array_filter( $_GET ) ); -$simple_mode = isset( $args['simple'] ) && $args['simple']; -$cache_mode = isset( $args['cache'] ) && $args['cache']; +$simple_mode = $args['simple'] ?? false; +$cache_mode = $args['cache'] ?? false; $show_advanced = ! get_option( 'fictioneer_disable_theme_search' ) && ! $simple_mode; $placeholder = $args['placeholder'] ?? _x( 'Search keywords or phrase', 'Advanced search placeholder.', 'fictioneer' ); -$toggle_id = wp_unique_id( 'fictioneer-advanced-search-toggle-' ); -$post_type = $_GET['post_type'] ?? $args['preselect_type'] ?? 'any'; -$sentence = $_GET['sentence'] ?? '0'; -$order = $_GET['order'] ?? 'desc'; -$orderby = $_GET['orderby'] ?? 'modified'; -$all_authors = get_users( - array( - 'has_published_posts' => ['fcn_story', 'fcn_chapter', 'fcn_recommendation', 'post'], - 'fields' => ['ID', 'display_name'] - ) -); +// Advanced setup +if ( $show_advanced ) { + $post_type = $_GET['post_type'] ?? $args['preselect_type'] ?? 'any'; + $sentence = $_GET['sentence'] ?? '0'; + $order = $_GET['order'] ?? 'desc'; + $orderby = $_GET['orderby'] ?? 'modified'; -$skip_author_keywords = count( $all_authors ) > FICTIONEER_AUTHOR_KEYWORD_SEARCH_LIMIT; + $all_authors = get_users( + array( + 'has_published_posts' => ['fcn_story', 'fcn_chapter', 'fcn_recommendation', 'post'] + ) + ); -$queried_authors_in = $_GET['authors'] ?? 0; -$queried_authors_out = $_GET['ex_authors'] ?? 0; -$author_name = $_GET['author_name'] ?? 0; // Simple text field + $skip_author_keywords = count( $all_authors ) > FICTIONEER_AUTHOR_KEYWORD_SEARCH_LIMIT; -$all_tags = get_tags(); -$all_genres = get_tags( ['taxonomy' => 'fcn_genre'] ); -$all_fandoms = get_tags( ['taxonomy' => 'fcn_fandom'] ); -$all_characters = get_tags( ['taxonomy' => 'fcn_character'] ); -$all_warnings = get_tags( ['taxonomy' => 'fcn_content_warning'] ); + $queried_authors_in = $_GET['authors'] ?? 0; + $queried_authors_out = $_GET['ex_authors'] ?? 0; + $author_name = $_GET['author_name'] ?? 0; // Simple text field -$queried_genres = $_GET['genres'] ?? 0; -$queried_fandoms = $_GET['fandoms'] ?? 0; -$queried_characters = $_GET['characters'] ?? 0; -$queried_warnings = $_GET['warnings'] ?? 0; -$queried_tags = $_GET['tags'] ?? 0; + $all_tags = get_tags(); + $all_genres = get_tags( ['taxonomy' => 'fcn_genre'] ); + $all_fandoms = get_tags( ['taxonomy' => 'fcn_fandom'] ); + $all_characters = get_tags( ['taxonomy' => 'fcn_character'] ); + $all_warnings = get_tags( ['taxonomy' => 'fcn_content_warning'] ); -$queried_ex_genres = $_GET['ex_genres'] ?? 0; -$queried_ex_fandoms = $_GET['ex_fandoms'] ?? 0; -$queried_ex_characters = $_GET['ex_characters'] ?? 0; -$queried_ex_warnings = $_GET['ex_warnings'] ?? 0; -$queried_ex_tags = $_GET['ex_tags'] ?? 0; + $queried_genres = $_GET['genres'] ?? 0; + $queried_fandoms = $_GET['fandoms'] ?? 0; + $queried_characters = $_GET['characters'] ?? 0; + $queried_warnings = $_GET['warnings'] ?? 0; + $queried_tags = $_GET['tags'] ?? 0; -$is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified'; -$is_advanced_search = $is_advanced_search || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings; -$is_advanced_search = $is_advanced_search || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings; -$is_advanced_search = $is_advanced_search || $queried_authors_in || $queried_authors_out || $author_name; + $queried_ex_genres = $_GET['ex_genres'] ?? 0; + $queried_ex_fandoms = $_GET['ex_fandoms'] ?? 0; + $queried_ex_characters = $_GET['ex_characters'] ?? 0; + $queried_ex_warnings = $_GET['ex_warnings'] ?? 0; + $queried_ex_tags = $_GET['ex_tags'] ?? 0; -// Prepare data JSONs -$all_terms = array_merge( $all_tags, $all_genres, $all_fandoms, $all_characters, $all_warnings ); -$allow_list = []; + $is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified'; + $is_advanced_search = $is_advanced_search || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings; + $is_advanced_search = $is_advanced_search || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings; + $is_advanced_search = $is_advanced_search || $queried_authors_in || $queried_authors_out || $author_name; -foreach ( $all_terms as $term ) { - $allow_list[ rawurlencode( strtolower( $term->name ) ) ] = $term->term_id; -} + // Prime author cache + if ( function_exists( 'update_post_author_caches' ) ) { + update_post_author_caches( $all_authors ); + } -if ( ! $skip_author_keywords ) { - foreach ( $all_authors as $author ) { - $allow_list[ rawurlencode( strtolower( $author->display_name ) ) ] = $author->ID; + // Prepare data JSONs + $all_terms = array_merge( $all_tags, $all_genres, $all_fandoms, $all_characters, $all_warnings ); + $allow_list = []; + + foreach ( $all_terms as $term ) { + $allow_list[ rawurlencode( strtolower( $term->name ) ) ] = $term->term_id; + } + + if ( ! $skip_author_keywords ) { + foreach ( $all_authors as $author ) { + $allow_list[ rawurlencode( strtolower( $author->display_name ) ) ] = $author->ID; + } } } @@ -89,14 +96,6 @@ if ( ! $skip_author_keywords ) { -
@@ -114,11 +113,11 @@ if ( ! $skip_author_keywords ) {
- + >
diff --git a/src/js/application.js b/src/js/application.js index 2f0e8e38..bfe986bc 100644 --- a/src/js/application.js +++ b/src/js/application.js @@ -1851,9 +1851,9 @@ _$$('.search-form').forEach(form => { }); }); -_$$('.search-form__advanced-control').forEach(element => { +_$$('.search-form__advanced-toggle').forEach(element => { element.addEventListener( - 'change', + 'click', event => { const toggle = event.currentTarget.closest('form'); toggle.dataset.advanced = toggle.dataset.advanced == 'true' ? 'false' : 'true';