Fix story checkmark on story pages
This commit is contained in:
parent
f958cca073
commit
0a98fcacc3
2
js/checkmarks.min.js
vendored
2
js/checkmarks.min.js
vendored
@ -1 +1 @@
|
|||||||
function fcn_toggleCheckmark(e,t=null,a=null){const r=window.FictioneerApp.Controllers.fictioneerCheckmarks;if(!r)return void fcn_showNotification("Error: Checkmarks Controller not connected.",3,"warning");const s=FcnUtils.userData();let i="story";if((e=parseInt(e??0))<1)return void fcn_showNotification("Error: Invalid story ID.",3,"warning");if(null!==t){if((t=parseInt(t))<1)return void fcn_showNotification("Error: Invalid chapter ID.",3,"warning");i="chapter"}("object"!=typeof s.checkmarks.data||null===s.checkmarks.data||Array.isArray(s.checkmarks.data))&&(s.checkmarks.data={}),s.checkmarks.data[e]||(s.checkmarks.data[e]=[]),null===a&&(a="chapter"===i?!s.checkmarks.data[e]?.includes(t):!s.checkmarks.data[e]?.includes(e));const c="chapter"===i?t:e;a?s.checkmarks.data[e].push(c):(FcnUtils.removeArrayItemOnce(s.checkmarks.data[e],c),"chapter"===i&&FcnUtils.removeArrayItemOnce(s.checkmarks.data[e],e)),s.checkmarks.data[e]=s.checkmarks.data[e].filter(((e,t,a)=>a.indexOf(e)==t)),s.lastLoaded=0,FcnUtils.setUserData(s),r.refreshView(),clearTimeout(r.timeout),r.timeout=setTimeout((()=>{FcnUtils.remoteAction("fictioneer_ajax_set_checkmark",{payload:{update:s.checkmarks.data[e].join(" "),story_id:e}})}),FcnGlobals.debounceRate)}application.register("fictioneer-checkmarks",class extends Stimulus.Controller{static get targets(){return["chapterCheck","storyCheck","ribbon"]}timeout=0;initialize(){fcn()?.userReady?this.#e=!0:document.addEventListener("fcnUserDataReady",(()=>{this.refreshView(),this.#e=!0,this.#t()}))}connect(){window.FictioneerApp.Controllers.fictioneerCheckmarks=this,this.#e&&(this.refreshView(),this.#t())}data(){return this.checkmarksCachedData=FcnUtils.userData().checkmarks?.data,Array.isArray(this.checkmarksCachedData)&&0===this.checkmarksCachedData.length&&(this.checkmarksCachedData={}),this.checkmarksCachedData}toggleChapter({params:{chapter:e,story:t}}){fcn_toggleCheckmark(t,e)}toggleStory({params:{story:e}}){fcn_toggleCheckmark(e)}clear(){const e=FcnUtils.userData();e.checkmarks={data:{},updated:Date.now()},fcn().setUserData(e),this.refreshView()}refreshView(){const e=this.data();!e||Object.keys(e).length<1?this.uncheckAll():Object.entries(e).forEach((([e,t])=>{e=parseInt(e);const a=t?.includes(e);this.hasChapterCheckTarget&&(a?this.chapterCheckTargets.forEach((e=>{e.classList.toggle("marked",!0),e.setAttribute("aria-checked",!0)})):this.chapterCheckTargets.forEach((a=>{const r=parseInt(a.dataset.fictioneerCheckmarksChapterParam);if(parseInt(a.dataset.fictioneerCheckmarksStoryParam)===e){const e=t?.includes(r);a.classList.toggle("marked",e),a.setAttribute("aria-checked",e)}}))),this.hasStoryCheckTarget&&(this.storyCheckTarget.classList.toggle("marked",a),this.storyCheckTarget.setAttribute("aria-checked",a)),this.hasRibbonTarget&&this.ribbonTarget.classList.toggle("hidden",!a)}))}uncheckAll(){this.hasChapterCheckTarget&&this.chapterCheckTargets.forEach((e=>{e.classList.toggle("marked",!1),e.setAttribute("aria-checked",!1)})),this.hasStoryCheckTarget&&(this.storyCheckTarget.classList.toggle("marked",!1),this.storyCheckTarget.setAttribute("aria-checked",!1))}#e=!1;#a=!1;#r(){const e=FcnUtils.loggedIn();return e||(this.#s(),this.#a=!0),e}#i(){return this.#r()&&JSON.stringify(this.checkmarksCachedData??0)!==JSON.stringify(this.data())}#c(){this.refreshInterval||(this.refreshInterval=setInterval((()=>{!this.#a&&this.#i()&&this.refreshView()}),3e4+1e3*Math.random()))}#t(){this.#c(),this.visibilityStateCheck=()=>{this.#r()&&("visible"===document.visibilityState?(this.#a=!1,this.refreshView(),this.#c()):(this.#a=!0,clearInterval(this.refreshInterval),this.refreshInterval=null))},document.addEventListener("visibilitychange",this.visibilityStateCheck)}#s(){clearInterval(this.refreshInterval),document.removeEventListener("visibilitychange",this.visibilityStateCheck)}});
|
function fcn_toggleCheckmark(e,t=null,a=null){const r=window.FictioneerApp.Controllers.fictioneerCheckmarks;if(!r)return void fcn_showNotification("Error: Checkmarks Controller not connected.",3,"warning");const s=FcnUtils.userData();let i="story";if((e=parseInt(e??0))<1)return void fcn_showNotification("Error: Invalid story ID.",3,"warning");if(null!==t){if((t=parseInt(t))<1)return void fcn_showNotification("Error: Invalid chapter ID.",3,"warning");i="chapter"}("object"!=typeof s.checkmarks.data||null===s.checkmarks.data||Array.isArray(s.checkmarks.data))&&(s.checkmarks.data={}),s.checkmarks.data[e]||(s.checkmarks.data[e]=[]),null===a&&(a="chapter"===i?!s.checkmarks.data[e]?.includes(t):!s.checkmarks.data[e]?.includes(e));const c="chapter"===i?t:e;a?s.checkmarks.data[e].push(c):(FcnUtils.removeArrayItemOnce(s.checkmarks.data[e],c),"chapter"===i&&FcnUtils.removeArrayItemOnce(s.checkmarks.data[e],e)),s.checkmarks.data[e]=s.checkmarks.data[e].filter(((e,t,a)=>a.indexOf(e)==t)),s.lastLoaded=0,FcnUtils.setUserData(s),r.refreshView(),clearTimeout(r.timeout),r.timeout=setTimeout((()=>{FcnUtils.remoteAction("fictioneer_ajax_set_checkmark",{payload:{update:s.checkmarks.data[e].join(" "),story_id:e}})}),FcnGlobals.debounceRate)}application.register("fictioneer-checkmarks",class extends Stimulus.Controller{static get targets(){return["chapterCheck","storyCheck","ribbon"]}timeout=0;initialize(){fcn()?.userReady?this.#e=!0:document.addEventListener("fcnUserDataReady",(()=>{this.refreshView(),this.#e=!0,this.#t()}))}connect(){window.FictioneerApp.Controllers.fictioneerCheckmarks=this,this.#e&&(this.refreshView(),this.#t())}data(){return this.checkmarksCachedData=FcnUtils.userData().checkmarks?.data,Array.isArray(this.checkmarksCachedData)&&0===this.checkmarksCachedData.length&&(this.checkmarksCachedData={}),this.checkmarksCachedData}toggleChapter({params:{chapter:e,story:t}}){fcn_toggleCheckmark(t,e)}toggleStory({params:{story:e}}){fcn_toggleCheckmark(e)}clear(){const e=FcnUtils.userData();e.checkmarks={data:{},updated:Date.now()},fcn().setUserData(e),this.refreshView()}refreshView(){const e=this.data();if(!e||Object.keys(e).length<1)return void this.uncheckAll();let t=!1;Object.entries(e).forEach((([e,a])=>{e=parseInt(e),this.hasStoryCheckTarget&&e==this.storyCheckTarget.dataset.fictioneerCheckmarksStoryParam&&(t=a?.includes(e)),this.hasChapterCheckTarget&&(t?this.chapterCheckTargets.forEach((e=>{e.classList.toggle("marked",!0),e.setAttribute("aria-checked",!0)})):this.chapterCheckTargets.forEach((t=>{const r=parseInt(t.dataset.fictioneerCheckmarksChapterParam);if(parseInt(t.dataset.fictioneerCheckmarksStoryParam)===e){const e=a?.includes(r);t.classList.toggle("marked",e),t.setAttribute("aria-checked",e)}}))),this.hasStoryCheckTarget&&(this.storyCheckTarget.classList.toggle("marked",t),this.storyCheckTarget.setAttribute("aria-checked",t)),this.hasRibbonTarget&&this.ribbonTarget.classList.toggle("hidden",!t)}))}uncheckAll(){this.hasChapterCheckTarget&&this.chapterCheckTargets.forEach((e=>{e.classList.toggle("marked",!1),e.setAttribute("aria-checked",!1)})),this.hasStoryCheckTarget&&(this.storyCheckTarget.classList.toggle("marked",!1),this.storyCheckTarget.setAttribute("aria-checked",!1))}#e=!1;#a=!1;#r(){const e=FcnUtils.loggedIn();return e||(this.#s(),this.#a=!0),e}#i(){return this.#r()&&JSON.stringify(this.checkmarksCachedData??0)!==JSON.stringify(this.data())}#c(){this.refreshInterval||(this.refreshInterval=setInterval((()=>{!this.#a&&this.#i()&&this.refreshView()}),3e4+1e3*Math.random()))}#t(){this.#c(),this.visibilityStateCheck=()=>{this.#r()&&("visible"===document.visibilityState?(this.#a=!1,this.refreshView(),this.#c()):(this.#a=!0,clearInterval(this.refreshInterval),this.refreshInterval=null))},document.addEventListener("visibilitychange",this.visibilityStateCheck)}#s(){clearInterval(this.refreshInterval),document.removeEventListener("visibilitychange",this.visibilityStateCheck)}});
|
2
js/complete.min.js
vendored
2
js/complete.min.js
vendored
File diff suppressed because one or more lines are too long
@ -65,10 +65,14 @@ application.register('fictioneer-checkmarks', class extends Stimulus.Controller
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let storyChecked = false;
|
||||||
|
|
||||||
Object.entries(checkmarks).forEach(([storyId, chapterArray]) => {
|
Object.entries(checkmarks).forEach(([storyId, chapterArray]) => {
|
||||||
storyId = parseInt(storyId);
|
storyId = parseInt(storyId);
|
||||||
|
|
||||||
const storyChecked = chapterArray?.includes(storyId);
|
if (this.hasStoryCheckTarget && storyId == this.storyCheckTarget.dataset.fictioneerCheckmarksStoryParam) {
|
||||||
|
storyChecked = chapterArray?.includes(storyId);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.hasChapterCheckTarget) {
|
if (this.hasChapterCheckTarget) {
|
||||||
if (storyChecked) {
|
if (storyChecked) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user