Skip to content

Commit 75e941f

Browse files
committed
improve add external lib modal ux
1 parent c232a16 commit 75e941f

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

src/index.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,12 @@
249249
</svg>
250250
</a>
251251
<h1>Add Library</h1>
252-
<h3>JavaScript</h3>
253-
<p style="font-size: 0.8em;opacity: 0.7;">Note: You can load external scripts from following domains: localhost, https://ajax.googleapis.com, https://code.jquery.com, https://cdnjs.cloudflare.com, https://unpkg.com, https://maxcdn.com, https://cdn77.com, https://maxcdn.bootstrapcdn.com, https://cdn.jsdelivr.net/, https://rawgit.com, https://wzrd.in</p>
254-
<textarea id="js-external-js" class="full-width" id="" cols="30" rows="5" placeholder="Start typing name of a library. Put each library in new line"></textarea>
255252

256-
<h3>CSS</h3>
257-
<textarea id="js-external-css" class="full-width" id="" cols="30" rows="5" placeholder="Start typing name of a library. Put each library in new line"></textarea>
258-
259-
<div style="margin-top:20px;">
253+
<input type="text" id="externalLibrarySearchInput" class="full-width" placeholder="Type here to search libraries">
254+
<div class="tar opacity--70">
255+
<small>Powered by cdnjs</small>
256+
</div>
257+
<div style="margin:20px 0;">
260258
Choose from popular libraries:
261259
<select name="" id="js-add-library-select">
262260
<option value="">-------</option>
@@ -268,6 +266,14 @@ <h3>CSS</h3>
268266
</optgroup>
269267
</select>
270268
</div>
269+
270+
<h3>JavaScript</h3>
271+
<p style="font-size: 0.8em;" class="opacity--70">Note: You can load external scripts from following domains: localhost, https://ajax.googleapis.com, https://code.jquery.com, https://cdnjs.cloudflare.com, https://unpkg.com, https://maxcdn.com, https://cdn77.com, https://maxcdn.bootstrapcdn.com, https://cdn.jsdelivr.net/, https://rawgit.com, https://wzrd.in</p>
272+
<textarea id="js-external-js" class="full-width" id="" cols="30" rows="5" placeholder="Start typing name of a library. Put each library in new line"></textarea>
273+
274+
<h3>CSS</h3>
275+
<textarea id="js-external-css" class="full-width" id="" cols="30" rows="5" placeholder="Start typing name of a library. Put each library in new line"></textarea>
276+
271277
</div>
272278
</div>
273279

src/script.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ onboardModal, settingsModal, notificationsBtn, onboardShowInTabOptionBtn, editor
77
onboardDontShowInTabOptionBtn, TextareaAutoComplete, savedItemCountEl, indentationSizeValueEl,
88
runBtn, searchInput, consoleEl, consoleLogEl, logCountEl, fontStyleTag, fontStyleTemplate,
99
customEditorFontInput, cssSettingsModal, cssSettingsBtn, acssSettingsTextarea,
10-
globalConsoleContainerEl
10+
globalConsoleContainerEl, externalLibrarySearchInput
1111
*/
1212
/* eslint-disable no-extra-semi */
1313
(function(alertsService) {
@@ -2249,12 +2249,21 @@ globalConsoleContainerEl
22492249
externalJsTextarea.addEventListener('blur', onExternalLibChange);
22502250
externalCssTextarea.addEventListener('blur', onExternalLibChange);
22512251

2252-
new TextareaAutoComplete(externalJsTextarea, obj =>
2253-
obj.latest.match(/\.js$/)
2254-
);
2255-
new TextareaAutoComplete(externalCssTextarea, obj =>
2256-
obj.latest.match(/\.css$/)
2257-
);
2252+
new TextareaAutoComplete(externalJsTextarea, {
2253+
filter: obj => obj.latest.match(/\.js$/)
2254+
});
2255+
new TextareaAutoComplete(externalCssTextarea, {
2256+
filter: obj => obj.latest.match(/\.css$/)
2257+
});
2258+
new TextareaAutoComplete(externalLibrarySearchInput, {
2259+
selectedCallback: value => {
2260+
const textarea = value.match(/\.js$/)
2261+
? externalJsTextarea
2262+
: externalCssTextarea;
2263+
textarea.value = `${textarea.value}\n${value}`;
2264+
externalLibrarySearchInput.value = '';
2265+
}
2266+
});
22582267

22592268
// Console header drag resize logic
22602269
var consoleHeaderDragStartY;

src/style.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ a { text-decoration: none; color: crimson; cursor: pointer; }
2626
.fr { float: right; }
2727
.relative { position: relative; }
2828
.tac { text-align: center; }
29+
.tar { text-align: right; }
2930
.va-m { vertical-align: middle; }
3031
.full-width { width: 100%; }
3132
.opacity--30 { opacity: 0.3; }
33+
.opacity--70 { opacity: 0.7; }
3234
.pointer-none { pointer-events: none; }
3335
.ml-1 { margin-left: 1rem; }
3436
.ml-2 { margin-left: 2rem; }
@@ -858,8 +860,8 @@ transition: 0.25s ease;
858860
}
859861
.autocomplete__loader {
860862
position: absolute;
861-
right: 10px;
862-
bottom: 10px;
863+
right: 3px;
864+
bottom: 1px;
863865
}
864866
@keyframes wobble {
865867
from {

src/textarea-autocomplete.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// textarea-autocomplete.js
22
(function() {
33
class TextareaAutoComplete {
4-
constructor(textarea, filter) {
4+
constructor(textarea, options) {
55
this.t = textarea;
6-
this.filter = filter;
6+
this.filter = options.filter;
7+
this.selectedCallback = options.selectedCallback;
78
var wrap = document.createElement('div');
89
wrap.classList.add('btn-group');
910
textarea.parentElement.insertBefore(wrap, textarea);
@@ -128,16 +129,24 @@
128129
event.preventDefault();
129130
} else if (event.keyCode === 13 && this.isShowingSuggestions) {
130131
selectedItemElement = this.list.querySelector('.selected');
131-
this.replaceCurrentLine(selectedItemElement.dataset.url);
132+
this.selectSuggestion(selectedItemElement.dataset.url);
132133
this.closeSuggestions();
133134
}
134135
}
135136
onListMouseDown(event) {
136137
var target = event.target;
137138
if (target.parentElement.dataset.url) {
138-
this.replaceCurrentLine(target.parentElement.dataset.url);
139-
this.closeSuggestions();
139+
this.selectSuggestion(target.parentElement.dataset.url);
140+
}
141+
}
142+
143+
selectSuggestion(value) {
144+
if (this.selectedCallback) {
145+
this.selectedCallback.call(null, value);
146+
} else {
147+
this.replaceCurrentLine(value);
140148
}
149+
this.closeSuggestions();
141150
}
142151
}
143152

0 commit comments

Comments
 (0)