Options
All
  • Public
  • Public/Protected
  • All
Menu

ReaderViews are used for displaying publication documents.

To get a ReaderView up and running you need to:

  1. Add one or more renderers.
  2. Set which reader documents to display.
  3. Set the DOM Element where the ReaderView should render.
  4. Go to a location in the content.

How the ReaderView selects a renderer

A newly created ReaderView is initially in responsive mode. In responsive mode, the ReaderView selects a renderer based on the ResponsiveViewRule (if any was assigned to the renderer) and how much area of the viewport element it can use.

It is important to note that the ReaderView will not automatically refresh and re-render on viewport resize. Clients need to call refresh() on the ReaderView when the element passed to renderTo() is resized. This can for example be done by adding a 'resize' listener on window The ReaderView does not handle this automatically because in certain circumstances, 'resize' events should not trigger refresh(). For example, clicking a search input field on mobile will popup the soft keyboard and trigger a 'resize' event which should probably not make the ReaderView refresh().

example

Creating a ReaderView over the complete publication let readerView = readingSystemEngine.createView(); readerView.addRenderer(new StackRenderer()); readerView.setReaderDocuments(readerPublication.getSpine()); readerView.renderTo(someElement) readerView.goToStart();

Hierarchy

Index

Methods

addEngineEventListener

addRenderer

  • Adds a renderer to this ReaderView and optionally a ResponsiveViewRule.

    When responsive renderer selections is enabled, the ResponsiveViewRule associated with the renderer is used to evaluate if the renderer can be used or not. The rule can be defined as a CSS media query or a custom callback. The rule is evaluated each time refresh(), or renderTo() is called, but may also be evaluated on other occasions. Omitting the rule will still allow the renderer to be picked, but the ReaderView will prioritize renderers where the rule has explicitly been set.

    If multiple renderers are added and more than one rule evaluates to true, the renderer that can use as much as possible of the area of the element set by ReaderView.renderTo() is chosen. If there are several renderers that can use an equal amount of the rendering area, the first one added will be chosen.

    example

    readerView.addRenderer(new StackRenderer()) readerView.addRenderer(new FlipBookRenderer(), '(orientation: landscape) and (min-width: 500px)')

    Parameters

    • renderer: IRenderer

      The renderer to add to this ReaderView.

    • Optional rule: string | IResponsiveViewRule | (() => boolean)

      An IResponsiveViewRule instance, a media query string, or a callback. Omitting the rule is the same as passing: new ResponsiveViewRule(() => true)

    Returns void

canPerformGoTo

  • canPerformGoTo(): boolean
  • Check if it is possible to call goTo() or goToStart() at this moment.

    You can typically always perform a goTo() or goToStart() given that there is an activeRenderer and setReaderDocuments() has been called with a non-empty list.

    Listen on "canPerformGoToChanged" to detect when this value changes.

    Returns boolean

canPerformNext

  • canPerformNext(): boolean
  • Check if it is possible to call next() at this moment.

    This will return false if isAtEnd() return true or if a next(), previous(), goTo() or goToStart() is currently being performed.

    Listen on "canPerformNextChanged" to detect when this value changes.

    Returns boolean

canPerformPrevious

  • canPerformPrevious(): boolean
  • Check if it is possible to call previous() at this moment.

    This will return false if at last page or if a next(), previous(), goTo() or goToStart() is currently being performed.

    Listen on "canPerformPreviousChanged" to detect when this value changes.

    Returns boolean

clearContentSelection

  • clearContentSelection(): void
  • Clears any selection made in content documents.

    Returns void

createAnnotationLayer

  • Create a new ReaderViewAnnotationLayer and adds it to this ReaderView.

    Type parameters

    • T = any

    Parameters

    • name: string

      A name identifying this annotation layer

    Returns IReaderViewAnnotationLayer<T>

destroyAnnotationLayer

  • Removes and destroys an annotation layer. Throws an error if the layer was not created with this ReaderView instance. Does nothing if the layer is already destroyed.

    Parameters

    Returns void

fetchRectsForVisibleContent

  • Fetch rectangles and content locations for line boxes and replaced elements such as <img> elements from the specified visible page. If a contentLocation is specified, it will be used to filter the result.

    The rectangle coordinates are in application viewport coordinate space. This means that any subsequent transform applied to the ReaderView, such as the user pinch-zooming, will make those rectangles out of date.

    The rects are ordered in document order.

    If the passed visiblePage is not currently part of the array returned by getVisiblePages(), the returned Promise is rejected with an error object with the error type set to VISIBLE_PAGE_OUTDATED.

    If the passed visiblePage is destroyed before the result could be calculated, the returned Promise is rejected with an error object with the error type set to ABORTED.

    If the passed contentLocation is not intersecting with the visiblePage, the returned Promise is rejected with an error object with the error type set to CONTENT_LOCATION_OUTSIDE_VISIBLE_PAGE.

    Parameters

    Returns Promise<IVisibleContentRectsResult>

focusOnReadingPosition

  • Focus on the page and/or element best matching the reading position.

    By focusing on publication content, your app give accessibility technologies such as screen readers an intent where to start reading. Depending on what browser, platform and accessibility technology you are targeting, you might need to experiment with the options you pass to this method in order to get the desired behavior.

    The focus action will be applied after any ongoing navigation has completed and visible content has finished rendering. Thus, this method is safe to call immediately after a call to any navigation method such as goTo(), next() or previous().

    NOTE: Calling focusOnReadingPosition() MAY remove user selection in some browsers. At the time of writing (2023-06-29), this has only been observed in Firefox on Windows.

    Parameters

    Returns Promise<void>

    A Promise that is resolved when the focus() action has been applied, rejected if the focus could not be applied due to an error.

getActiveGestureType

  • Get the current active gesture type being performed by the user if any.

    Listen on "activeGestureTypeChanged" to detect when this value changes.

    Returns ReaderViewGestureType

getActiveNavigationAction

  • Get the current ongoing navigation action if any.

    Listen on "navigationStarted" and "navigationEnded" to detect when this value changes.

    Returns NavigationAction

getActiveRenderer

  • Get the current active Renderer. Note that calling this method immediately after setting up the ReaderView will in most cases return null if the ReaderView.isResponsiveRendererSelectionEnabled() returns true, as it performs several async operations before selecting an active renderer.

    You can also detect when the active renderer changes by adding an 'activeRendererChanged' event listener.

    Returns IRenderer

getAllowedGestureTypes

getAnnotationLayerByName

getAnnotationLayers

getElement

  • getElement(): HTMLElement
  • Get the Element this ReaderView is rendering to.

    Returns HTMLElement

getEngineEventListeners

getName

  • getName(): string
  • Get the name of this ReaderView.

    Returns string

getOptions

getPageProgressionDirection

  • Get the page progression direction used by this ReaderView. Will return the actual runtime value after setReaderDocuments() has been called.

    Returns ReaderViewPageProgressionDirection

getPageProgressionTimeline

  • Get the page progression timeline of this ReaderView if available. Listen on the "pageProgressionTimelineRecalculated" EngineEvent to detect when a new instance is available.

    Returns IPageProgressionTimeline

getReaderDocuments

  • Get the reader documents used by this ReaderView, previously set with setReaderDocuments().

    Returns IReaderDocument[]

getReaderDocumentsLoadedForRendering

  • Get the reader documents currently loaded for rendering visible content and offscreen content.

    Returns IReaderDocument[]

getReaderPublications

  • Get the reader publications used by this ReaderView. Calculated from the reader documents previously set with setReaderDocuments().

    Returns IReaderPublication[]

getReadingPosition

  • Get the current reading position, or null if this ReaderView is not rendering any publication content.

    Returns IContentLocation

getReadingSystemEngine

  • Get the ReadingSystemEngine instance that was used to create this ReaderView.

    Returns IReadingSystemEngine

getRendererByName

  • Get a renderer by name that was previously added with addRenderer().

    Parameters

    • name: string

    Returns IRenderer

getRenderers

  • Get all renderers that have been added with addRenderer().

    Returns IRenderer[]

getScrollState

  • Get information about the active renderer's current scroll state, if the renderer is a scrolling renderer. Note that the scrollTop value is not up-to-date while scrolling is true.

    Returns IReaderViewScrollStateData

getSyncMediaPlayer

  • Get the sync media player that has been attached to this ReaderView using setSyncMediaPlayer().

    Returns ISyncMediaPlayer

getTransformManager

  • Returns the ReaderViewTransformManager used for applying transformations such as scaling and translations.

    Returns IReaderViewTransformManager

getVisiblePages

  • Get a list of the current visible pages.

    The number of visible pages depend on the renderer used.

    For example: If the active renderer is rendering single pages, one IVisiblePage will be returned. If the active renderer is rendering spreads, up to two IVisiblePages will be returned.

    Returns IVisiblePage[]

getVisibleRange

  • Get a ResolvedContentLocation describing the range of the visible content.

    Returns IContentLocation

getVisibleReaderDocuments

  • Get the reader documents currently visible in the ReaderView.

    Returns IReaderDocument[]

goTo

  • Go to a specific location in a reader document that has been added to this ReaderView.

    The location can be specified as:

    • An IContentLocation or IUnresolvedContentLocation object retrieved from a ReaderPublication, EngineEvent, etc.
    • A Locator object or a serialized Locator (see the type ILocatorData for alternatives)
    • A relative or absolute URL to the location in the publication content. These URLs can for example be retreived using Locator.toString(). You can also specify a selector string compatible with the publication format, like '#page=3' to go to Page 3 in a PDF publication.

    See IReaderViewGotoOptions for additional options to use with goTo().

    Parameters

    Returns Promise<void>

    A Promise that is resolved when the active renderer has navigated to the new location. Rejected if the locator was invalid, or the locator could not be resolved to a readerDocument in this ReaderView. Rejected with errorType ABORTED if goTo() or goToStart() is called again before this call to goTo() had completed successfully.

goToStart

  • goToStart(): Promise<void>
  • Go to the start of the first ReaderDocument in this ReaderView.

    Returns Promise<void>

    A Promise that is resolved when the active renderer has navigated to the new location. Rejected with errorType ABORTED if goTo() or goToStart() is called again before this call to goTo() had completed successfully.

hasActiveTransform

  • hasActiveTransform(): boolean
  • If there is an active transform applied on the ReaderView. Use getTransformManager() to get/set the active transform.

    Returns boolean

isAtEnd

  • isAtEnd(): boolean
  • Check if this ReaderView is currently showing the last content in the last reader document added to the ReaderView. Call this method after receiving the 'visiblePagesChanged' event to detect when this value is changed.

    Returns boolean

isAtStart

  • isAtStart(): boolean
  • Check if this ReaderView is currently showing the first content in the first reader document added to the ReaderView. Call this method after receiving the 'visiblePagesChanged' event to detect when this value is changed.

    Returns boolean

isContentSelectionEnabled

  • isContentSelectionEnabled(): boolean
  • If the user is able to select content in content documents.

    Returns boolean

isDestroyed

  • isDestroyed(): boolean
  • Check if this ReaderView has been destroyed.

    Returns boolean

isNavigating

  • isNavigating(): boolean
  • Returns true if any navigation action such as next/previous/goTo is currently being processed.

    Returns boolean

isOffscreenContentRendering

  • isOffscreenContentRendering(): boolean
  • If offscreen content is currently rendering.

    Returns boolean

isResponsiveRendererSelectionEnabled

  • isResponsiveRendererSelectionEnabled(): boolean
  • If the ReaderView will choose the activeRenderer based on the ResponsiveViewRules associated with each added renderer. See addRenderer() for more details.

    Returns boolean

isScriptedContentDocumentEventHandlersEnabled

  • isScriptedContentDocumentEventHandlersEnabled(): boolean
  • If the scripted content document event handlers are allowed to receive events. Note that regardless if true or false is returned, you will still receive EngineEvents.

    Returns boolean

isScrolling

  • isScrolling(): boolean
  • If active renderer is currently scrolling. This method always return false for paginated renderers.

    Returns boolean

isVisibleContentRendering

  • isVisibleContentRendering(): boolean
  • If visible content is currently rendering.

    Returns boolean

next

  • next(): Promise<void>
  • Tell the activeRenderer to navigate to and display next content fragment (i.e. page, spread, or content-document, depending on the renderer implementation). The navigation will be ignored if there is an ongoing navigation started with next(), previous(), goTo() or goToStart().

    Scrolling renderers will always navigate to the next content-document when this method is called. See scrollBy() for programmatically scrolling the renderer.

    Returns Promise<void>

    Returns a Promise that is resolved when the navigation has completed successfully. Rejected if the navigation is canceled because another action forced a view change before the navigation completed. Rejected if the navigation cannot be done at all, for example if the ReaderView.isAtEnd() returns true or another navigation is being performed.

previous

  • previous(): Promise<void>
  • Tell the activeRenderer to navigate to and display previous content fragment (i.e. page, spread, or content-document, depending on the renderer implementation). The navigation will be ignored if there is an ongoing navigation started with next(), previous(), goTo() or goToStart().

    Scrolling renderers will always navigate to the previous content-document when this method is called. See scrollBy() for programmatically scrolling the renderer.

    Returns Promise<void>

    Returns a Promise that is resolved when the navigation has completed successfully. Rejected if the navigation is canceled because another action forced a view change before the navigation completed. Rejected if the navigation cannot be done at all, for example if the ReaderView.isAtStart() returns true or another navigation is being performed.

refresh

  • refresh(force?: boolean): void
  • Re-render contents if view element dimensions have changed. If the "force" parameter is set to true, the content is re-rendered regardless if the view element dimensions changed.

    If responsive renderer selection is enabled, this method may switch active renderer.

    The current reading position, if any, is kept. This method should be called when the view element has been resized in order for the renderer to use the new dimensions.

    Note that calls to refresh() are quite expensive. Therefore, there is a built-in delay such that multiple calls to refresh() within a short time-span will internally be merged into a single refresh() call. You can configure the length of this delay using the refreshDelayMs option.

    This method does nothing if there is no renderer assigned to this ReaderView, renderTo() has not been called yet, or if the list of reader documents is empty.

    Parameters

    • Optional force: boolean

      If true, re-render contents regardless if the view element dimensions changed. Defaults to false.

    Returns void

removeEngineEventListener

removeRenderer

  • Remove a renderer previously added with addRenderer().

    Parameters

    Returns void

renderTo

  • renderTo(viewElement: HTMLElement): void
  • Render to the specified viewElement. The viewElement MUST be added to the DOM and have a width and height. The ReaderView will use the dimensions of the viewElement and will not expand the viewElement.

    If the passed element has the position style set to "static", it will be changed to "relative" to ensure that is is an "offsetParent"

    throws

    EngineError with errorType set to INVALID_VIEW_OPERATION if the viewElement has no dimensions or is a non-displayed element.

    Parameters

    • viewElement: HTMLElement

    Returns void

scrollBy

  • Scrolls a scrolling renderer's content by the specified amount. Relative values such as PERCENTAGE will be based on the renderer element's clientHeight.

    If the active renderer is not a scrolling renderer, this method does nothing.

    Returns true if the renderer started scrolling, false otherwise.

    Parameters

    Returns boolean

setActiveRenderer

  • Sets the active renderer. The renderer must have previously been added with addRenderer(). This will set responsiveRendererSelectionEnabled to false meaning that calls to refresh() will no longer change the active renderer.

    Call setResponsiveRendererSelectionEnabled(true) to allow refresh() to switch active renderer again.

    Parameters

    • renderer: IRenderer

      The renderer to use as active renderer. Passing null will force no renderer to be used.

    Returns void

setAllowedGestureTypes

  • Sets which gesture types the user is allowed to perform on the ReaderView.

    Parameters

    Returns void

setContentOnActiveRendererMissing

  • Set custom content to show when no active renderer could be found.

    Parameters

    • customViewContent: string | ICustomReaderViewContent

      An implementation of ICustomReaderViewContent or a HTML string. If null is passed, no content will be shown.

    Returns void

setContentOnEmptyPage

  • Set custom content to use for empty pages. This can typically happen in spread renderers when pages have a preferred PageSpreadSlot.

    Parameters

    • customViewContent: string | ICustomReaderViewContent

      An implementation of ICustomReaderViewContent or a HTML string. If null is passed, a blank page is shown.

    Returns void

setContentOnLicenseGracePeriodExpired

  • Set custom content to use when no license has been validated on the device for the duration of the grace period (defaults to 30 days). See Engine Event 'licenseReadingSessionBlocked' for more information.

    The default content is "Reading session expired. Please check your internet connection."

    Parameters

    • customViewContent: string | ICustomReaderViewContent

      An implementation of ICustomViewContent or a HTML string. If null is passed, a blank page is shown.

    Returns void

setContentOnLoadError

  • Set custom content to show for pages that could not be loaded due to an error.

    It is recommended to show a "retry" button in this custom page content which is bound to ReaderView.refresh(true)

    Parameters

    • customViewContent: string | ICustomReaderViewContent

      An implementation of ICustomReaderViewContent or a HTML string. If null is passed, a blank page is shown.

    Returns void

setContentOnLoading

  • Set custom content to show when loading publication content. Use this method to change the default loading animation.

    Parameters

    • customViewContent: string | ICustomReaderViewContent

      An implementation of ICustomReaderViewContent or a HTML string. If null is passed, the default Colibrio loader animation is used.

    Returns void

setContentSelectionEnabled

  • setContentSelectionEnabled(enabled: boolean): void
  • Sets if the user should be able to select content in content documents.

    Parameters

    • enabled: boolean

    Returns void

setOptions

  • Set new ReaderView options. Existing properties are preserved if they are not present in the passed options object. Properties explicitly set to the value undefined will be restored to their default values.

    Parameters

    Returns void

setReaderDocuments

  • Set which ReaderDocuments this ReaderView should render.

    The passed list of ReaderDocuments is validated according to the following rules:

    • All ReaderDocuments must belong to one publication.
    • All ReaderDocuments must be ordered as in the publication spine.

    If the passed list of readerDocuments fails validation, this method will throw an EngineError.

    ReaderDocuments where ReaderDocument.isRenderable() returns false (eg. Audiobook documents) will be filtered out and will not added to the ReaderView. If this happens, an error will be logged.

    Some examples:

    const spine = readerPublication.getSpine();
    readerView.setReaderDocuments(spine); // OK!
    readerView.setReaderDocuments(spine.slice(1, 4)) // OK!
    readerView.setReaderDocuments(spine.filter(item => item.isReflowable()); // OK!
    readerView.setReaderDocuments(spine.reverse()); // ERROR, items are not ordered correctly!

    You need to call goTo() or goToStart() after calling this method to start rendering the new content. There is one exception where you don't need to call goTo() or goToStart() and that is when using this method to add additional ReaderDocuments from the same publication:

    readerView.setReaderDocuments(spine.slice(0, 4)): // Initially, only render first 4 documents.
    readerView.goToStart(); // We need goTo() or goToStart() so ReaderView knows what to render initially.
    ...

    // Later:
    readerView.setReaderDocuments(spine.slice(0, 6)); // Add 2 more ReaderDocuments,
    // No need to call goTo() or goToStart()

    Parameters

    • readerDocuments: IReaderDocument[]

      A list of reader documents in reading order that should be rendered by this ReaderView.

    Returns void

setResponsiveRendererSelectionEnabled

  • setResponsiveRendererSelectionEnabled(enabled: boolean): void
  • Sets if the ReaderView will choose the activeRenderer based on the ResponsiveViewRules associated with each added renderer. See addRenderer() for more details.

    When this mode is enabled, active renderer may change when calling refresh() or renderTo().

    When setting this to enabled, the active renderer will change immediately and re-render contents.

    Parameters

    • enabled: boolean

    Returns void

setScriptedContentDocumentEventHandlersEnabled

  • setScriptedContentDocumentEventHandlersEnabled(enabled: boolean): void
  • Sets if the scripted content document event handlers are allowed to receive events. This is the only way to prevent scripted content document from receiving user generated events. Note that regardless if this is set to true or false, you will still receive EngineEvents.

    Parameters

    • enabled: boolean

    Returns void

setSyncMediaPlayer

  • Attach a SyncMediaPlayer to the ReaderView. This allows the SyncMediaPlayer and ReaderView to synchronize. See SyncMediaPlayer for more details.

    If another SyncMediaPlayer is attached to this ReaderView, it will be detached.

    Parameters

    • syncMediaPlayer: ISyncMediaPlayer

      The SyncMediaPlayer to attach, or null to detach any already attached SyncMediaPlayer.

    Returns void

toJSON

Generated using TypeDoc