PageSourceSearch

https://www.schwerin.de/export/system/modules/de.sis.lhs/resources/js/Hyphenator_Loader.js

js schwerin.de collected 2026-09-24 17:54:56 UTC 5,844 bytes, 159 lines download raw bytes

1/** @license Hyphenator_Loader 5.1.0 - client side hyphenation for webbrowsers
2 *  Copyright (C) 2015  Mathias Nater, Zürich (mathiasnater at gmail dot com)
3 *  https://github.com/mnater/Hyphenator
4 * 
5 *  Released under the MIT license
6 *  http://mnater.github.io/Hyphenator/LICENSE.txt
7 */
8
9/**
10 * @constructor
11 * @description Checks if there's CSS-hyphenation available for the given languages and
12 * loads and runs Hyphenator if there's no CSS-hyphenation
13 * @author Mathias Nater, <a href = "mailto:[email protected]">[email protected]</a>
14 * @version 5.1.0
15 * @namespace Holds all methods and properties
16 */
17
18/* The following comment is for JSLint: */
19/*jslint browser: true */
20/*global Hyphenator: false */
21
22var Hyphenator_Loader = (function (window) {
23    'use strict';
24    var languages,
25        config,
26        path,
27
28        /**
29         * @name Hyphenator-createElem
30         * @description
31         * A function alias to document.createElementNS or document.createElement
32         * @param {string} tagname the Element to create
33         * @type {function({string})}
34         * @private
35         */
36        createElem = function (tagname) {
37            var r;
38            if (window.document.createElementNS) {
39                r = window.document.createElementNS('http://www.w3.org/1999/xhtml', tagname);
40            } else if (window.document.createElement) {
41                r = window.document.createElement(tagname);
42            }
43            return r;
44        },
45
46        /**
47         * @name Hyphenator-checkLangSupport
48         * @description
49         * Checks if hyphenation for all languages are supported:
50         * If body is present (i.e. DOMContentLoaded) a hidden div is added to the body and the height of probably hyphenated text is measured.
51         * Else a fake body is inserted and used instead of the 'real' body. It will later be removed.
52         * @type {function()}
53         * @return {bool}
54         * @private
55         */
56        checkLangSupport = function () {
57            var shadowContainer,
58                shadow,
59                shadows = [],
60                lang,
61                i,
62                r = true,
63                bdy = window.document.getElementsByTagName('body')[0],
64                fakeBdy = false;
65            if (!bdy) {
66                fakeBdy = createElem('body');
67            }
68            shadowContainer = createElem('div');
69            shadowContainer.style.MozHyphens = 'auto';
70            shadowContainer.style['-webkit-hyphens'] = 'auto';
71            shadowContainer.style['-ms-hyphens'] = 'auto';
72            shadowContainer.style.hyphens = 'auto';
73            shadowContainer.style.fontSize = '12px';
74            shadowContainer.style.lineHeight = '12px';
75            shadowContainer.style.wordWrap = 'normal';
76            shadowContainer.style.visibility = 'hidden';
77
78            for (lang in languages) {
79                if (languages.hasOwnProperty(lang)) {
80                    shadow = createElem('div');
81                    shadow.style.width = '5em';
82                    shadow.lang = lang;
83                    shadow.style['-webkit-locale'] = "'" + lang + "'";
84                    shadow.appendChild(window.document.createTextNode(languages[lang]));
85                    shadowContainer.appendChild(shadow);
86                    shadows.push(shadow);
87                }
88            }
89            if (fakeBdy) {
90                fakeBdy.appendChild(shadowContainer);
91                window.document.documentElement.appendChild(fakeBdy);
92            } else {
93                bdy.appendChild(shadowContainer);
94            }
95            for (i = 0; i < shadows.length; i += 1) {
96                r = (shadows[i].offsetHeight > 12) && r;
97            }
98            if (fakeBdy) {
99                fakeBdy.parentNode.removeChild(fakeBdy);
100            } else {
101                bdy.removeChild(shadowContainer);
102            }
103            return r;
104        },
105
106        /**
107         * @name Hyphenator-loadNrunHyphenator
108         * @description Loads Hyphenator.js and runs it with the given configuration
109         * @type {function({object})}
110         * @param {object} config the configuration object for Hyphenator.js
111         * @private
112         */
113        loadNrunHyphenator = function (config) {
114            var head, script, done = false;
115
116            head = window.document.getElementsByTagName('head').item(0);
117            script = createElem('script');
118            script.src = path;
119            script.type = 'text/javascript';
120            script.onload = script.onreadystatechange = function () {
121                if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
122                    done = true;
123
124                    Hyphenator.config(config);
125                    Hyphenator.run();
126
127                    // Handle memory leak in IE
128                    script.onload = script.onreadystatechange = null;
129                    if (head && script.parentNode) {
130                        head.removeChild(script);
131                    }
132                }
133            };
134            head.appendChild(script);
135        },
136
137        runner = function () {
138            var allLangsSupported = checkLangSupport();
139            if (!allLangsSupported) {
140                loadNrunHyphenator(config);
141            }
142        };
143
144    return {
145        /**
146         * @name Hyphenator_Loader.init
147         * @description Bootstrap function that inits the loader
148         * @param {Object} languages an object with the language as key and a long word as value
149         * @param {Object} config the Hyphenator.js configuration object
150         * @public
151         */
152        init: function (langs, p, configs) {
153            languages = langs;
154            path = p;
155            config = configs || {};
156            runner();
157        }
158    };
159}(window));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.