Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Widow/Orphan Control with JavaScript?

It can be library-dependent or -agnostic. I just want to know if a script exists that will analyze the page (or maybe certain nodes that it has been given) and... "protect" against widows and orphans in the text.

What does "protect" mean? I don't know. I considered seeing if I could come up with one myself, but part of the problem is I'm not even sure how I would go about doing it.

Clarification: This would be for the screen version of the site, not print.

like image 337
sdleihssirhc Avatar asked Jan 20 '11 00:01

sdleihssirhc


People also ask

How do you add orphan control to a widow?

Control widow and orphan lines Select the paragraphs in which you want to control widow and orphan. On the Format menu, click Paragraph, and then click the Line and Page Breaks tab. Select the Widow/Orphan control check box.

What is widow orphan control?

Widow/Orphan control Widows and orphans are single lines of text in a paragraph that print at the top or bottom of a text box or column. To prevent widows and orphans by always having at least two lines of text at the top or bottom of a text box, select the Widow/Orphan control check box.

What are Javascript orphans?

The orphans property sets or returns the minimum number of lines for an element that must be visible at the bottom of a page (for printing or print preview). The orphans property only affects block-level elements.

Is widow orphan control on by default?

By default, widow and orphan control is already enabled when you first install and launch Contributor.


3 Answers

I recently ran into this problem in my angular app and used some regex I found on this post to add a non-breaking space before the last word:

String.replace(/\s([^\s<]+)\s*$/,\'&nbsp\;$1');

But angular was printing the non-breaking space as a string so I used unicode and it worked great:
String.replace(/\s([^\s<]+)\s*$/,'\u00A0$1');

like image 63
watersbythebay Avatar answered Nov 15 '22 06:11

watersbythebay


Adobe has stepped up and decided this is a serious issue on the web. They have put forward a proposal to help fix widows/orphans and other text balancing typography issues.

The repository for their jQuery plugin is here: https://github.com/adobe-webplatform/balance-text

The proposal to the w3c was here: http://adobe-webplatform.github.io/balance-text/proposal/index.html

It has since been adopted into the CSS Text Module Level 4 Editor's Draft.

like image 28
spex Avatar answered Nov 15 '22 06:11

spex


I believe you're describing typographic widows in an HTML document? Where a single word wraps around onto a new line in a header, for example?

The jQuery Widon't plugin goes through your HTML looking for this and puts a non-breaking space between the second-last and last words to ensure that at least two words wrap to a new line.

Hope this helps, Karl

like image 37
Karl Dawson Avatar answered Nov 15 '22 07:11

Karl Dawson