# mergeAndPack

This page helps you configure, merge and pack Hyphenator.js, Hyphenator_Loader.js and the pattern files. The information that accompanies each setting should be clear enough. If you need more information you will find some in the wiki on https://github.com/mnater/Hyphenator.js/blob/wiki/en_PublicAPI.md.

Since this page uses XMLHttpRequests to load the script and pattern files, it will not work if you call it with the file:// protocol. Instead put it on your server or go to http://code.google.com/p/hyphenator/.

The script loads the versions of Hyphenator.js (and Hyphenator_Loader.js and the patterns) that resides in the same directory like this page.

Hyphenator_Loader.js

Hyphenator_Loader.js is a small script that tests if the client supports css3 hyphenation for the given languages. If at least one language isn't supported by the client it loads Hyphenator.js.
If you check this box the language selection below will be hidden and two scripts will be outputted at the end of the page.

Use Hyphenator_Loader.js

Hyphenator_Loader.js needs some information:

Test language(s):

Create an object where the keys are the language codes and the values are a long word in that language (at least 12 characters long). If the website is written in one language only one key/value pair is needed (the example shows the entries for a dual language site: english and armenian).
{ "en": "hyphenationalgorithm", "hy": "Հայերենն" }

Path to Hyphenator.js:

Specify the path to Hyphenator.js. This can be absolute or relative. The example implies that Hyphenator.js is in the same directory like Hyphenator_Loader.js
Use the minified version of Hyphenator.js (without any patterns included) that you get at the end of this page.

The settings for Hyphenator.js can be made below. They will be passed by Hyphenator_Loader.js to Hyphenator.js

Languages

Select the language you use on your website. The patterns of the selected languages will be included in the ouputted script for faster page loading. If you select no language, make sure that "enable remote loading" is on (see below)!

- Беларуская (Belarusian)
- বাংলা (Bengali)
- Català (Catalan)
- Česky (Czech)
- Dansk (Danish)
- Deutsch (German)
- Ελληνική monotone (monotone greek)
- Ελληνική polytone (polytone greek)
- British English (British English)
- American English (American English)
- Esperanto (Esperanto)
- Español (Spanish)
- Eesti (Estonian)
- Suomi (Finnish)
- Français (French)
- Ελληνική ancient (ancient greek)
- ગુજરાતી (Gujarati)
- हिंदी (Hindi)
- Magyar (Hungarian)
- Հայերեն լեզու (Armenian)
- Italiano (Italian)

- ಕನ್ನಡ (Kannada)
- Latina (Latin)
- Lietuvių (Lithuanian)
- latviešu valoda (Latvian)
- മലയാളം (Malayalam)
- Nederlands (Dutch)
- Norsk (Norwegian)
- ଓଡ଼ିଆ (Oriya)
- ਪੰਜਾਬੀ (Punjabi)
- Polski (Polish)
- Português (Portuguese)
- Română (Romanian)
- Pyccĸий (Russian)
- Slovenčina (Slovak)
- Slovenščina (Slovenian)
- Српски (Serbian, Cyrillic script)
- Srpski (Serbian, Latin script)
- Svenska (Swedish)
- தமிழ் (Tamil)
- తెలుగు (Telugu)
- Türkçe (Turkish)
- Українська (Ukrainian)

- Select all

Configuration

Make the settings for Hyphenator. Leave empty textfields empty for the default value to be set. If no special configuration is made, there will be no Hyphenator.config(); function in the output.

Don't hyphenate words shorter than this value (leave empty for default value 6)

A value lesser than 4 makes no sense. By increasing this value lesser words will be hyphenated, thus, there's a small speed gain.

The hyphen char for words (leave empty for &shy;)

The hyphen char for URLs and E-Mail (leave empty for zero width space)

Make Hyphenator to use this language as a fallback

At best you define the language by using the lang-Attribute in your HTML-Document. But sometimes this isn't possible. In this case you can set the language here. Use a two-letter language code (e.g. en for English).

Hyphenate the Document when Hyphenator.run() is called.

Sometimes you like to run the script, prepare everything, but not to hyphenate yet.
Hyphenation can later be executed by calling Hyphenator.toggleHyphenation()

Enable remote loading of language patterns.

By enabling remote loading Hyphenator will automatically load language patterns of supported languages when they are needed.
If you turn off remote loading Hyphenator only hyphenates texts in languages it has the patterns for. Make sure you have them selected!

Enable cache

Once a word is hyphenated it is cached, thus a word has only to be hyphenated once. You can turn this mechanism off – mainly for performance-measuring.

Remove hyphenation when copying text

Browsers don't remove soft hyphens from copied text. By enabling this feature hyphenation is removed on copy. This only works in browsers that support the oncopy-event.

Hyphenate frames and iframes, too

By default, hyphenator doesn't hyphenate text in frames. You can turn this on, but it will only work on frames that fullfill the same origin policy!

Store settings over page reload (only if DOMStorage is available).

With this option enabled, all configuration options are stored in a object called `Hyphenator_config` in the storage type defined by the property `storagetype` (if `storagetype is none` or storage isn't supported, nothing is stored).
By reloading or going to an other page, those settings remain set. This is very and specially usefull for the toggle-button.
Be carefull with this option!

Define intermediate state (style.visibility of elements while they are hyphenated).

Since Javascript is executed after the page is loaded, the user may see the unhyphenated text for a short time befor it is hyphenated and redrawn. To prevent this all textblocks treated by Hyphenator are set to invisible upon hyphenation (setting: "hidden"). The result is, that only hyphenated text is displayed.
On the other hand – if there's an error in the execution of Hyphenator.js – the text may stay invisible. Turn hiding off for debugging or if you prefer to see the redrawing of the text (setting: "visible").

Define DOM-Storage type (for modern browsers only).

Hyphenation patterns can be stored in DOM-Storage for later reuse. You can define the method (if at all):
'local': patterns are stored locally (they will be there even after a restart)
'session': patterns are removed if the window is closed
'none': DOM-Storage is not used
Degrades gracefully, if the browser does not support DOM-Storage.

Define, when elements are hyphenated.

Elements can either be hyphenated when all necessary patterns are loaded ('wait') or when the patterns for the specified language are loaded ('progressive').
The second option may be useful on multilanguage pages, where one language takes much longer to load.

Use the in-browser CSS3 hyphenation if available.

With this option enabled Hyphenator.js checks if the browser supports CSS3-hyphenation. If so, the elements are hyphenated by the browser instead of Hyphenator.js.
For unsupported languages or other browsers Hyphenator.js fills the gap and hyphenates as expected.
Make sure to check this box if you use Hyphenator_Loader.js!

Element Selection

Indicate how to get the elements for hyphenation:

Standard: Collecting elements by a classname
Custom: Collecting elements by a custom Selector-Function

indicate a classname (leave empty for default "hyphenate")
Selector Function:
function (hyphenateClass) { var tmp, el = [], i, l; if (window.document.getElementsByClassName) { el = contextWindow.document.getElementsByClassName(hyphenateClass); } else if (window.document.querySelectorAll) { el = contextWindow.document.querySelectorAll('.' + hyphenateClass); } else { tmp = contextWindow.document.getElementsByTagName('*'); l = tmp.length; for (i = 0; i < l; i += 1) { if (tmp[i].className.indexOf(hyphenateClass) !== -1 && tmp[i].className.indexOf(dontHyphenateClass) === -1) { el.push(tmp[i]); } } } return el; }
Using this method Hyphenator.js searches the DOM for elements with the indicated classname. Note: an element can have multiple classnames; separate them with spaces (e.g. <div class="content hyphenate">)
If you want to have more control over the element selection you may define your own selector function. It has to return an HTMLCollection of elements to be hyphenated. Specifially if you use a JavaScript-Framework, this may be very interesting…

Indicate a classname for elements that should NOT be hyphenated:
indicate a classname (leave empty for default "donthyphenate")

You can turn off hyphenation for elements with the indicated classname. (Note: The following elements are never hyphenated: video, audio, script, code, pre, img, br, samp, kbd, var, abbr, acronym, sub, sup, button, option, label, textarea, input, math, svg, style)

Indicate a classname for elements that should be hyphenated like URLs:
indicate a classname (leave empty for default "urlhyphenate")

If there are elements that are not normal text (e.g. programming code) they can by hyphenated like URLs (using the hyphen character for URLs).
Toggle Box

Indicate how the Togglebox should be displayed:

Display Toggle Box

The standard togglebox is a small button in the upper right corner of the page. By clicking on it, the user can turn off/on hyphenation. This is useful for copying or searching text on the site.
Since the standard togglebox may interfere with the design of your page, you can define it on your own.
Standard: The standard togglebox is used.
Custom: A custom Toggle Box is used
Toggle Box Function:
function () { var bdy, myTextNode, text = (Hyphenator.doHyphenation ? 'Hy-phen-a-tion' : 'Hyphenation'), myBox = contextWindow.document.getElementById('HyphenatorToggleBox'); if (!!myBox) { myBox.firstChild.data = text; } else { bdy = contextWindow.document.getElementsByTagName('body')[0]; myBox = createElem('div', contextWindow); myBox.setAttribute('id', 'HyphenatorToggleBox'); myBox.setAttribute('class', dontHyphenateClass); myTextNode = contextWindow.document.createTextNode(text); myBox.appendChild(myTextNode); myBox.onclick = Hyphenator.toggleHyphenation; myBox.style.position = 'absolute'; myBox.style.top = '0px'; myBox.style.right = '0px'; myBox.style.margin = '0'; myBox.style.backgroundColor = '#AAAAAA'; myBox.style.color = '#FFFFFF'; myBox.style.font = '6pt Arial'; myBox.style.letterSpacing = '0.2em'; myBox.style.padding = '3px'; myBox.style.cursor = 'pointer'; myBox.style.WebkitBorderBottomLeftRadius = '4px'; myBox.style.MozBorderRadiusBottomleft = '4px'; myBox.style.borderBottomLeftRadius = '4px'; bdy.appendChild(myBox); } }
Special Settings

Trigger callback function when hyphenation is done

onhyphenationdonecallback function:
onHyphenationDone = function (context) { return undefined; }
This function is called, when hyphenation of a page is completed. The 'context' paramater gets the href of the document.

Overwrite onerrorhandler

onerrorhandler function:
function(e){ alert("Hyphenator.js says:\n\nAn Error ocurred:\n"+e.message); }
Most errors (critical problems) are catched and catched errors dipatch the onerror function. By default there's an alert with a predefined text. You can change this function.

Overwrite onwarninghandler

onwarninghandler function:
function (e) { window.console.log(e.message); }
Most non critical problems are catched and catched problem dipatch the onwarning function. By default there's an console.log with a predefined text. You can change this function.

Overwrite onbeforehyphenationhandler

onbeforehyphenationhandler function:
function (word) { return word; }
This function is called for each word just before it gets hyphenated. You can change this function.

Overwrite onbeforehyphenationhandler

onafterhyphenationhandler function:
function (word) { return word; }
This function is called for each word just after it has been hyphenated. You can change this function
Minify

By minifying the resulting script you can save some bandwith. This page uses the JavaScript-Version of jsmin since it's easy to run on a webpage. You may achieve better results if you pack the resulting script with other minifiers/packers such as YUI Compressor or Google's Closure Compiler.

pack with jsmin Level

Copy the merged and packed script from the output field as is to a new text-file, give it a name (e.g. `"hyphenate.js"`) and include it in your website (`<script src="hyphenate.js" type="text/javascript"></script>`).
It will run automatically.

Note: You are not allowed to remove the licensing at the beginning of the script!

Output Hyphenator.js (plus patterns):

You are using Hyphenator_Loader.js. Therefor you have to create two script files as described below:

Copy the packed script from the first output field below as is to a new text-file, give it a name (e.g. `"hyphenator.js"`. Make sure this is the same name as you configured Hyphenator_Loader.js for.) and include it in your website (`<script src="hyphenator.js" type="text/javascript"></script>`).

Note: You are not allowed to remove the licensing at the beginning of the script!

Output Hyphenator.js:

Copy the script from the output field as is to a new text-file, give it a name (e.g. `"hylo.js"`) and include it in your website (`<script src="hylo.js" type="text/javascript"></script>`).
It will run automatically. Make sure that Hyphenator.js and the pattern files are available, too!

Note: You are not allowed to remove the licensing at the beginning of the script!

Output Hyphenator_Loader.js: