Skip to content

Commit ebe8b77

Browse files
authored
Merge pull request #108 from WebCoder49/allow-lazy-loading
Allow lazy loading; Clean up code-input loading appearance
2 parents 80db646 + 6fd32b8 commit ebe8b77

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

code-input.css

+22-15
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,16 @@ code-input {
3030

3131

3232
code-input:not(.code-input_loaded) {
33-
margin: 0px!important;
34-
margin-bottom: calc(-1 * var(--padding, 16px))!important;
3533
padding: var(--padding, 16px)!important;
36-
border: 0;
3734
}
3835

3936
code-input textarea, code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_pre-element-styled pre {
4037
/* Both elements need the same text and space styling so they are directly on top of each other */
4138
margin: 0px!important;
4239
padding: var(--padding, 16px)!important;
4340
border: 0;
44-
min-width: 100%;
45-
min-height: 100%;
46-
box-sizing: border-box; /* Don't need to worry about padding to calculate width! */
41+
min-width: calc(100% - var(--padding) * 2);
42+
min-height: calc(100% - var(--padding) * 2);
4743
overflow: hidden;
4844
resize: none;
4945
grid-row: 1;
@@ -87,13 +83,6 @@ code-input pre {
8783
z-index: 0;
8884
}
8985

90-
code-input:not(.code-input_loaded) pre, code-input:not(.code-input_loaded) textarea {
91-
opacity: 0;
92-
}
93-
code-input:not(.code-input_loaded)::before {
94-
color: #ccc;
95-
}
96-
9786
/* Make textarea almost completely transparent, except for caret and placeholder */
9887

9988
code-input textarea {
@@ -119,11 +108,29 @@ code-input textarea {
119108
outline: none!important;
120109
}
121110

122-
code-input:not(.code-input_registered)::before {
111+
/* Before registering give a hint about how to register. */
112+
code-input:not(.code-input_registered) {
113+
overflow: hidden;
114+
display: block;
115+
box-sizing: border-box; /* Include padding in width/height */
116+
}
117+
118+
code-input:not(.code-input_registered)::after {
123119
/* Display message to register */
124120
content: "Use codeInput.registerTemplate to set up.";
125121
display: block;
126-
color: grey;
122+
position: absolute;
123+
bottom: var(--padding);
124+
left: var(--padding);
125+
width: calc(100% - 2 * var(--padding));
126+
127+
border-top: 1px solid grey;
128+
outline: var(--padding) solid white;
129+
background-color: white;
130+
}
131+
132+
code-input:not(.code-input_loaded) pre, code-input:not(.code-input_loaded) textarea {
133+
opacity: 0;
127134
}
128135

129136
/* Contains dialog boxes that might appear as the result of a plugin.

code-input.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,13 @@ var codeInput = {
521521

522522
this.syncSize();
523523

524-
// Scroll to the caret by focusing, though this shouldn't count as a focus event
525-
this.passEventsToTextarea = false;
526-
this.textareaElement.blur();
527-
this.textareaElement.focus();
528-
this.passEventsToTextarea = true;
524+
// If editing here, scroll to the caret by focusing, though this shouldn't count as a focus event
525+
if(this.textareaElement === document.activeElement) {
526+
this.passEventsToTextarea = false;
527+
this.textareaElement.blur();
528+
this.textareaElement.focus();
529+
this.passEventsToTextarea = true;
530+
}
529531

530532
this.pluginEvt("afterHighlight");
531533
}
@@ -990,16 +992,12 @@ var codeInput = {
990992
* has loaded (or now if it has already loaded)
991993
*/
992994
runOnceWindowLoaded(callback, codeInputElem) {
993-
if(codeInput.windowLoaded) {
995+
if(document.readyState == "complete") {
994996
callback(); // Fully loaded
995997
} else {
996998
window.addEventListener("load", callback);
997999
}
998-
},
999-
windowLoaded: false
1000+
}
10001001
}
1001-
window.addEventListener("load", function() {
1002-
codeInput.windowLoaded = true;
1003-
});
10041002

10051003
customElements.define("code-input", codeInput.CodeInput);

tests/prism.html

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ <h4><a href="hljs.html">Test for highlight.js</a></h4>
4848
// A third line with &lt;html> tags</code-input>
4949
<input type="submit" value="Search Google For Code"/>
5050
</form>
51+
5152
<script>
5253
beginTest(false);
5354
</script>

0 commit comments

Comments
 (0)