readium / readium-shared-js

Repository for the shared JavaScript libraries that are used in the SDK-Launchers and other applications developed on top of the SDK
BSD 3-Clause "New" or "Revised" License
78 stars 102 forks source link

Proposal for new event: CONTENT_DOCUMENT_READY #249

Open jccr opened 8 years ago

jccr commented 8 years ago

Use case: Adding highlights or accessing reader API functions only once per spine item, only when view instance is fully loaded and paginated.

This can be done with the current event model like this:

    reader.on(ReadiumSDK.Events.CONTENT_DOCUMENT_LOADED, function($iframe, spineItem) {

        reader.once(ReadiumSDK.Events.PAGINATION_CHANGED, function(pageChangeEventArgs) {
            if (pageChangeEventArgs.spineItem === spineItem) {
                // You can now add highlights safely for this spine item at this point
            }
        });
    });

It would be nice if this could be officially supported as an event with a name like: CONTENT_DOCUMENT_READY

or SPINE_ITEM_LOADED or PAGINATION_FINISHED, etc

danielweck commented 8 years ago

Good idea. Especially as reader.once() is so easy to mistake withreader.on(), and very convenient for accessing the spineItem reference directly too.

CONTENT_DOCUMENT_READY sounds good to me.

List of existing (related) events: https://github.com/readium/readium-shared-js/blob/develop/js/globals.js#L62

PAGINATION_CHANGED CONTENT_DOCUMENT_LOAD_START CONTENT_DOCUMENT_LOADED

rkwright commented 8 years ago

I am OK with merging it after we push 0.23