Skip to content

Commit a3355fc

Browse files
krisahilmariohernandez
krisahil
authored and
mariohernandez
committed
Show loading indicator when JSON Editor is loading
1 parent b1b3c0f commit a3355fc

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

css/patternkit.css

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Miscellaneous styles for Patternkit interfaces.
3+
*/
4+
5+
/*
6+
* Implements spinning loader to display while
7+
* JSON Editor's schemas are being loaded.
8+
*/
9+
.js-patternkit-loading__on {
10+
border: 4px solid #ebebeb; /* Light grey */
11+
border-top: 4px solid #0066cc; /* Blue */
12+
border-radius: 50%;
13+
width: 30px;
14+
height: 30px;
15+
margin: 40px auto;
16+
animation: spin 1s linear infinite;
17+
}
18+
19+
@keyframes spin {
20+
0% { transform: rotate(0deg); }
21+
100% { transform: rotate(360deg); }
22+
}

js/patternkit.jsoneditor.es6.js

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ patternkitEditorArray(jQuery, Drupal, JSONEditor);
5353
};
5454
let $target = $('#patternkit-editor-target', context);
5555
$target.once('patternkit-editor').each(function () {
56+
var loadingIndicatorClass = 'js-patternkit-loading__on';
57+
58+
$target.before(`<div class="${loadingIndicatorClass}"></div>`);
5659

5760
let theme_js = settings.patternkitEditor.themeJS;
5861
if (typeof theme_js === 'string') {
@@ -186,6 +189,8 @@ patternkitEditorArray(jQuery, Drupal, JSONEditor);
186189
if (window.M) {
187190
window.M.updateTextFields();
188191
}
192+
193+
$('.' + loadingIndicatorClass).removeClass(loadingIndicatorClass);
189194
});
190195
window.patternkitEditor.on('change', saveSchema);
191196
// Drupal triggers Ajax submit via input events.

js/patternkit.jsoneditor.js

+4
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
10631063

10641064
var $target = $('#patternkit-editor-target', context);
10651065
$target.once('patternkit-editor').each(function () {
1066+
var loadingIndicatorClass = 'js-patternkit-loading__on';
1067+
$target.before("<div class=\"".concat(loadingIndicatorClass, "\"></div>"));
10661068
var theme_js = settings.patternkitEditor.themeJS;
10671069

10681070
if (typeof theme_js === 'string') {
@@ -1216,6 +1218,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
12161218
if (window.M) {
12171219
window.M.updateTextFields();
12181220
}
1221+
1222+
$('.' + loadingIndicatorClass).removeClass(loadingIndicatorClass);
12191223
});
12201224
window.patternkitEditor.on('change', saveSchema); // Drupal triggers Ajax submit via input events.
12211225
// This is before allowing other events, so we need to add a pre-hook

patternkit.libraries.yml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jsoneditor.dev:
1616

1717
patternkit.jsoneditor:
1818
version: VERSION
19+
css:
20+
theme:
21+
css/patternkit.css: {}
1922
js:
2023
js/patternkit.jsoneditor.js: {}
2124
dependencies:

0 commit comments

Comments
 (0)