Skip to content

Commit 5e238aa

Browse files
committed
runOnceWindowLoaded isn't needed
1 parent f94a603 commit 5e238aa

File tree

3 files changed

+27
-75
lines changed

3 files changed

+27
-75
lines changed

code-input.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ var codeInput = {
129129
for (let i in codeInput.templateNotYetRegisteredQueue[templateName]) {
130130
const elem = codeInput.templateNotYetRegisteredQueue[templateName][i];
131131
elem.template = template;
132-
codeInput.runOnceWindowLoaded((function(elem) { elem.connectedCallback(); }).bind(null, elem), elem);
132+
elem.connectedCallback();
133133
// Bind sets elem as first parameter of function
134134
// So innerHTML can be read
135135
}
@@ -143,7 +143,7 @@ var codeInput = {
143143
for (let i in codeInput.templateNotYetRegisteredQueue[undefined]) {
144144
const elem = codeInput.templateNotYetRegisteredQueue[undefined][i];
145145
elem.template = template;
146-
codeInput.runOnceWindowLoaded((function(elem) { elem.connectedCallback(); }).bind(null, elem), elem);
146+
elem.connectedCallback();
147147
// Bind sets elem as first parameter of function
148148
// So innerHTML can be read
149149
}
@@ -739,10 +739,8 @@ var codeInput = {
739739
this.template = this.getTemplate();
740740
if (this.template != undefined) {
741741
this.classList.add("code-input_registered");
742-
codeInput.runOnceWindowLoaded(() => {
743-
this.setup();
744-
this.classList.add("code-input_loaded");
745-
}, this);
742+
this.setup();
743+
this.classList.add("code-input_loaded");
746744
}
747745
this.mutationObserver = new MutationObserver(this.mutationObserverCallback.bind(this));
748746
this.mutationObserver.observe(this, {
@@ -1032,18 +1030,6 @@ var codeInput = {
10321030
formResetCallback() {
10331031
this.value = this.initialValue;
10341032
};
1035-
},
1036-
1037-
/**
1038-
* To ensure the DOM is ready, run this callback after the window
1039-
* has loaded (or now if it has already loaded)
1040-
*/
1041-
runOnceWindowLoaded(callback, codeInputElem) {
1042-
if(document.readyState == "complete") {
1043-
callback(); // Fully loaded
1044-
} else {
1045-
window.addEventListener("load", callback);
1046-
}
10471033
}
10481034
}
10491035

tests/i18n.html

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,23 @@
4343
<link rel="stylesheet" href="../plugins/special-chars.css">
4444

4545
<!--Register templates-->
46+
47+
</head>
48+
<body>
49+
<textarea dir="rtl" placeholder="textarea rtl"></textarea>
50+
<textarea dir="ltr" placeholder="textarea ltr"></textarea>
51+
<code-input dir="rtl" template="prism" language="markdown" placeholder="prism rtl"></code-input>
52+
<code-input dir="ltr" template="prism" language="markdown" placeholder="prism ltr"></code-input>
53+
<code-input dir="rtl" template="hljs" language="markdown" placeholder="hljs rtl"></code-input>
54+
<code-input dir="ltr" template="hljs" language="markdown" placeholder="hljs ltr"></code-input>
55+
<code-input dir="rtl" template="prism+" language="markdown" placeholder="prism rtl" class="line-numbers"></code-input>
56+
<code-input dir="ltr" template="prism+" language="markdown" placeholder="prism ltr" class="line-numbers"></code-input>
57+
<code-input dir="rtl" template="hljs+" language="markdown" placeholder="hljs rtl"></code-input>
58+
<code-input dir="ltr" template="hljs+" language="markdown" placeholder="hljs ltr"></code-input>
59+
4660
<script>
47-
codeInput.registerTemplate("hljs", codeInput.templates.hljs(hljs, [
48-
/*new codeInput.plugins.AutoCloseBrackets(),
49-
new codeInput.plugins.Autocomplete(function(popupElem, textarea, selectionEnd) {
50-
if(textarea.value.substring(selectionEnd-5, selectionEnd) == "popup") {
51-
// Show popup
52-
popupElem.style.display = "block";
53-
popupElem.innerHTML = "Here's your popup!";
54-
} else {
55-
popupElem.style.display = "none";
56-
}
57-
}),
58-
new codeInput.plugins.Autodetect(),
59-
new codeInput.plugins.FindAndReplace(),
60-
new codeInput.plugins.GoToLine(),
61-
new codeInput.plugins.Indent(true, 2),
62-
new codeInput.plugins.SelectTokenCallbacks(codeInput.plugins.SelectTokenCallbacks.TokenSelectorCallbacks.createClassSynchronisation("in-selection"), false, true, true, true, true, false),
63-
new codeInput.plugins.SpecialChars(true),*/
64-
]));
65-
codeInput.registerTemplate("prism", codeInput.templates.prism(Prism, [
66-
/*new codeInput.plugins.AutoCloseBrackets(),
67-
new codeInput.plugins.Autocomplete(function(popupElem, textarea, selectionEnd) {
68-
if(textarea.value.substring(selectionEnd-5, selectionEnd) == "popup") {
69-
// Show popup
70-
popupElem.style.display = "block";
71-
popupElem.innerHTML = "Here's your popup!";
72-
} else {
73-
popupElem.style.display = "none";
74-
}
75-
}),
76-
new codeInput.plugins.FindAndReplace(),
77-
new codeInput.plugins.GoToLine(),
78-
new codeInput.plugins.Indent(true, 2),
79-
new codeInput.plugins.SelectTokenCallbacks(new codeInput.plugins.SelectTokenCallbacks.TokenSelectorCallbacks(selectBrace, deselectAllBraces), true),
80-
new codeInput.plugins.SpecialChars(true),*/
81-
]));
61+
codeInput.registerTemplate("hljs", codeInput.templates.hljs(hljs, []));
62+
codeInput.registerTemplate("prism", codeInput.templates.prism(Prism, []));
8263

8364
// Attribution: Translated by Oliver Geer with some help from English Wiktionary
8465
let findAndReplaceTranslations = {
@@ -146,18 +127,6 @@
146127
//new codeInput.plugins.SpecialChars(true),
147128
]));
148129
</script>
149-
</head>
150-
<body>
151-
<textarea dir="rtl" placeholder="textarea rtl"></textarea>
152-
<textarea dir="ltr" placeholder="textarea ltr"></textarea>
153-
<code-input dir="rtl" template="prism" language="markdown" placeholder="prism rtl"></code-input>
154-
<code-input dir="ltr" template="prism" language="markdown" placeholder="prism ltr"></code-input>
155-
<code-input dir="rtl" template="hljs" language="markdown" placeholder="hljs rtl"></code-input>
156-
<code-input dir="ltr" template="hljs" language="markdown" placeholder="hljs ltr"></code-input>
157-
<code-input dir="rtl" template="prism+" language="markdown" placeholder="prism rtl" class="line-numbers"></code-input>
158-
<code-input dir="ltr" template="prism+" language="markdown" placeholder="prism ltr" class="line-numbers"></code-input>
159-
<code-input dir="rtl" template="hljs+" language="markdown" placeholder="hljs rtl"></code-input>
160-
<code-input dir="ltr" template="hljs+" language="markdown" placeholder="hljs ltr"></code-input>
161130

162131
<script>
163132
rtl = `# ערך מומלץ ערך מומלץ
@@ -183,15 +152,12 @@
183152
CC-BY-SA hi.wikipedia.org: **ग्लेशियर नेशनल पार्क** अमेरिकी राष्ट्रीय उद्यान है, जो कि कनाडा-संयुक्त राज्य अमेरिका की सीमा पर स्थित है। उद्यान संयुक्त राज्य के उत्तर-पश्चिमी मोंटाना राज्य
184153
185154
में स्थित है और कनाडा की ओर अल्बर्टा और ब्रिटिश कोलम्बिया प्रांतों से सटा हुआ है। उद्यान दस लाख एकड़ RTL: ערך מומלץ ערך מומלץ (4,000 किमी2) से अधिक क्षेत्र में फैला हुआ है और इसमें दो पर्वत श्रृंखला (रॉकी पर्वत की उप-श्रेणियाँ), 130 से अधिक नामित झीलें...`;
186-
window.addEventListener("load", function() {
187-
188-
const elems = document.querySelectorAll("body > code-input, body > textarea");
189-
for(let i = 0; i < elems.length; i++) {
190-
let dir = elems[i].getAttribute("dir");
191-
if(dir == "rtl") elems[i].value = rtl;
192-
else elems[i].value = ltr;
193-
}
194-
});
155+
const elems = document.querySelectorAll("body > code-input, body > textarea");
156+
for(let i = 0; i < elems.length; i++) {
157+
let dir = elems[i].getAttribute("dir");
158+
if(dir == "rtl") elems[i].value = rtl;
159+
else elems[i].value = ltr;
160+
}
195161
</script>
196162
</body>
197163
</html>

tests/tester.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,4 @@ console.log("I've got another line!", 2 &lt; 3, "should be true.");
590590
document.querySelector("h2").style.backgroundColor = "lightgreen";
591591
document.querySelector("h2").textContent = "All Tests have Passed.";
592592
}
593-
}
593+
}

0 commit comments

Comments
 (0)