-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyphenator.js
2569 lines (2452 loc) · 80.9 KB
/
Hyphenator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @license Hyphenator X.Y.Z - client side hyphenation for webbrowsers
* Copyright (C) 2012 Mathias Nater, Zürich (mathias at mnn dot ch)
* Project and Source hosted on http://code.google.com/p/hyphenator/
*
* This JavaScript code is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser
* General Public License (GNU LGPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
*
* Hyphenator.js contains code from Bram Steins hypher.js-Project:
* https://github.com/bramstein/Hypher
*
* Code from this project is marked in the source and belongs
* to the following license:
*
* Copyright (c) 2011, Bram Stein
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* Comments are jsdoctoolkit formatted. See http://code.google.com/p/jsdoc-toolkit/
*/
/* The following comment is for JSLint: */
/*global window, ActiveXObject, unescape */
/*jslint browser: true */
/**
* @constructor
* @description Provides all functionality to do hyphenation, except the patterns that are loaded
* externally.
* @author Mathias Nater, <a href = "mailto:[email protected]">[email protected]</a>
* @version X.Y.Z
* @namespace Holds all methods and properties
* @example
* <script src = "Hyphenator.js" type = "text/javascript"></script>
* <script type = "text/javascript">
* Hyphenator.run();
* </script>
*/
var Hyphenator = (function (window) {
'use strict';
/**
* @name Hyphenator-supportedLang
* @description
* A key-value object that stores supported languages.
* The key is the bcp47 code of the language and the value
* is an object containing informations about the language
* @type {Object.<string, Object>}
* @private
* @example
* Check if language lang is supported:
* if (supportedLangs.hasOwnProperty(lang))
*/
var supportedLangs = (function () {
var r = {},
o = function (code, file, script, prompt) {
r[code] = {'file': file, 'script': script, 'prompt': prompt};
};
//latin:0, cyrillic: 1, arabic: 2, armenian:3, bengali: 4, devangari: 5, greek: 6
//gujarati: 7, kannada: 8, lao: 9, malayalam: 10, oriya: 11, persian: 12, punjabi: 13, tamil: 14, telugu: 15
//
//(language code, file name, script, prompt)
o('be', 'be.js', 1, 'Мова гэтага сайта не можа быць вызначаны аўтаматычна. Калі ласка пакажыце мову:');
o('ca', 'ca.js', 0, '');
o('cs', 'cs.js', 0, 'Jazyk této internetové stránky nebyl automaticky rozpoznán. Určete prosím její jazyk:');
o('da', 'da.js', 0, 'Denne websides sprog kunne ikke bestemmes. Angiv venligst sprog:');
o('bn', 'bn.js', 4, '');
o('de', 'de.js', 0, 'Die Sprache dieser Webseite konnte nicht automatisch bestimmt werden. Bitte Sprache angeben:');
o('el', 'el-monoton.js', 6, '');
o('el-monoton', 'el-monoton.js', 6, '');
o('el-polyton', 'el-polyton.js', 6, '');
o('en', 'en-us.js', 0, 'The language of this website could not be determined automatically. Please indicate the main language:');
o('en-gb', 'en-gb.js', 0, 'The language of this website could not be determined automatically. Please indicate the main language:');
o('en-us', 'en-us.js', 0, 'The language of this website could not be determined automatically. Please indicate the main language:');
o('eo', 'eo.js', 0, 'La lingvo de ĉi tiu retpaĝo ne rekoneblas aŭtomate. Bonvolu indiki ĝian ĉeflingvon:');
o('es', 'es.js', 0, 'El idioma del sitio no pudo determinarse autom%E1ticamente. Por favor, indique el idioma principal:');
o('et', 'et.js', 0, 'Veebilehe keele tuvastamine ebaõnnestus, palun valige kasutatud keel:');
o('fi', 'fi.js', 0, 'Sivun kielt%E4 ei tunnistettu automaattisesti. M%E4%E4rit%E4 sivun p%E4%E4kieli:');
o('fr', 'fr.js', 0, 'La langue de ce site n%u2019a pas pu %EAtre d%E9termin%E9e automatiquement. Veuillez indiquer une langue, s.v.p.%A0:');
o('grc', 'grc.js', 6, '');
o('gu', 'gu.js', 7, '');
o('hi', 'hi.js', 5, '');
o('hu', 'hu.js', 0, 'A weboldal nyelvét nem sikerült automatikusan megállapítani. Kérem adja meg a nyelvet:');
o('hy', 'hy.js', 3, 'Չհաջողվեց հայտնաբերել այս կայքի լեզուն։ Խնդրում ենք նշեք հիմնական լեզուն՝');
o('it', 'it.js', 0, 'Lingua del sito sconosciuta. Indicare una lingua, per favore:');
o('kn', 'kn.js', 8, 'ಜಾಲ ತಾಣದ ಭಾಷೆಯನ್ನು ನಿರ್ಧರಿಸಲು ಸಾಧ್ಯವಾಗುತ್ತಿಲ್ಲ. ದಯವಿಟ್ಟು ಮುಖ್ಯ ಭಾಷೆಯನ್ನು ಸೂಚಿಸಿ:');
o('la', 'la.js', 0, '');
o('lt', 'lt.js', 0, 'Nepavyko automatiškai nustatyti šios svetainės kalbos. Prašome įvesti kalbą:');
o('lv', 'lv.js', 0, 'Šīs lapas valodu nevarēja noteikt automātiski. Lūdzu norādiet pamata valodu:');
o('ml', 'ml.js', 10, 'ഈ വെ%u0D2C%u0D4D%u200Cസൈറ്റിന്റെ ഭാഷ കണ്ടുപിടിയ്ക്കാ%u0D28%u0D4D%u200D കഴിഞ്ഞില്ല. ഭാഷ ഏതാണെന്നു തിരഞ്ഞെടുക്കുക:');
o('nb', 'nb-no.js', 0, 'Nettstedets språk kunne ikke finnes automatisk. Vennligst oppgi språk:');
o('no', 'nb-no.js', 0, 'Nettstedets språk kunne ikke finnes automatisk. Vennligst oppgi språk:');
o('nb-no', 'nb-no.js', 0, 'Nettstedets språk kunne ikke finnes automatisk. Vennligst oppgi språk:');
o('nl', 'nl.js', 0, 'De taal van deze website kan niet automatisch worden bepaald. Geef de hoofdtaal op:');
o('or', 'or.js', 11, '');
o('pa', 'pa.js', 13, '');
o('pl', 'pl.js', 0, 'Języka tej strony nie można ustalić automatycznie. Proszę wskazać język:');
o('pt', 'pt.js', 0, 'A língua deste site não pôde ser determinada automaticamente. Por favor indique a língua principal:');
o('ru', 'ru.js', 1, 'Язык этого сайта не может быть определен автоматически. Пожалуйста укажите язык:');
o('sk', 'sk.js', 0, '');
o('sl', 'sl.js', 0, 'Jezika te spletne strani ni bilo mogoče samodejno določiti. Prosim navedite jezik:');
o('sr-latn', 'sr-latn.js', 0, 'Jezika te spletne strani ni bilo mogoče samodejno določiti. Prosim navedite jezik:');
o('sv', 'sv.js', 0, 'Spr%E5ket p%E5 den h%E4r webbplatsen kunde inte avg%F6ras automatiskt. V%E4nligen ange:');
o('ta', 'ta.js', 14, '');
o('te', 'te.js', 15, '');
o('tr', 'tr.js', 0, 'Bu web sitesinin dili otomatik olarak tespit edilememiştir. Lütfen dökümanın dilini seçiniz%A0:');
o('uk', 'uk.js', 1, 'Мова цього веб-сайту не може бути визначена автоматично. Будь ласка, вкажіть головну мову:');
return r;
}()),
/**
* @name Hyphenator-languageHint
* @description
* An automatically generated string to be displayed in a prompt if the language can't be guessed.
* The string is generated using the supportedLangs-object.
* @see Hyphenator-supportedLang
* @type {string}
* @private
* @see Hyphenator-autoSetMainLanguage
*/
languageHint = (function () {
var k, r = '';
for (k in supportedLangs) {
if (supportedLangs.hasOwnProperty(k)) {
r += k + ', ';
}
}
r = r.substring(0, r.length - 2);
return r;
}()),
/**
* @name Hyphenator-basePath
* @description
* A string storing the basepath from where Hyphenator.js was loaded.
* This is used to load the patternfiles.
* The basepath is determined dynamically by searching all script-tags for Hyphenator.js
* If the path cannot be determined http://hyphenator.googlecode.com/svn/trunk/ is used as fallback.
* @type {string}
* @private
* @see Hyphenator-loadPatterns
*/
basePath = (function () {
var s = document.getElementsByTagName('script'), i = 0, p, src, t = s[i];
while (!!t) {
if (!!t.src) {
src = t.src;
p = src.indexOf('Hyphenator.js');
if (p !== -1) {
return src.substring(0, p);
}
}
i += 1;
t = s[i];
}
return 'http://hyphenator.googlecode.com/svn/trunk/';
}()),
/**
* @name Hyphenator-isLocal
* @description
* isLocal is true, if Hyphenator is loaded from the same domain, as the webpage, but false, if
* it's loaded from an external source (i.e. directly from google.code)
*/
isLocal = (function () {
var re = false;
if (window.location.href.indexOf(basePath) !== -1) {
re = true;
}
return re;
}()),
/**
* @name Hyphenator-documentLoaded
* @description
* documentLoaded is true, when the DOM has been loaded. This is set by runOnContentLoaded
*/
documentLoaded = false,
documentCount = 0,
/**
* @name Hyphenator-persistentConfig
* @description
* if persistentConfig is set to true (defaults to false), config options and the state of the
* toggleBox are stored in DOM-storage (according to the storage-setting). So they haven't to be
* set for each page.
*/
persistentConfig = false,
/**
* @name Hyphenator-contextWindow
* @description
* contextWindow stores the window for the document to be hyphenated.
* If there are frames this will change.
* So use contextWindow instead of window!
*/
contextWindow = window,
/**
* @name Hyphenator-doFrames
* @description
* switch to control if frames/iframes should be hyphenated, too
* defaults to false (frames are a bag of hurt!)
*/
doFrames = false,
/**
* @name Hyphenator-dontHyphenate
* @description
* A key-value object containing all html-tags whose content should not be hyphenated
* @type {Object.<string,boolean>}
* @private
* @see Hyphenator-hyphenateElement
*/
dontHyphenate = {'script': true, 'code': true, 'pre': true, 'img': true, 'br': true, 'samp': true, 'kbd': true, 'var': true, 'abbr': true, 'acronym': true, 'sub': true, 'sup': true, 'button': true, 'option': true, 'label': true, 'textarea': true, 'input': true, 'math': true, 'svg': true},
/**
* @name Hyphenator-enableCache
* @description
* A variable to set if caching is enabled or not
* @type boolean
* @default true
* @private
* @see Hyphenator.config
* @see hyphenateWord
*/
enableCache = true,
/**
* @name Hyphenator-storageType
* @description
* A variable to define what html5-DOM-Storage-Method is used ('none', 'local' or 'session')
* @type {string}
* @default 'none'
* @private
* @see Hyphenator.config
*/
storageType = 'local',
/**
* @name Hyphenator-storage
* @description
* An alias to the storage-Method defined in storageType.
* Set by Hyphenator.run()
* @type {Object|undefined}
* @default null
* @private
* @see Hyphenator.run
*/
storage,
/**
* @name Hyphenator-enableReducedPatternSet
* @description
* A variable to set if storing the used patterns is set
* @type boolean
* @default false
* @private
* @see Hyphenator.config
* @see hyphenateWord
* @see Hyphenator.getRedPatternSet
*/
enableReducedPatternSet = false,
/**
* @name Hyphenator-enableRemoteLoading
* @description
* A variable to set if pattern files should be loaded remotely or not
* @type boolean
* @default true
* @private
* @see Hyphenator.config
* @see Hyphenator-loadPatterns
*/
enableRemoteLoading = true,
/**
* @name Hyphenator-displayToggleBox
* @description
* A variable to set if the togglebox should be displayed or not
* @type boolean
* @default false
* @private
* @see Hyphenator.config
* @see Hyphenator-toggleBox
*/
displayToggleBox = false,
/**
* @name Hyphenator-onError
* @description
* A function that can be called upon an error.
* @see Hyphenator.config
* @type {function(Object)}
* @private
*/
onError = function (e) {
window.alert("Hyphenator.js says:\n\nAn Error occurred:\n" + e.message);
},
/**
* @name Hyphenator-createElem
* @description
* A function alias to document.createElementNS or document.createElement
* @type {function(string, Object)}
* @private
*/
createElem = function (tagname, context) {
context = context || contextWindow;
var el;
if (document.createElementNS) {
el = context.document.createElementNS('http://www.w3.org/1999/xhtml', tagname);
} else if (document.createElement) {
el = context.document.createElement(tagname);
}
return el;
},
/**
* @name Hyphenator-css3
* @description
* A variable to set if css3 hyphenation should be used
* @type boolean
* @default false
* @private
* @see Hyphenator.config
*/
css3 = false,
/**
* @name Hyphenator-css3_hsupport
* @description
* A generated object containing information for CSS3-hyphenation support
* {
* support: boolean,
* property: <the property name to access hyphen-settings>,
* languages: <an object containing supported languages>
* }
* @type object
* @default undefined
* @private
* @see Hyphenator-css3_gethsupport
*/
css3_h9n,
/**
* @name Hyphenator-css3_gethsupport
* @description
* This function sets Hyphenator-css3_h9n for the current UA
* @type function
* @private
* @see Hyphenator-css3_h9n
*/
css3_gethsupport = function () {
var s,
ua = navigator.userAgent,
createLangSupportChecker = function (prefix) {
var testStrings = [
//latin: 0
'abcdefghijklmnopqrstuvwxyz',
//cyrillic: 1
'абвгдеёжзийклмнопрстуфхцчшщъыьэюя',
//arabic: 2
'أبتثجحخدذرزسشصضطظعغفقكلمنهوي',
//armenian: 3
'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆ',
//bengali: 4
'ঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ',
//devangari: 5
'ँंःअआइईउऊऋऌएऐओऔकखगघङचछजझञटठडढणतथदधनपफबभमयरलळवशषसहऽािीुूृॄेैोौ्॒॑ॠॡॢॣ',
//greek: 6
'αβγδεζηθικλμνξοπρσςτυφχψω',
//gujarati: 7
'બહઅઆઇઈઉઊઋૠએઐઓઔાિીુૂૃૄૢૣેૈોૌકખગઘઙચછજઝઞટઠડઢણતથદધનપફસભમયરલળવશષ',
//kannada: 8
'ಂಃಅಆಇಈಉಊಋಌಎಏಐಒಓಔಕಖಗಘಙಚಛಜಝಞಟಠಡಢಣತಥದಧನಪಫಬಭಮಯರಱಲಳವಶಷಸಹಽಾಿೀುೂೃೄೆೇೈೊೋೌ್ೕೖೞೠೡ',
//lao: 9
'ກຂຄງຈຊຍດຕຖທນບປຜຝພຟມຢຣລວສຫອຮະັາິີຶືຸູົຼເແໂໃໄ່້໊໋ໜໝ',
//malayalam: 10
'ംഃഅആഇഈഉഊഋഌഎഏഐഒഓഔകഖഗഘങചഛജഝഞടഠഡഢണതഥദധനപഫബഭമയരറലളഴവശഷസഹാിീുൂൃെേൈൊോൌ്ൗൠൡൺൻർൽൾൿ',
//oriya: 11
'ଁଂଃଅଆଇଈଉଊଋଌଏଐଓଔକଖଗଘଙଚଛଜଝଞଟଠଡଢଣତଥଦଧନପଫବଭମଯରଲଳଵଶଷସହାିୀୁୂୃେୈୋୌ୍ୗୠୡ',
//persian: 12
'أبتثجحخدذرزسشصضطظعغفقكلمنهوي',
//punjabi: 13
'ਁਂਃਅਆਇਈਉਊਏਐਓਔਕਖਗਘਙਚਛਜਝਞਟਠਡਢਣਤਥਦਧਨਪਫਬਭਮਯਰਲਲ਼ਵਸ਼ਸਹਾਿੀੁੂੇੈੋੌ੍ੰੱ',
//tamil: 14
'ஃஅஆஇஈஉஊஎஏஐஒஓஔகஙசஜஞடணதநனபமயரறலளழவஷஸஹாிீுூெேைொோௌ்ௗ',
//telugu: 15
'ఁంఃఅఆఇఈఉఊఋఌఎఏఐఒఓఔకఖగఘఙచఛజఝఞటఠడఢణతథదధనపఫబభమయరఱలళవశషసహాిీుూృౄెేైొోౌ్ౕౖౠౡ'
],
f = function (lang) {
var shadow,
computedHeight,
bdy = window.document.getElementsByTagName('body')[0];
//create and append shadow-test-element
shadow = createElem('div', window);
shadow.id = 'Hyphenator_LanguageChecker';
shadow.style.width = '5em';
shadow.style[prefix] = 'auto';
shadow.style.hyphens = 'auto';
shadow.style.fontSize = '12px';
shadow.style.lineHeight = '12px';
shadow.style.visibility = 'hidden';
if (supportedLangs.hasOwnProperty(lang)) {
shadow.lang = lang;
shadow.style['-webkit-locale'] = "'" + lang + "'";
shadow.innerHTML = testStrings[supportedLangs[lang].script];
} else {
return false;
}
bdy.appendChild(shadow);
//measure its height
//computedHeight = parseInt(window.getComputedStyle(shadow, null).height.slice(0, -2), 10);
computedHeight = shadow.offsetHeight;
//remove shadow element
bdy.removeChild(shadow);
return (computedHeight > 12) ? true : false;
};
return f;
},
r = {
support: false,
property: '',
checkLangSupport: function () {}
};
if (window.getComputedStyle) {
s = contextWindow.getComputedStyle(contextWindow.document.getElementsByTagName('body')[0], null);
} else {
//ancient Browsers don't support CSS3 anyway
css3_h9n = r;
return;
}
if (s['-webkit-hyphens'] !== undefined) {
r.support = true;
r.property = '-webkit-hyphens';
r.checkLangSupport = createLangSupportChecker('-webkit-hyphens');
} else if (s.MozHyphens !== undefined) {
r.support = true;
r.property = 'MozHyphens';
r.checkLangSupport = createLangSupportChecker('MozHyphens');
} else if (s['-ms-hyphens'] !== undefined) {
r.support = true;
r.property = '-ms-hyphens';
r.checkLangSupport = createLangSupportChecker('-ms-hyphens');
}
css3_h9n = r;
},
/**
* @name Hyphenator-hyphenateClass
* @description
* A string containing the css-class-name for the hyphenate class
* @type {string}
* @default 'hyphenate'
* @private
* @example
* <p class = "hyphenate">Text</p>
* @see Hyphenator.config
*/
hyphenateClass = 'hyphenate',
/**
* @name Hyphenator-dontHyphenateClass
* @description
* A string containing the css-class-name for elements that should not be hyphenated
* @type {string}
* @default 'donthyphenate'
* @private
* @example
* <p class = "donthyphenate">Text</p>
* @see Hyphenator.config
*/
dontHyphenateClass = 'donthyphenate',
/**
* @name Hyphenator-min
* @description
* A number wich indicates the minimal length of words to hyphenate.
* @type {number}
* @default 6
* @private
* @see Hyphenator.config
*/
min = 6,
/**
* @name Hyphenator-orphanControl
* @description
* Control how the last words of a line are handled:
* level 1 (default): last word is hyphenated
* level 2: last word is not hyphenated
* level 3: last word is not hyphenated and last space is non breaking
* @type {number}
* @default 1
* @private
*/
orphanControl = 1,
/**
* @name Hyphenator-isBookmarklet
* @description
* Indicates if Hyphanetor runs as bookmarklet or not.
* @type boolean
* @default false
* @private
*/
isBookmarklet = (function () {
var loc = null, re = false, jsArray = document.getElementsByTagName('script'), i, l;
for (i = 0, l = jsArray.length; i < l; i += 1) {
if (!!jsArray[i].getAttribute('src')) {
loc = jsArray[i].getAttribute('src');
}
if (!!loc && loc.indexOf('Hyphenator.js?bm=true') !== -1) {
re = true;
}
}
return re;
}()),
/**
* @name Hyphenator-mainLanguage
* @description
* The general language of the document. In contrast to {@link Hyphenator-defaultLanguage},
* mainLanguage is defined by the client (i.e. by the html or by a prompt).
* @type {string|null}
* @private
* @see Hyphenator-autoSetMainLanguage
*/
mainLanguage = null,
/**
* @name Hyphenator-defaultLanguage
* @description
* The language defined by the developper. This language setting is defined by a config option.
* It is overwritten by any html-lang-attribute and only taken in count, when no such attribute can
* be found (i.e. just before the prompt).
* @type {string|null}
* @private
* @see Hyphenator-autoSetMainLanguage
*/
defaultLanguage = '',
/**
* @name Hyphenator-elements
* @description
* An array holding all elements that have to be hyphenated. This var is filled by
* {@link Hyphenator-gatherDocumentInfos}
* @type {Array}
* @private
*/
elements = (function () {
var Element = function (element, data) {
this.element = element;
this.hyphenated = false;
this.treated = false; //collected but not hyphenated (dohyphenation is off)
this.data = data;
},
ElementCollection = function () {
this.count = 0;
this.hyCount = 0;
this.list = {};
};
ElementCollection.prototype = {
add: function (el, lang, data) {
if (!this.list.hasOwnProperty(lang)) {
this.list[lang] = [];
}
this.list[lang].push(new Element(el, data));
this.count += 1;
},
each: function (fn) {
var k;
for (k in this.list) {
if (this.list.hasOwnProperty(k)) {
fn(k, this.list[k]);
}
}
}
};
return new ElementCollection();
}()),
/**
* @name Hyphenator-exceptions
* @description
* An object containing exceptions as comma separated strings for each language.
* When the language-objects are loaded, their exceptions are processed, copied here and then deleted.
* @see Hyphenator-prepareLanguagesObj
* @type {Object}
* @private
*/
exceptions = {},
/**
* @name Hyphenator-docLanguages
* @description
* An object holding all languages used in the document. This is filled by
* {@link Hyphenator-gatherDocumentInfos}
* @type {Object}
* @private
*/
docLanguages = {},
/**
* @name Hyphenator-state
* @description
* A number that inidcates the current state of the script
* 0: not initialized
* 1: loading patterns
* 2: ready
* 3: hyphenation done
* 4: hyphenation removed
* @type {number}
* @private
*/
state = 0,
/**
* @name Hyphenator-url
* @description
* A string containing a RegularExpression to match URL's
* @type {string}
* @private
*/
url = '(\\w*:\/\/)?((\\w*:)?(\\w*)@)?((([\\d]{1,3}\\.){3}([\\d]{1,3}))|((www\\.|[a-zA-Z]\\.)?[a-zA-Z0-9\\-\\.]+\\.([a-z]{2,4})))(:\\d*)?(\/[\\w#!:\\.?\\+=&%@!\\-]*)*',
// protocoll usr pwd ip or host tld port path
/**
* @name Hyphenator-mail
* @description
* A string containing a RegularExpression to match mail-adresses
* @type {string}
* @private
*/
mail = '[\\w-\\.]+@[\\w\\.]+',
/**
* @name Hyphenator-urlRE
* @description
* A RegularExpressions-Object for url- and mail adress matching
* @type {RegExp}
* @private
*/
urlOrMailRE = new RegExp('(' + url + ')|(' + mail + ')', 'i'),
/**
* @name Hyphenator-zeroWidthSpace
* @description
* A string that holds a char.
* Depending on the browser, this is the zero with space or an empty string.
* zeroWidthSpace is used to break URLs
* @type {string}
* @private
*/
zeroWidthSpace = (function () {
var zws, ua = navigator.userAgent.toLowerCase();
zws = String.fromCharCode(8203); //Unicode zero width space
if (ua.indexOf('msie 6') !== -1) {
zws = ''; //IE6 doesn't support zws
}
if (ua.indexOf('opera') !== -1 && ua.indexOf('version/10.00') !== -1) {
zws = ''; //opera 10 on XP doesn't support zws
}
return zws;
}()),
/**
* @name Hyphenator-onHyphenationDone
* @description
* A method to be called, when the last element has been hyphenated or the hyphenation has been
* removed from the last element.
* @see Hyphenator.config
* @type {function()}
* @private
*/
onHyphenationDone = function () {},
/**
* @name Hyphenator-selectorFunction
* @description
* A function that has to return a HTMLNodeList of Elements to be hyphenated.
* By default it uses the classname ('hyphenate') to select the elements.
* @see Hyphenator.config
* @type {function()}
* @private
*/
selectorFunction = function () {
var tmp, el = [], i, l;
if (document.getElementsByClassName) {
el = contextWindow.document.getElementsByClassName(hyphenateClass);
} else if (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;
},
/**
* @name Hyphenator-intermediateState
* @description
* The value of style.visibility of the text while it is hyphenated.
* @see Hyphenator.config
* @type {string}
* @private
*/
intermediateState = 'hidden',
/**
* @name Hyphenator-unhide
* @description
* How hidden elements unhide: either simultaneous (default: 'wait') or progressively.
* 'wait' makes Hyphenator.js to wait until all elements are hyphenated (one redraw)
* With 'progressiv' Hyphenator.js unhides elements as soon as they are hyphenated.
* @see Hyphenator.config
* @type {string}
* @private
*/
unhide = 'wait',
/**
* @name Hyphenator-CSSEditors
* @description A container array that holds CSSEdit classes
* For each window object one CSSEdit class is inserted
* @see Hyphenator-CSSEdit
* @type {array}
* @private
*/
CSSEditors = [],
/**
* @name Hyphenator-CSSEditors
* @description A custom class with two public methods: setRule() and clearChanges()
* Tis is used to hide/unhide elements when they are hyphenated.
* @see Hyphenator-gatherDocumentInfos
* @type {function ()}
* @private
*/
CSSEdit = function (w) {
w = w || window;
var doc = w.document,
sheet = doc.styleSheets[doc.styleSheets.length - 1],
changes = [],
findRule = function (sel) {
var sheet, rule, sheets = window.document.styleSheets, rules, i, j;
for (i = 0; i < sheets.length; i += 1) {
sheet = sheets[i];
if (!!sheet.cssRules) {
rules = sheet.cssRules;
} else if (!!sheet.rules) {
// IE < 9
rules = sheet.rules;
}
if (!!rules && !!rules.length) {
for (j = 0; j < rules.length; j += 1) {
rule = rules[j];
if (rule.selectorText === sel) {
return {
index: j,
rule: rule
};
}
}
}
}
return false;
},
addRule = function (sel, rulesStr) {
var i, r;
if (!!sheet.insertRule) {
if (!!sheet.cssRules) {
i = sheet.cssRules.length;
} else {
i = 0;
}
r = sheet.insertRule(sel + '{' + rulesStr + '}', i);
} else if (!!sheet.addRule) {
// IE < 9
if (!!sheet.rules) {
i = sheet.rules.length;
} else {
i = 0;
}
sheet.addRule(sel, rulesStr, i);
r = i;
}
return r;
},
removeRule = function (sheet, index) {
if (sheet.deleteRule) {
sheet.deleteRule(index);
} else {
// IE < 9
sheet.removeRule(index);
}
};
return {
setRule: function (sel, rulesString) {
var i, existingRule, cssText;
existingRule = findRule(sel);
if (!!existingRule) {
if (!!existingRule.rule.cssText) {
cssText = existingRule.rule.cssText;
} else {
// IE < 9
cssText = existingRule.rule.style.cssText.toLowerCase();
}
if (cssText === '.' + hyphenateClass + ' { visibility: hidden; }') {
//browsers w/o IE < 9 and no additional style defs:
//add to [changes] for later removal
changes.push({sheet: existingRule.rule.parentStyleSheet, index: existingRule.index});
} else if (cssText.indexOf('visibility: hidden') !== -1) {
// IE < 9 or additional style defs:
// add new rule
i = addRule(sel, rulesString);
//add to [changes] for later removal
changes.push({sheet: sheet, index: i});
// clear existing def
existingRule.rule.style.visibility = '';
}
} else {
i = addRule(sel, rulesString);
changes.push({sheet: sheet, index: i});
}
},
clearChanges: function () {
var change = changes.pop();
while (!!change) {
removeRule(change.sheet, change.index);
change = changes.pop();
}
}
};
},
/**
* @name Hyphenator-hyphen
* @description
* A string containing the character for in-word-hyphenation
* @type {string}
* @default the soft hyphen
* @private
* @see Hyphenator.config
*/
hyphen = String.fromCharCode(173),
/**
* @name Hyphenator-urlhyphen
* @description
* A string containing the character for url/mail-hyphenation
* @type {string}
* @default the zero width space
* @private
* @see Hyphenator.config
* @see Hyphenator-zeroWidthSpace
*/
urlhyphen = zeroWidthSpace,
/**
* @name Hyphenator-safeCopy
* @description
* Defines wether work-around for copy issues is active or not
* Not supported by Opera (no onCopy handler)
* @type boolean
* @default true
* @private
* @see Hyphenator.config
* @see Hyphenator-registerOnCopy
*/
safeCopy = true,
/*
* runOnContentLoaded is based od jQuery.bindReady()
* see
* jQuery JavaScript Library v1.3.2
* http://jquery.com/
*
* Copyright (c) 2009 John Resig
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
* Revision: 6246
*/
/**
* @name Hyphenator-runOnContentLoaded
* @description
* A crossbrowser solution for the DOMContentLoaded-Event based on jQuery
* <a href = "http://jquery.com/</a>
* I added some functionality: e.g. support for frames and iframes…
* @param {Object} w the window-object
* @param {function()} f the function to call onDOMContentLoaded
* @private
*/
runOnContentLoaded = function (w, f) {
var
toplevel, hyphRunForThis = {},
add = document.addEventListener ? 'addEventListener' : 'attachEvent',
rem = document.addEventListener ? 'removeEventListener' : 'detachEvent',
pre = document.addEventListener ? '' : 'on',
init = function (context) {
contextWindow = context || window;
if (!hyphRunForThis[contextWindow.location.href] && (!documentLoaded || !!contextWindow.frameElement)) {
documentLoaded = true;
f();
hyphRunForThis[contextWindow.location.href] = true;
}
},
doScrollCheck = function () {
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch (error) {
setTimeout(doScrollCheck, 1);
return;
}
// and execute any waiting functions
init(window);
},
doOnLoad = function () {
var i, haveAccess, fl = window.frames.length;
if (doFrames && fl > 0) {
for (i = 0; i < fl; i += 1) {
haveAccess = undefined;
//try catch isn't enough for webkit
try {
//opera throws only on document.toString-access
haveAccess = window.frames[i].document.toString();
} catch (e) {
haveAccess = undefined;
}
if (!!haveAccess) {
if (window.frames[i].location.href !== 'about:blank') {
init(window.frames[i]);
}
}
}
contextWindow = window;
f();
hyphRunForThis[window.location.href] = true;
} else {
init(window);