test26.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <title>Test 026</title>
  6. <script>
  7. const Hyphenopoly = {
  8. require: {
  9. "de": "FORCEHYPHENOPOLY"
  10. },
  11. setup: {
  12. selectors: {
  13. ".hyphenate": {
  14. hyphen: "•"
  15. },
  16. ".usePipe": {
  17. hyphen: "|"
  18. }
  19. }
  20. },
  21. handleEvent: {
  22. hyphenopolyEnd: function (e) {
  23. /*async function hyphenate_de(text) {
  24. document.getElementById("test2").innerText = (await Hyphenopoly.hyphenators.de)(text);
  25. assert();
  26. }*/
  27. function hyphenate_de(text) {
  28. Hyphenopoly.hyphenators.de.then(function (dehyph) {
  29. document.getElementById("test2").innerText = dehyph(text, ".usePipe");
  30. assertAll();
  31. });
  32. }
  33. hyphenate_de("Silbentrennung verbessert den Blocksatz.");
  34. },
  35. error: function (e) {
  36. assertError(e);
  37. }
  38. }
  39. };
  40. function assertError(e) {
  41. var result = false;
  42. if (e.msg.indexOf("Promises not supported in this engine") !== -1) {
  43. result = true;
  44. }
  45. if (parent != window) {
  46. parent.postMessage(JSON.stringify({
  47. desc: document.getElementById("desc").innerHTML,
  48. index: 26,
  49. result: (result ? "passed" : "failed")
  50. }), window.location.href);
  51. }
  52. }
  53. function assertAll() {
  54. var tests = 2;
  55. var i = 1;
  56. var test = "";
  57. var ref = "";
  58. var result = false;
  59. while (i <= tests) {
  60. test = document.getElementById("test" + i).innerHTML;
  61. ref = document.getElementById("ref" + i).innerHTML;
  62. if (test === ref) {
  63. document.getElementById("result").innerHTML += "<p style=\"background-color: #d6ffd6\">" + i + " passed</p>";
  64. result = result || true;
  65. } else {
  66. document.getElementById("result").innerHTML += "<p style=\"background-color: #ffd6d6\">" + i + " failed</p>";
  67. result = result || false;
  68. }
  69. i += 1;
  70. }
  71. if (parent != window) {
  72. parent.postMessage(JSON.stringify({
  73. desc: document.getElementById("desc").innerHTML,
  74. index: 26,
  75. result: (result ? "passed" : "failed")
  76. }), window.location.href);
  77. }
  78. }
  79. </script>
  80. <script src="../Hyphenopoly_Loader.js"></script>
  81. <style type="text/css">
  82. body {
  83. width:50%;
  84. margin-left:25%;
  85. margin-right:25%;
  86. }
  87. .test {
  88. background-color: #D8E2F9;
  89. }
  90. .ref {
  91. background-color: #FEEFC0;
  92. }
  93. .hyphenate {
  94. hyphens: auto;
  95. -ms-hyphens: auto;
  96. -moz-hyphens: auto;
  97. -webkit-hyphens: auto;
  98. }
  99. </style>
  100. </head>
  101. <body>
  102. <div id="navigate"><a href="index.html">&Larr;&nbsp;Index</a>&nbsp;|&nbsp;<a href="test25.html">&larr;&nbsp;Prev</a>&nbsp;|&nbsp;<a href="test27.html">Next&nbsp;&rarr;</a></div>
  103. <h1>Test 026</h1>
  104. <p id="desc">Hyphenate manually (uses promises): FORCE</p>
  105. <div id="result"></div>
  106. <hr>
  107. <p id="test1" class="test hyphenate" lang="de">Silbentrennungsalgorithmus</p>
  108. <p id="ref1" class="ref" lang="de">Sil•ben•tren•nungs•al•go•rith•mus</p>
  109. <p id="test2" class="test" lang="de"></p>
  110. <p id="ref2" class="ref" lang="de">Sil|ben|tren|nung ver|bes|sert den Block|satz.</p>
  111. <hr>
  112. <div><span class="test">Test</span> <span class="ref">Ref</span></div>
  113. </body>
  114. </html>