# Publication

## Commands

### `getDetails`

Retrieves details of the flipbook.

```javascript
instance.publication.getDetails((result) => {
    // YOUR CODE HERE
});
```

The command will return an object with the following properties:

| Property     | Type      | Description                      |
| ------------ | --------- | -------------------------------- |
| `name`       | `string`  | Name of the flipbook             |
| `seoTitle`   | `string`  | SEO title of the flipbook        |
| `paperId`    | `number`  | ID of the flipbook               |
| `isEmbedded` | `boolean` | Is the flipbook embedded/iframed |

## Events

### `onSpreadChange`

{% hint style="warning" %}
**Note:**

For new implementations, we reccommend you use the [`paging.onChange`](/flipbook-javascript-api/commands-and-events/paging.md#onchange) event instead of this event.
{% endhint %}

This subscription will trigger when the spread of the flipbook changes.

```javascript
instance.publication.onSpreadChange((result) => {
    // YOUR CODE HERE
});
```

The callback contains a value/result with the following properties:

| Property              | Type       | Description                                                                                                                                                                                                        |
| --------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `currentSpreadPages`  | `number[]` | Page numbers that are in the current spread.                                                                                                                                                                       |
| `currentVisiblePages` | `number[]` | Page number(s) that are currently in view. This array may contain one or two numbers, depending if the current view is page- (mobile/tablet in portrait) or spread-based (desktop, or mobile/tablet in landscape). |

### `onPageElementClick`

This subscription will trigger when a product/shop item action is clicked.

```javascript
instance.publication.onPageElementClick((result) => {
    // YOUR CODE HERE
});
```

{% hint style="info" %}
**Note:**

Current only shop items will fire this event. Click events on any other enrichments are not emitted.
{% endhint %}

The callback contains a value/result with the following properties:

<table><thead><tr><th width="283.3333333333333">Property</th><th width="175">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>type</code></td><td><code>string</code></td><td>The page element type that was clicked on</td></tr><tr><td><code>data</code></td><td><code>{}</code></td><td>Data associated with the page element</td></tr><tr><td><code>data.title</code></td><td><code>string</code></td><td>Shop item title</td></tr><tr><td><code>data.description</code></td><td><code>string</code></td><td>Shop item description</td></tr><tr><td><code>data.productId</code></td><td><code>string</code></td><td>Shop item product ID</td></tr><tr><td><code>data.price</code></td><td><code>number</code></td><td>Shop item price</td></tr><tr><td><code>data.amountSelection</code></td><td><code>boolean</code></td><td>If users are allowed to manually specify an amount before adding to basket</td></tr><tr><td><code>data.packageSize</code></td><td><code>number</code></td><td>Number of items per package</td></tr><tr><td><code>event</code></td><td><code>{}</code></td><td>Event data associated with the click event</td></tr><tr><td><code>event.originPage</code></td><td><code>number</code></td><td>Page number on which the page element is located on</td></tr><tr><td><code>event.originSpreadPages</code></td><td><code>number[]</code></td><td>Page numbers on which the spread where the page element is located on</td></tr><tr><td><code>event.coordinates.pageX</code></td><td><code>number</code></td><td>Absolute x coordinate of the click event</td></tr><tr><td><code>event.coordinates.pageY</code></td><td><code>number</code></td><td>Absolute y coordinate of the click event</td></tr><tr><td><code>event.coordinates.bookX</code></td><td><code>number</code></td><td>Ratio of the x coordinate relative to book width</td></tr><tr><td><code>event.coordinates.bookY</code></td><td><code>number</code></td><td>Ratio of the y coordinate relative to book height</td></tr></tbody></table>

### `onDownload`

This subscription will trigger when the download button in the topbar is clicked (if enabled in Flipbook settings).

```
instance.publication.onDownload(() => {
    // YOUR CODE HERE
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ipaper.io/flipbook-javascript-api/commands-and-events/publication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
