Show pagesourceOld revisionsBacklinksBack to top Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer Reddit TeamsRecent ChangesSend via e-MailPrintPermalink × Table of Contents SaletView class CoffeeScript properties CoffeeScript methods init disableSaving enableSaving enableErasing disableErasing enableLoading disableLoading scrollTopTo scrollBottomTo scrollToBottom clearContent prepareContent write append replace clearLinks writeChoices showBlock hideBlock cycleLink SaletView class A view object is available as salet.view. It's automatically initialized when Salet loads, so it's always available with the salet object. You can't create new instances of this class. It's the only class that knows about what's jQuery, DOM and HTML. It encapsulates the DOM functions for the other classes. These are all the assumptions Salet has about your game: The game takes place inside a #page container. Everything outside the #page are non-game elements. The game text is inside the #content container. The interface can have a single button having a save ID. The interface can have a single button to load the game. The button has a load ID. The interface can have a single button to restart the game. The button has an erase ID. The interface can have a #intro block for the introduction text present before Javascript is loaded. The interface can have a block #ways containing a list of rooms available to go to. The interface can have a block #ways_hint containing a hint text for the movement block. This documentation doesn't list some system methods; see the sources if you need them. CoffeeScript properties SaletView doesn't have any properties. CoffeeScript methods init Called automatically on Salet's initialization, declares the standard event handlers. disableSaving Disables the save button when called. enableSaving Enables the save button when called. enableErasing Enables the restart button when called. disableErasing Disables the restart button when called. enableLoading Enables the save button when called. disableLoading Disables the load button when called. scrollTopTo Slowly rewinds the page to the specified number of pixels from the top edge of the screen. Regardless of the page height or rewind extent, the animation takes 500ms. Argument: number of pixels from the top edge of the screen, an integer. Required. scrollBottomTo Slowly scrolls the page to the specified number of pixels from the bottom edge of the screen. Regardless of the page height or rewind extent, the animation takes 500ms. Argument: number of pixels from the bottom edge of the screen, an integer. Required. scrollToBottom Slowly scrolls the page until the end. The animation takes 500ms. clearContent Clears the contents of the specified block. Argument: a selector for the element that needs to be cleared; by default, it's #content. This argument is optional. prepareContent Converts the argument to text. If you pass a function, it will be run. If you pass a jQuery object, it will be converted into HTML code. Argument: anything; mandatory argument. write A synonym for append but the selector is #current-room by default. append Appends the HTML provided to the text of the block provided. The text is processed by prepareContent. If the block is not found, the text would be appended to the #content block. The function returns block's HTML after appending. Argument 1: the text to append, anything. Mandatory argument. Argument 2: a selector of a block to append the text into. By default, it's #content. Optional argument. replace Replaces the text of a given block with given HTML. The text is processed by prepareContent. Argument 1: the text that replaces the original content, anything. Mandatory argument. Argument 2: a selector of a block that would have its text replaced. Mandatory argument. clearLinks If the Argument 1 is present, then the function turns all HTML links leading to this address into text. If it's omitted, then the functions turns all links into text. If the Argument 2 is present, then the function works only on the links inside that block. If it's omitted, then the functionw works inside the #page block. Argument 1: link target. Optional parameter. Argument 2: a selector of the block to work in. Optional parameter. writeChoices The function gets a list of room IDs and returns a regular list of choices linked to these rooms. The list is not sorted but if a room has canChoose = false, the text optionText would be printed not as a link but as a <span> HTML. Therefore, you can make optionText something else, for example, a form or a special button. Argument 1: a list of room IDs showBlock Shows the specified block with a nice animation. If *Salet* is not in the interactive mode (loading a game), the animation is skipped. Argument 1: block selector. Mandatory argument. hideBlock Hides the specified block with a nice animation. If *Salet* is not in the interactive mode (loading a game), the animation is skipped. Argument 1: block selector. Mandatory argument. Argument 2: removal flag. If true, then after the animation the block would be removed from DOM; if false then it will just be hidden. false by default, optional argument. cycleLink The function returns a code for the cycle link. With it you can make links that cycle their content. api en/api/view.txt Last modified: 2021/01/24 10:42by 127.0.0.1