-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_dom-updaters.js
50 lines (42 loc) · 1.5 KB
/
_dom-updaters.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
define(["_dom-readers", "_dom-writers", "_tag-builders", "_expression"], function(readers, writers, builders, Expression){
var domUpdaterFunctions = {
insertHint: insertHint,
insertWritingHint: insertWritingHint,
replaceWithLength: replaceWithLength,
replaceRomanWord: replaceRomanWord,
};
return domUpdaterFunctions;
function insertHint(expressionText, fullTextId){
var hintId = "hint";
var expression = Expression({ text: expressionText });
replaceClozedWLength(expression);
buildAndInsertHint(expression, fullTextId, hintId);
}
function insertWritingHint(expressionText, fullTextId){
var hintId = "writing-hint";
var expression = Expression({ text: expressionText });
buildAndInsertHint(expression, fullTextId, hintId);
}
function buildAndInsertHint(expr, fullTextId, hintId){
var pHintTag = builders.buildWriterSection(hintId);
writers.appendTags(fullTextId, [pHintTag], "afterEnd");
var wordSet = {
words: [expr.text],
writerId: hintId,
};
writers.writeDfnTags(wordSet);
}
function replaceClozedWLength(expr) {
[].forEach.call(
readers.readClozeSpans(),
function(span){ replaceWithLength(span, expr); }
);
}
function replaceWithLength(element, expression){
element.innerHTML = expression.dottify();
}
function replaceRomanWord(word, element){
var wordRegex = new RegExp(word, "gi");
element.innerHTML = element.innerHTML.replace(wordRegex, "<span class='cloze'>*</span>")
}
});