(function(storyContent) { // Create ink story from the content using inkjs var story = new inkjs.Story(storyContent); // Global tags - those at the top of the ink file // We support: // # theme: dark // # author: Your Name var globalTags = story.globalTags; if( globalTags ) { for(var i=0; i${choice.text}` storyContainer.appendChild(choiceParagraphElement); // Fade choice in after a short delay showAfter(delay, choiceParagraphElement); delay += 200.0; // Click on choice var choiceAnchorEl = choiceParagraphElement.querySelectorAll("a")[0]; choiceAnchorEl.addEventListener("click", function(event) { if (choice.text === "Start"){ var video = document.getElementById('autoplay'); video.play(); } // Don't follow link event.preventDefault(); // Remove all existing choices removeAll("p.choice"); // Tell the story where to go next story.ChooseChoiceIndex(choice.index); // Aaand loop continueStory(); }); }); // Extend height to fit // We do this manually so that removing elements and creating new ones doesn't // cause the height (and therefore scroll) to jump backwards temporarily. storyContainer.style.height = contentBottomEdgeY()+"px"; if( !firstTime ) scrollDown(previousBottomEdge); } function restart() { story.ResetState(); setVisible(".header", true); continueStory(true); outerScrollContainer.scrollTo(0, 0); } // ----------------------------------- // Various Helper functions // ----------------------------------- // Fades in an element after a specified delay function showAfter(delay, el) { el.classList.add("hide"); setTimeout(function() { el.classList.remove("hide") }, delay); } // Scrolls the page down, but no further than the bottom edge of what you could // see previously, so it doesn't go too far. function scrollDown(previousBottomEdge) { // Line up top of screen with the bottom of where the previous content ended var target = previousBottomEdge; // Can't go further than the very bottom of the page var limit = outerScrollContainer.scrollHeight - outerScrollContainer.clientHeight; if( target > limit ) target = limit; var start = outerScrollContainer.scrollTop; var dist = target - start; var duration = 300 + 300*dist/100; var startTime = null; function step(time) { if( startTime == null ) startTime = time; var t = (time-startTime) / duration; var lerp = 3*t*t - 2*t*t*t; // ease in/out outerScrollContainer.scrollTo(0, (1.0-lerp)*start + lerp*target); if( t < 1 ) requestAnimationFrame(step); } requestAnimationFrame(step); } // The Y coordinate of the bottom end of all the story content, used // for growing the container, and deciding how far to scroll. function contentBottomEdgeY() { var bottomElement = storyContainer.lastElementChild; return bottomElement ? bottomElement.offsetTop + bottomElement.offsetHeight : 0; } // Remove all elements that match the given selector. Used for removing choices after // you've picked one, as well as for the CLEAR and RESTART tags. function removeAll(selector) { var allElements = storyContainer.querySelectorAll(selector); for(var i=0; i