previewService

AngularJS Service for handling CMS builder preview mode.

When the game is loaded with ?preview=true inside an iframe, this service replaces the normal API data-loading flow with the following:

  1. Game sends CHILD_READY to the parent (tga-admin)
  2. Parent responds with GAME_DATA containing the full game object
  3. On each builder edit, parent re-sends GAME_DATA with updated data

Requires

Methods

(static) isPreview() → {boolean}

Whether the app is running in preview mode. True only when ?preview=true AND loaded inside an iframe.

Source:
Returns:
Type:
boolean

(static) sendReady()

Post CHILD_READY to the parent window so the CMS knows the iframe is ready to receive game data.

Source:

(static) listen(initialCallback, fallbackCallbackopt)

Listen for GAME_DATA messages from the parent window. The first message triggers the initial load callback. Subsequent messages broadcast 'preview:update' on $rootScope.

If no GAME_DATA arrives within READY_TIMEOUT_MS, the fallback callback is invoked so the game can fall back to normal API loading.

Source:
Parameters:
Name Type Attributes Description
initialCallback function

called once with the first GAME_DATA message

fallbackCallback function <optional>

called if no response within timeout

(static) sendState(state)

Post state back to the parent CMS so it can update its UI.

Source:
Parameters:
Name Type Description
state Object

arbitrary state object (e.g. { tossupPlaying: true })

(static) destroy()

Remove the message event listener.

Source: