QX.js Scripting Guide

Working with Spreads

QXML for spread

Spread is represented by the <qx-spread> node. It contains the following attributes:

 

Attribute

Value

Description

spread-index

number

Index of the spread

Create new spread

To create a new spread:

  1. Get the DOM of the active layout.

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

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

  4. Append the <qx-spread> element as a child of the <qx-layout> node.

Sample JavaScript:

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

Delete existing spread

To delete existing spread:

  1. Get the DOM of the active layout.

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

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

Sample JavaScript:

var layout=app.activeLayoutDOM();
var spreads=layout.getElementsByTagName('qx-spread')[1];
layout.removeChild(spreads);