QX.js Scripting Guide

Working with Paragraphs

QXML for paragraph

Paragraph is represented by <qx-p> node. It contains following attributes:

 

Attribute

Value

Description

class

text

Name of paragraph style sheet and space separated H&J Style, Bullet and Numbering Style, Para Shading Style, Hanging Character Set

Create new paragraph

To create a new paragraph:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-box>, <qx-p> and <qx-span> tags.

  3. Create a new <qx-p> element.

  4. Create a new <qx-span> element.

  5. Append the <qx-span> element as child of <qx-p> element.

  6. Append the <qx-p> element as child of <qx-story> node.

Sample JavaScript:

var layout=app.activeLayoutDOM();
var boxes=layout.getElementsByTagName('qx-box')[0];
var paras=boxes.getElementsByTagName('qx-p')[0];
var span=paras.getElementsByTagName('qx-span')[0];
var newPara=document.createElement('qx-p');
var newSpan=document.createElement('qx-span');
newSpan.innerText='NEW';
newPara.appendChild(newSpan);
paras.parentNode.appendChild(newPara);

Delete existing paragraph

To delete an existing paragraph:

  1. Get the DOM of the active layout.

  2. Get the <qx-box>, <qx-story> and <qx-p> node corresponding to the paragraph to be deleted.

  3. Remove the desired <qx-p> child node from <qx-story> node.

Sample JavaScript:

var layout=app.activeLayoutDOM();
var boxes=layout.getElementsByTagName('qx-box')[0];
var story=boxes.getElementsByTagName('qx-story')[0];
var paras=story.getElementsByTagName('qx-p')[0];
story.removeChild(paras);

Apply margin

Margin top

To apply margin top:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxMarginTop styling property to '0.069in'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[1];
    para.style.qxMarginTop='0.069in';

Margin bottom

To apply margin bottom:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxMarginBottom styling property to '0.042in'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxMarginBottom='0.042in';

Margin left

To apply margin left:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxMarginLeft styling property to '0.111in'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxMarginLeft='0.111in';

Margin right

To apply margin right:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxMarginRight styling property to '0.222in'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxMarginRight='0.222in';

Apply text indent

To apply text indent:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxTextIndent styling property to '0.208in'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxTextIndent='0.208in';

Apply line height

To apply line height:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxLineHeight styling property to '17.4pt'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxLineHeight='17.4pt';

Apply text align

To apply text align:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxTextAlign styling property to 'justify'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxTextAlign='justify';

Apply initial letter and initial letter count

To apply initial letter and initial letter count:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxInitialLetterCount styling property to '2'.

  4. Set the qxInitialLetter styling property to '4'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxInitialLetterCount='2';
    para.style.qxInitialLetter='4';

Apply orphans and widows

Orphans

To apply orphans:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxOrphans styling property to '2'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxOrphans='2';

Widows

To apply widows:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxWidows styling property to '3'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxWidows='3';

Break inside

To apply break inside:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxBreakInside styling property to 'auto'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxBreakInside='auto';

Break after

To apply break after:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxBreakAfter styling property to 'avoid'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxBreakAfter='avoid';

Apply grid properties

Lock text to grid

To apply lock text to grid:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxLockTextToGrid styling property to 'textbox'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxLockTextToGrid='textbox';

Text grid alignment

To apply text grid alignment:

  1. Get the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxTextGridAlignment styling property to 'topline'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxTextGridAlignment='topline';

Specify minimum distance between bullet and text

To specify the minimum distance between a bullet and text:

  1. et the DOM of the active layout.

  2. Get the <qx-p> node inside the <qx-box> node .

  3. Set the qxBnMinGap styling property to '0.2in'.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box')[0];
    var para=boxes.getElementsByTagName('qx-p')[0];
    para.style.qxBnMinGap='0.2in';