-
Notifications
You must be signed in to change notification settings - Fork 9
/
tengwar.js
105 lines (94 loc) · 3.18 KB
/
tengwar.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
// Compiles to public/tengwar.js
"use strict";
var GeneralUse = require("./general-use");
var Classical = require("./classical");
var Beleriand = require("./beleriand");
var TengwarAnnatar = require("./tengwar-annatar");
var TengwarParmaite = require("./tengwar-parmaite");
var modes = require("./modes");
var detectWebFont = require("./detect-web-font");
var array_ = Array.prototype;
if (typeof document !== "undefined") {
if (document.readyState === "complete") {
onload();
} else {
document.addEventListener("DOMContentLoaded", onload, true);
}
detectWebFont(onfontcheck);
}
var loaded;
function onload() {
loaded = true;
progress();
}
var webfontDetected;
function onfontcheck(detected) {
if (detected) {
webfontDetected = true;
progress()
} else {
onnowebfont();
}
}
function onnowebfont() {
if (!supportedBrowser())
return;
var elements = document.querySelectorAll(".tengwar");
array_.forEach.call(elements, function (element) {
element.classList.add("error");
element.innerHTML = "Cannot render because WebFonts are not available in this browser.";
});
}
function supportedBrowser() {
if (!document.body.classList || !document.querySelectorAll || !array_.forEach) {
return;
}
return true;
}
function onoldbrowser() {
if (!document.body.classList || !document.querySelectorAll || !array_.forEach)
return;
}
function progress() {
if (loaded === void 0 || webfontDetected === void 0)
return;
if (!supportedBrowser())
return;
var elements = document.querySelectorAll(".tengwar");
array_.forEach.call(elements, function (element) {
setTimeout(function () {
var data = element.dataset;
var tengwar, mode, font, encoding, block;
block = element.tagName.toLowerCase() !== "span";
if (data) {
tengwar = data.tengwar;
mode = data.mode;
encoding = data.encoding;
} else {
tengwar = element.getAttribute("data-tengwar");
mode = element.getAttribute("data-mode");
encoding = element.getAttribute("data-encoding");
}
if (encoding) {
element.innerText = TengwarAnnatar.transcribe(encoding, {block: block});
element.classList.add("rendered");
} else if (tengwar) {
font = element.classList.contains("parmaite") ? TengwarParmaite : TengwarAnnatar;
var flags = mode.split(/\s+/);
var mode = flags.shift();
var Mode = modes[mode] || GeneralUse;
var options = Mode.makeOptions();
flags.forEach(function (flag) {
flag = flag.replace(/\-(\w)/g, function ($, $1) {
return $1.toUpperCase();
});
options[flag] = true;
});
options.block = block;
options.font = font;
element.innerHTML = Mode.transcribe(tengwar, options);
element.classList.add("rendered");
}
}, 0);
});
}