QX.js Scripting Guide

Working with Pages

QXML for page

  Page is represented by the <qx-page> node. It contains the following attributes:

 

Attribute

Value

Description

page-index

number

Index of the page

page-position

left | right

Specifies whether a page should be on the left or right of the spine

left

Specifies that page is on left side of the spine

right

Specifies that page is on right side of the spine

applied-master-page

text

Identifies the master-page that is applied to a page

Create a new page

To create a new page:

  1. Get the DOM of the active layout.

  2. Create a new <qx-page> element.

  3. Set the page-index attribute in the <qx-page> element.

  4. Set the page-position attribute in the <qx-page> element.

  5. Set the applied-master-page attribute in the <qx-page> element.

  6. Append the <qx-page> element as a child of the <qx-spread> node.

Sample JavaScript:

var layout = app.activeLayoutDOM();
var spread= layout.getElementsByTagName('qx-spread')[0];
var page = document.createElement('qx-page');
page.setAttribute('page-index','2');
page.setAttribute('page-position','right');
page.setAttribute('applied-master-page','A-Master A');
spread.appendChild(page);

Delete existing page

To delete an existing page:

  1. Get the DOM of the active layout.

  2. Get the <qx-page> node corresponding to the page to be deleted.

  3. Remove the <qx-page> child node from the <qx-spread> node.

Sample JavaScript:

var layout = app.activeLayoutDOM();
var spread= layout.getElementsByTagName('qx-spread')[0];
var page = layout.querySelector("qx-page[page-index='2']");
spread.removeChild(page);