ui.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /// <reference types="jquery" />
  2. export interface DialogOptions {
  3. /** Top y-coordinate of the dialog (default: 50; in pixels, but without the unit). */
  4. top?: number | undefined;
  5. /** Opacity of the overlay (default: 0.8). */
  6. opacity?: number | undefined;
  7. }
  8. export interface DialogAPI {
  9. /**
  10. * @deprecated
  11. * This method has been deprecated and should no longer be used. The core of what it does is simply to wrap
  12. * a call to Dialog.open() within a call to jQuery.ariaClick(), which can be done directly and with
  13. * greater flexibility.
  14. *
  15. * Adds WAI-ARIA-compatible mouse/keyboard event handlers to the target element(s) which open the dialog when
  16. * activated.
  17. * @param targets The DOM element(s) to attach the handler to—may be either an HTMLElement object, a jQuery object,
  18. * or a jQuery-style selector set.
  19. * @param options he options object; the currently understood properties are:
  20. * top: Top y-coordinate of the dialog (default: 50; in pixels, but without the unit).
  21. * opacity: Opacity of the overlay (default: 0.8).
  22. * @param tartFn The function to execute at the start of Dialog.addClickHandler(). This is commonly used to setup
  23. * the dialog.
  24. * @param doneFn The function to execute at the end of Dialog.addClickHandler().
  25. * @param closeFn The function to execute whenever the associated dialog is closed.
  26. * @since 2.0.0
  27. * @example
  28. * // Commonly used something like the following.
  29. * Dialog.addClickHandler("#some-element", undefined, function () {
  30. * Dialog.setup("My Dialog Title", "my-dialog-class");
  31. * Dialog.wiki(Story.get("MyDialogContents").processText());
  32. * });
  33. */
  34. addClickHandler(
  35. targets: HTMLElement | string,
  36. options?: DialogOptions,
  37. tartFn?: () => void,
  38. doneFn?: () => void,
  39. closeFn?: () => void,
  40. ): void;
  41. /**
  42. * Appends the given content to the dialog's content area. Returns a reference to the Dialog object for chaining.
  43. *
  44. * NOTE: If your content contains any SugarCube markup, you'll need to use the Dialog.wiki() method instead.
  45. * @param content The content to append. As this method is essentially a shortcut for jQuery(Dialog.body()).append
  46. * (…), see jQuery's append() method for the range of valid content types.
  47. * @since 2.9.0
  48. * @example
  49. * Dialog.append("Cry 'Havoc!', and let slip the <em>ponies</em> of <strong>friendship</strong>.");
  50. * Dialog.append( <some DOM nodes> );
  51. */
  52. append(...content: ReadonlyArray<JQuery.htmlString | JQuery.TypeOrArray<JQuery.Node | JQuery<JQuery.Node>>>): this;
  53. /**
  54. * Returns a reference to the dialog's content area
  55. * @since 2.0.0
  56. * @example
  57. * jQuery(Dialog.body()).append("Cry 'Havoc!', and let slip the <em>ponies</em> of <strong>friendship</strong>.");
  58. * jQuery(Dialog.body()).wiki("Cry 'Havoc!', and let slip the //ponies// of ''friendship''.");
  59. */
  60. body(): HTMLElement;
  61. /**
  62. * Closes the dialog. Returns a reference to the Dialog object for chaining.
  63. * @since 2.0.0
  64. */
  65. close(): this;
  66. /**
  67. * Returns whether the dialog is currently open.
  68. * @param classNames the space-separated-list of classes to check for when determining the state of the dialog.
  69. * Each of built-in dialogs contains a name-themed class which can be tested for in this manner—e.g. the Saves
  70. * dialog contains the class saves.
  71. * @since 2.0.0
  72. * @example
  73. * if (Dialog.isOpen()) {
  74. * // code to execute if the dialog is open...
  75. * }
  76. * @example
  77. * if (Dialog.isOpen("saves")) {
  78. * // code to execute if the Saves dialog is open
  79. * }
  80. */
  81. isOpen(classNames?: string): boolean;
  82. /**
  83. * Opens the dialog. Returns a reference to the Dialog object for chaining.
  84. *
  85. * NOTE: Call this only after populating the dialog with content.
  86. * @param options The options to be used when opening the dialog.
  87. * @param closeFn The function to execute whenever the dialog is closed.
  88. * @since 2.0.0
  89. */
  90. open(options?: DialogOptions, closeFn?: () => void): this;
  91. /**
  92. * Prepares the dialog for use and returns a reference to its content area.
  93. * @param title The title of the dialog.
  94. * @param classNames The space-separated-list of classes to add to the dialog.
  95. * @since 2.0.0
  96. * @example
  97. * // Basic example.
  98. * Dialog.setup();
  99. * Dialog.wiki("Blah //blah// ''blah''.");
  100. * Dialog.open();
  101. *
  102. * @example
  103. * // Adding a title to the dialog.
  104. * Dialog.setup("Character Sheet");
  105. * Dialog.wiki(Story.get("PC Sheet").processText());
  106. * Dialog.open();
  107. *
  108. * @example
  109. * // Adding a title and class to the dialog.
  110. * Dialog.setup("Character Sheet", "charsheet");
  111. * Dialog.wiki(Story.get("PC Sheet").processText());
  112. * Dialog.open();
  113. */
  114. setup(title?: string, classNames?: string): HTMLElement;
  115. /**
  116. * Renders the given markup and appends it to the dialog's content area. Returns a reference to the Dialog object
  117. * for chaining.
  118. *
  119. * NOTE: If your content consists of DOM nodes, you'll need to use the @see Dialog.append() method instead.
  120. * @param wikiMarkup The markup to render.
  121. * @since 2.9.0
  122. * @example
  123. * Dialog.wiki("Cry 'Havoc!', and let slip the //ponies// of ''friendship''.");
  124. */
  125. wiki(wikiMarkup: string): this;
  126. }
  127. export interface FullscreenRequestOptions {
  128. /**
  129. * Determines the fullscreen navigation UI preference. Valid values are (default: "auto"):
  130. * * "auto": Indicates no preference.
  131. * * "hide": Request that the browser's navigation UI be hidden. The full dimensions of the screen will be used to
  132. * display the element.
  133. * * "show": Request that the browser's navigation UI be shown. The screen dimensions allocated to the element will
  134. * be clamped to leave room for the UI.
  135. */
  136. navigationUI: "auto" | "hide" | "show";
  137. }
  138. /**
  139. * Provides access to browsers' fullscreen functionality.
  140. */
  141. export interface FullscreenAPI {
  142. /**
  143. * Current fullscreen element or, if fullscreen mode is not active, null.
  144. * @since 2.31.0
  145. */
  146. readonly element: HTMLElement;
  147. /**
  148. * Returns whether fullscreen is both supported and enabled.
  149. * @since 2.31.0
  150. */
  151. isEnabled(): boolean;
  152. /**
  153. * Returns whether fullscreen mode is currently active.
  154. * @since 2.31.0
  155. */
  156. isFullscreen(): boolean;
  157. /**
  158. * Request that the browser enter fullscreen mode.
  159. * @param options The fullscreen options object.
  160. * @param requestedEl The element to enter fullscreen mode with. If omitted, defaults to the entire page.
  161. * @since 2.31.0
  162. */
  163. request(options?: FullscreenRequestOptions, requestedEl?: HTMLElement): Promise<void>;
  164. /**
  165. * Request that the browser exit fullscreen mode.
  166. * @since 2.31.0
  167. */
  168. exit(): Promise<void>;
  169. /**
  170. * Request that the browser toggle fullscreen mode—i.e., enter or exit as appropriate.
  171. * @param options The fullscreen options object. See Fullscreen.request() for more information.
  172. * @param requestedEl The element to toggle fullscreen mode with. If omitted, defaults to the entire page.
  173. * @since 2.31.0
  174. */
  175. toggle(options?: FullscreenRequestOptions, requestedEl?: HTMLElement): Promise<void>;
  176. /**
  177. * Attaches fullscreen change event handlers.
  178. * @param handlerFn The function to invoke when fullscreen mode is changed.
  179. * @param requestedEl The element to attach the handler to.
  180. * @since 2.31.0
  181. */
  182. onChange(handlerFn: (ev: JQuery.Event) => void, requestedEl?: HTMLElement): void;
  183. /**
  184. * Removes fullscreen change event handlers.
  185. * @param handlerFn The function to remove. If omitted, will remove all handler functions.
  186. * @param requestedEl The element to remove the handler(s) from.
  187. * @since 2.31.0
  188. */
  189. offChange(handlerFn: (ev: JQuery.Event) => void, requestedEl?: HTMLElement): void;
  190. /**
  191. * Attaches fullscreen error event handlers.
  192. * @param handlerFn The function to invoke when fullscreen mode encounters an error.
  193. * @param requestedEl The element to attach the handler to.
  194. * @since 2.31.0
  195. */
  196. onError(handlerFn: (ev: JQuery.Event) => void, requestedEl?: HTMLElement): void;
  197. /**
  198. * Removes fullscreen error event handlers.
  199. * @param handlerFn The function to remove. If omitted, will remove all handler functions.
  200. * @param requestedEl The element to remove the handler(s) from.
  201. * @since 2.31.0
  202. */
  203. offError(handlerFn: (ev: JQuery.Event) => void, requestedEl?: HTMLElement): void;
  204. }
  205. export interface LoadScreenAPI {
  206. /**
  207. * Acquires a loading screen lock and returns its ID. Displays the loading screen, if necessary.
  208. * @since 2.15.0
  209. */
  210. lock(): number;
  211. /**
  212. * Releases the loading screen lock with the given ID. Hides the loading screen, if no other locks exist.
  213. * @param lockId The loading screen lock ID.
  214. * @since 2.15.0
  215. * @example
  216. * var lockId = LoadScreen.lock();
  217. * // Do something whose timing is unpredictable that should be hidden by the loading screen
  218. * LoadScreen.unlock(lockId);
  219. */
  220. unlock(lockId: number): void;
  221. }
  222. export interface UIAPI {
  223. /**
  224. * Opens the built-in alert dialog, displaying the given message to the player.
  225. * @param message The message to display to the player.
  226. * @param options The options object. @see Dialog.addClickHandler() for more information.
  227. * @param closeFn The function to execute whenever the dialog is closed.
  228. * @since 2.0.0
  229. */
  230. alert(message: string, options?: DialogOptions, closeFn?: () => void): void;
  231. /**
  232. * Opens the built-in jump to dialog, which is populated via the bookmark tag.
  233. * @param options The options object. @see Dialog.addClickHandler() for more information.
  234. * @param closeFn The function to execute whenever the dialog is closed.
  235. * @since 2.0.0
  236. */
  237. jumpto(options?: DialogOptions, closeFn?: () => void): void;
  238. /**
  239. * Opens the built-in restart dialog, prompting the player to restart the story.
  240. * @param options The options object. @see Dialog.addClickHandler() for more information.
  241. * @since 2.0.0
  242. */
  243. restart(options?: DialogOptions): void;
  244. /**
  245. * Opens the built-in saves dialog.
  246. * @param options The options object. See Dialog.addClickHandler() for more information.
  247. * @param closeFn The function to execute whenever the dialog is closed.
  248. * @since 2.0.0
  249. */
  250. saves(options?: DialogOptions, closeFn?: () => void): void;
  251. /**
  252. * Opens the built-in settings dialog, which is populated from the Setting API.
  253. * @param options The options object. See Dialog.addClickHandler() for more information.
  254. * @param closeFn The function to execute whenever the dialog is closed.
  255. * @since 2.0.0
  256. */
  257. settings(options?: DialogOptions, closeFn?: () => void): void;
  258. /**
  259. * Opens the built-in share dialog, which is populated from the StoryShare passage.
  260. * @param options The options object. See Dialog.addClickHandler() for more information.
  261. * @param closeFn The function to execute whenever the dialog is closed.
  262. * @since 2.0.0
  263. */
  264. share(options?: DialogOptions, closeFn?: () => void): void;
  265. }
  266. export interface UIBarAPI {
  267. /**
  268. * Completely removes the UI bar and all of its associated styles and event handlers.
  269. * @since 2.17.0
  270. */
  271. destroy(): void;
  272. /**
  273. * Hides the UI bar. Returns a reference to the UIBar object for chaining.
  274. *
  275. * NOTE: This does not reclaim the space reserved for the UI bar. Thus, a call to UIBar.stow() may also be necessary.
  276. * Alternatively, if you simply want the UI bar gone completely and permanently, either using UIBar.destroy() or the
  277. * StoryInterface special passage may be a better choice.
  278. * @since 2.29.0
  279. */
  280. hide(): this;
  281. /**
  282. * Returns whether the UI bar is currently hidden.
  283. * @since 2.29.0
  284. */
  285. isHidden(): boolean;
  286. /**
  287. * Returns whether the UI bar is currently stowed.
  288. * @since 2.29.0
  289. */
  290. isStowed(): boolean;
  291. /**
  292. * Shows the UI bar. Returns a reference to the UIBar object for chaining.
  293. * @since 2.29.0
  294. */
  295. show(): this;
  296. /**
  297. * Stows the UI bar, so that it takes up less space.
  298. * @param noAnimation Whether to skip the default animation.
  299. * @since 2.17.0
  300. * @since 2.29.0: Added returned UIBar chaining reference.
  301. */
  302. stow(noAnimation?: boolean): this;
  303. /**
  304. * Unstows UI bar, so that it is fully accessible again.
  305. * @param noAnimation Whether to skip the default animation.
  306. * @since 2.17.0
  307. * @since 2.29.0: Added returned UIBar chaining reference.
  308. */
  309. unstow(noAnimation?: boolean): this;
  310. /**
  311. * Updates all sections of the UI bar that are populated by special passages — e.g., StoryBanner,
  312. * StoryCaption, StoryMenu, etc.
  313. * WARNING: As all special passage populated sections are updated it is recommended that
  314. * UIBar.update() be used sparingly. Ideally, if you need to update UI bar content outside of
  315. * the normal passage navigation update, then you should update only the specific areas you
  316. * need to rather than the entire UI bar.
  317. *
  318. * @since 2.29.0 Introduced
  319. */
  320. update(): void;
  321. }
  322. export {};