Show a Monarch screen. Note that the screen must be registered before it can be shown. The init()
function of the screen script (either screen_proxy.script
or screen_factory.script
) takes care of registration. This operation will be added to the queue if Monarch is busy.
PARAMETERS
screen_id
(string|hash) - Id of the screen to show.options
(table) - Options when showing the new screen (see below).data
(table) - Optional data to associate with the screen. Retrieve usingmonarch.data()
.callback
(function) - Optional function to call when the new screen is visible.
The options table can contain the following fields:
clear
(boolean) - If theclear
flag is set Monarch will search the stack for the screen that is to be shown. If the screen already exists in the stack and the clear flag is set Monarch will remove all screens between the current top and the screen in question.reload
(boolean) - If thereload
flag is set Monarch will reload the collection proxy if it's already loaded (this can happen if the previous screen was a popup).no_stack
(boolean) - If theno_stack
flag is set Monarch will load the screen without adding it to the screen stack.sequential
(boolean) - If thesequential
flag is set Monarch will start loading the screen only after the previous screen finished transitioning out.pop
(number) - Ifpop
is set to a number, Monarch will pop that number of screens from the stack before adding the new one.
Replace the top of the stack with a new screen. Equivalent to calling monarch.show()
with pop = 1
. It takes the same parameters as monarch.show()
.
Hide a screen that has been shown using the no_stack
option. If used on a screen that was shown without the no_stack
option it will only hide it if the screen is on top of the stack and the behavior will be exactly like if monarch.back()
had been called. This operation will be added to the queue if Monarch is busy.
PARAMETERS
screen_id
(string|hash) - Id of the screen to hide.callback
(function) - Optional function to call when the screen has been hidden.
RETURN
success
(boolean) - True if the process of hiding the screen was started successfully.
Clear the stack of screens completely. Any visible screen will be hidden by navigating back out from them. This operation will be added to the queue if Monarch is busy.
PARAMETERS
callback
(function) - Optional function to call when the stack has been cleared.
Go back to a previous Monarch screen. This operation will be added to the queue if Monarch is busy.
PARAMETERS
options
(table) - Options when showing the new screen (see below).data
(table) - Optional data to associate with the screen you are going back to. Retrieve usingmonarch.data()
.callback
(function) - Optional function to call when the previous screen is visible.
The options table can contain the following fields:
sequential
(boolean) - If thesequential
flag is set Monarch will start loading the screen only after the previous screen finished transitioning out.
Preload a Monarch screen. This will load but not enable the screen. This is useful for content heavy screens that you wish to be able to show without having to wait for it load. This operation will be added to the queue if Monarch is busy.
PARAMETERS
screen_id
(string|hash) - Id of the screen to preload.options
(table)callback
(function) - Optional function to call when the screen is preloaded.
The options table can contain the following fields:
keep_loaded
(boolean) - If thekeep_loaded
flag is set Monarch will keep the screen preloaded even after ahide()
orback()
navigation event that normally would unload the screen.
Check if a Monarch screen is preloading (via monarch.preload() or the Preload screen setting).
PARAMETERS
screen_id
(string|hash) - Id of the screen to check
RETURN
preloading
(boolean) - True if the screen is preloading.
Invoke a callback when a screen has been preloaded.
PARAMETERS
screen_id
(string|hash) - Id of the screen to checkcallback
(function) - Function to call when the screen has been preloaded.
Unload a preloaded Monarch screen. A preloaded screen will automatically get unloaded when hidden, but this function can be useful if a screen has been preloaded and it needs to be unloaded again without actually hiding it. This operation will be added to the queue if Monarch is busy.
PARAMETERS
screen_id
(string|hash) - Id of the screen to unload.callback
(function) - Optional function to call when the screen is unloaded.
Get the id of the screen at the top of the stack.
PARAMETERS
offset
(number) - Optional offset from the top of the stack, ie -1 to get the previous screen
RETURN
screen_id
(string|hash) - Id of the requested screen
Get the id of the screen at the bottom of the stack.
PARAMETERS
offset
(number) - Optional offset from the bottom of the stack
RETURN
screen_id
(string|hash) - Id of the requested screen
Get the data associated with a screen (from a call to monarch.show()
or monarch.back()
).
PARAMETERS
screen_id
(string|hash) - Id of the screen to get data for
RETURN
data
(table) - Data associated with the screen.
Check if a Monarch screen exists.
PARAMETERS
screen_id
(string|hash) - Id of the screen to get data for
RETURN
exists
(boolean) - True if the screen exists.
Check if Monarch is busy showing and/or hiding a screen.
RETURN
busy
(boolean) - True if busy hiding and/or showing a screen.
Check if a Monarch screen is at the top of the view stack.
PARAMETERS
screen_id
(string|hash) - Id of the screen to check
RETURN
exists
(boolean) - True if the screen is at the top of the stack.
Check if a Monarch screen is visible.
PARAMETERS
screen_id
(string|hash) - Id of the screen to check
RETURN
exists
(boolean) - True if the screen is visible.
Set the timestep to apply for a screen when below a popup.
PARAMETERS
screen_id
(string|hash) - Id of the screen to change timestep setting fortimestep
(number) - Timestep to apply
Add a URL that will be notified of navigation events.
PARAMETERS
url
(url) - URL to send navigation events to. Will use current URL if omitted.
Remove a previously added listener.
PARAMETERS
url
(url) - URL to remove. Will use current URL if omitted.
Post a message to a visible screen. The screen must have set a message listener using monarch.on_post()
.
PARAMETERS
screen_id
(string|hash) - Id of the screen to post message tomessage_id
(string|hash) - Id of the message to sendmessage
(table|nil) - Optional message data to send
RETURN
result
(boolean) - True if the message was senterror
(string|nil) - Error message if unable to send message
Set a function to be called when a screen should transition in our out. The function will receive (message_id, message, sender) with message_id
being one of the transition constants.
IMPORTANT! You must call monarch.on_message(message_id, message, sender)
from the same script as this function was called.
PARAMETERS
screen_id
(string|hash) - Id of the screenfn
(function) - The function to call when a transition should start
Set a function to be called when a screen gains or loses focus. The function will receive (message_id, message, sender) with message_id
being one of the focus change constants.
IMPORTANT! You must call monarch.on_message(message_id, message, sender)
from the same script as this function was called.
PARAMETERS
screen_id
(string|hash) - Id of the screenfn
(function) - The function to call screen focus changes
Set either a function to be called when msg.post()
is called on a specific screen or a URL where the message is sent.
IMPORTANT! If you provide a function you must also make sure to call monarch.on_message(message_id, message, sender)
from the same script as this function was called.
PARAMETERS
screen_id
(string|hash) - Id of the screenfn_or_url
(function) - The function to call or URL to send message to
Check if a screen has any missing resources. If the screen is loaded by a collection proxy with Load Dynamically this will use collectionproxy.missing_resources()
. For other cases this function will always return false.
RETURN
result
(boolean) - true if the screen has missing resources
Enable verbose logging of the internals of Monarch.
Message sent to listeners added using monarch.add_listener()
when a screen has started to transition in.
PARAMETERS
screen
(hash) - Id of the screenprevious_screen
(hash) - Id of the previous screen (if any)
Message sent to listeners added using monarch.add_listener()
when a screen has finished to transition in.
PARAMETERS
screen
(hash) - Id of the screenprevious_screen
(hash) - Id of the previous screen (if any)
Message sent to listeners added using monarch.add_listener()
when a screen has started to transition out.
PARAMETERS
screen
(hash) - Id of the screennext_screen
(hash) - Id of the next screen (if any)
Message sent to listeners added using monarch.add_listener()
when a screen has finished to transition out.
PARAMETERS
screen
(hash) - Id of the screennext_screen
(hash) - Id of the next screen (if any)