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274).
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--;
}
});
section
Thesectionobjectcanbeusedtoqueryandmodifyhowthesection(andtherelatedcontext)willbe
outputted.ItisoneofthemostimportantobjectsinControlScripts(see"ControlScripts"onpage398
and"ControlScriptAPI"onpage815).
Retrievingasection
Asectioncanberetrievedusingmerge.template.contexts.ContextType.sections["sec-
tion name"],forexample:merge.template.contexts.PRINT.sections["Section EN"].
Asectioncanalsoberetrievedviamerge.context.sections['section name'].Remember,
however,thatwhenseveralcontextsneedtobemerged(forexample,whenthePrintcontextis
attachedtoanemail),thescriptneedstocheckifthecurrentcontextisofthetypethatcontainsthe
desiredsection(forexample:if (merge.context.type == ContextType.PRINT) {}).When
Page 847