inspecting the hyphenated output?

27 views
Skip to first unread message

lovelost

unread,
Jun 8, 2012, 6:00:48 AM6/8/12
to Hyphenator.js
Once Hyphenator.js has done its job, can I inspect the hyphenated
output programmatically, say with jQuery? Say I want to use
Hyphenator to do the hyphenating, and then re-use that hyphenated text
elsewhere through code?

Mathias Nater

unread,
Jun 8, 2012, 7:04:32 AM6/8/12
to hyphen...@googlegroups.com
Hi

Thanks for your mail.

In it's simplest usecase Hyphenator.js replaces the text of hyphenated elements. Thus you can retrieve the hyphenated text from any hyphenated element after Hyphenator.js has run.

You may also hyphenate any string by using the public method described here: http://code.google.com/p/hyphenator/wiki/en_PublicAPI#mixed_Hyphenator.hyphenate(mixed_target,_string_lang)

I hope this helps. Otherways please let me know.

Regards,
Mathias

lovelost

unread,
Jun 8, 2012, 7:59:40 AM6/8/12
to Hyphenator.js
Hi Mathias. When I inspect the hyphenated div in jQuery, it does not
contain the hyphenated version. In my document.ready function I call
Hyphenator and (and it works in the browser), then immediately write
the div to the console log in Safari, but there is no recorded
hyphenation data, just the original div content. It is as though
Hyphenator was never called first. Does Hyphenator rewrite the DOM at
some specific point in "time" so I need to sequence my jQuery call at
some other point in time?


Thanks


On Jun 8, 12:04 pm, Mathias Nater <mathiasna...@gmail.com> wrote:
> Hi
>
> Thanks for your mail.
>
> In it's simplest usecase Hyphenator.js replaces the text of hyphenated elements. Thus you can retrieve the hyphenated text from any hyphenated element after Hyphenator.js has run.
>
> You may also hyphenate any string by using the public method described here:http://code.google.com/p/hyphenator/wiki/en_PublicAPI#mixed_Hyphenato...)

Mathias

unread,
Jun 12, 2012, 3:06:51 PM6/12/12
to hyphen...@googlegroups.com
You don't have to call Hyphenator.js in document.ready(). Hyphenator.js has it's own logic to know when the page has loaded (it's basically the same as jQuery uses). Calling Hyphenator.js in document.ready() may cause some issues (I'll have to test this).

Hyphenator.js takes some time to run (loading the patterns, unpack them and compute the hyphenation points) and does this asynchronously. So the elements are not yet updated if you access them after calling Hyphenator.run().
If you want to call a function after Hyphenator.js has finished you can define a callback (see: http://code.google.com/p/hyphenator/wiki/en_PublicAPI#property_onhyphenationdonecallback)

Just for interest: what are you planning to do?
Reply all
Reply to author
Forward
0 new messages