Event listeners

更新时间:
复制 MD 格式

Event listeners allow a component to perform specific operations when events occur.

Important

This document is no longer maintained. Use the new version of Intelligent Media Management.

Implementation

You can use the on method of an instance to listen for events.

demo.on('event-name', function(data) {
    // do something...
})

Event list

The following table describes the parameters.

Event name

Description

Minimum supported version

fileOpen

Document open. A callback for when a document is opened or fails to open.

1.0.0

error

Error event. A callback for when an error occurs.

1.1.2

tabSwitch

PC header tab switch. A callback for when a tab is switched.

1.1.2

fileStatus

File save status. A callback for when a file is saved.

1.1.5

previewLimit

Preview page limit event. A callback for when a user scrolls to the bottom of the limited page range.

This event is valid only in preview page limit mode and supports only WORD, PDF, and PDF components.

1.1.5

hasDocMap

Document has a table of contents. A callback for when a document has a table of contents.

This event supports only the text component.

The table of contents for a text document is loaded dynamically in shards. Therefore, an event listener is required to determine if a table of contents exists.

1.1.5

fullscreenchange

Enter or exit full screen event. A callback for when a user enters or exits full screen mode.

1.1.5

Examples

  • File open

    • Example

      demo.on('fileOpen', function(data) {
          // do something...
      })
    • If the event is successful, the following result is returned:

      {
          "success": true,
          "time": 111, // Open duration.
          "fileInfo": {
            name: "Seating Chart",
            officeType: "w",
            id: "64784347535"
          }
      }
    • If the event fails, the following result is returned:

      {
          "success": true,
          "time": 111,
          "reason": "InvalidLink", // An error code is returned on failure.
      }
  • Error event

    • Example

      demo.on('error', function(data) {
          // do something...
      })
    • Returned result

      ```javascript
      {
          "reason": "InvalidLink", // An error code is returned on failure.
      }

      For more information about error codes, see Error codes.

  • Header tab switch

    • Example

      demo.on('tabSwitch', function(data) {
          // do something...
      })
    • Returned result

      {
        tabKey: 1 // The ordinal number of the current tab.
      }
  • File save status

    • Example

      demo.on('fileStatus', function() {
          // do something...
      })
    • Returned result

      {
        status: 0, // No document updates.
        status: 1, // Version saved. Triggered by manual save, scheduled save, or closing the page.
        status: 2, // Cannot save empty file. Triggered if file is empty after kernel save.
        status: 3, // Storage space is full.
        status: 4, // Saving in progress. Avoid frequent operations. Triggered when server-side save queue is full.
        status: 5, // Save failed.
        status: 6, // Saving file update. Triggered by save after content modification.
        status: 7, // Saved successfully. Triggered when modified content is saved.
      }
  • Preview page limit

    • Example

      demo.on('previewLimit', function(result) {
          // do something...
      })
    • Returned result

      Note

      Because text documents use a stream layout, the exact number of actual pages cannot be determined. Therefore, the returned result contains only the total parameter.

      // Text document.
      {
          total: 4 // The number of limited pages.
      }
      // PDF and presentation documents.
      {
          total: 4, // The number of limited pages.
          realTotal: 10 // The total number of real pages.
      }
  • Does the document include a table of contents?

    Example:

    demo.on('hasDocMap', function() {
        // If the document has a table of contents, the callback is executed.
    }) 
  • Enter or exit full screen mode

    • Example

      demo.on('fullscreenchange', , function(result) {
          // do something...
      })
    • Returned result

      {
        status: 0, // Triggered when exiting full screen mode.
        status: 1, // Triggered when entering full screen mode.
      }

Error codes

Error code

Description

Unknown

Unknown error.

userNotLogin

The user is not logged on.

InvalidLink

Broken hyperlink.

SessionFull

The maximum number of collaboration members is reached.

Fail

Failed to open.

PermissionDenied

Insufficient permissions for this operation.

GetTokenFailed

Failed to get the token.

SessionExpired

The session has expired.

fileTooLarge

The file is too large. The preview service is not supported.

GetFileInfoFailed

Failed to get file information.