2022.2

Table Of Contents
Tip: Youdon'tneedascripttoresizetextinordertomakeitfitinabox.TheCopyFitfeatureauto-
maticallyscalestexttotheavailablespace(see"CopyFit"onpage685).
Examples
var $box = query("#mybox");
while ( ! $box.overflows()) {
//do something
}
Aslightlyshorterversion:
while ( ! query("#mybox").overflows()) {
//do something
}
Thefollowingscriptselectsthreeboxesthatallhavetheclassbox(selector:.box).Itloopsoverthem,
insertingasmanyproductsfromanarrayaspossibleintothebox.Infact,itinsertsonetoomanyand
removesthelastonebeforemovingontothenextbox.
var products = ["Appetizer","Beans","Beef","Lettuce","Sprouts","Coconut","Juice","Soup","Coriander","Cheese","Pasta","Sugar","Vinegar","Bread"];
var i = 0;
results.each( function() {
// Add elements to the box until it overflows.
while ( ! this.overflows() && i < products.length ) {
this.append("<p>" + products[i] + "</p>");
i++;
}
// Go one step back unless we processed all items in our array.
if( i < products.length ) {
query("p:last-child", this).remove();
i--;
}
});
pageref()
Returnsamarkerthatwillbereplacedwiththeelement'spagenumberafterpagination.Thisonly
worksforelementsinthesectionthatiscurrentlybeingmerged.
Example
Creating a table of contents
Thefollowingscriptcreatesatableofcontentsforalllevel1headings(<h1>elements)withtheclass
titleinonesection.
var toc = '<ul ID="toc">';
query('h1.title').each(function()
{toc += '<li>' + this.text() + ' <span class="li_toc">' + this.pageref() + '</span></li>';
});
toc += '</ul>';
results.after(toc);
Page 1260