Skip to content

Commit 3fd5ba7

Browse files
authored
Merge pull request #2006 from dmarcos/inspectorLoader
Add loading feedback while the inspector library is fetched over the network
2 parents 319aa89 + 5df4bc5 commit 3fd5ba7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

‎src/components/scene/inspector.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var pkg = require('../../../package');
55
var registerComponent = require('../../core/component').registerComponent;
66

77
var INSPECTOR_URL = pkg.homepage + 'releases/' + pkg.version + '/aframe-inspector.min.js';
8+
var LOADING_MESSAGE = 'Loading Inspector';
89

910
module.exports.Component = registerComponent('inspector', {
1011
schema: {
@@ -14,10 +15,18 @@ module.exports.Component = registerComponent('inspector', {
1415
init: function () {
1516
this.onKeydown = bind(this.onKeydown, this);
1617
this.onMessage = bind(this.onMessage, this);
18+
this.initOverlay();
1719
window.addEventListener('keydown', this.onKeydown);
1820
window.addEventListener('message', this.onMessage);
1921
},
2022

23+
initOverlay: function () {
24+
var dotsHTML = '<span class="dots"><span>.</span><span>.</span><span>.</span></span>';
25+
this.loadingMessageEl = document.createElement('div');
26+
this.loadingMessageEl.classList.add('a-inspector-loader');
27+
this.loadingMessageEl.innerHTML = LOADING_MESSAGE + dotsHTML;
28+
},
29+
2130
remove: function () {
2231
this.removeEventListeners();
2332
},
@@ -31,6 +40,14 @@ module.exports.Component = registerComponent('inspector', {
3140
this.injectInspector();
3241
},
3342

43+
showLoader: function () {
44+
document.body.appendChild(this.loadingMessageEl);
45+
},
46+
47+
hideLoader: function () {
48+
this.el.removeChild(this.loadingMessageEl);
49+
},
50+
3451
/**
3552
* postMessage. aframe.io uses this to create a button on examples to open Inspector.
3653
*/
@@ -44,13 +61,16 @@ module.exports.Component = registerComponent('inspector', {
4461

4562
if (AFRAME.INSPECTOR || AFRAME.inspectorInjected) { return; }
4663

64+
this.showLoader();
65+
4766
// Inject.
4867
script = document.createElement('script');
4968
script.src = this.data.url;
5069
script.setAttribute('data-name', 'aframe-inspector');
5170
script.setAttribute(AFRAME_INJECTED, '');
5271
script.onload = function () {
5372
AFRAME.INSPECTOR.open();
73+
self.hideLoader();
5474
self.removeEventListeners();
5575
};
5676
document.head.appendChild(script);

‎src/style/aframe.css‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,44 @@
5858
position: fixed !important;
5959
}
6060

61+
.a-inspector-loader {
62+
background-color: #ed3160;
63+
position: fixed;
64+
left: 3px;
65+
top: 3px;
66+
padding: 6px 10px;
67+
color: #fff;
68+
text-decoration: none;
69+
font-size: 12px;
70+
font-family: Roboto,sans-serif;
71+
text-align: center;
72+
z-index: 99999;
73+
width: 174px;
74+
}
75+
76+
/* Inspector loader animation */
77+
@keyframes dots-1 { from { opacity: 0; } 25% { opacity: 1; } }
78+
@keyframes dots-2 { from { opacity: 0; } 50% { opacity: 1; } }
79+
@keyframes dots-3 { from { opacity: 0; } 75% { opacity: 1; } }
80+
@-webkit-keyframes dots-1 { from { opacity: 0; } 25% { opacity: 1; } }
81+
@-webkit-keyframes dots-2 { from { opacity: 0; } 50% { opacity: 1; } }
82+
@-webkit-keyframes dots-3 { from { opacity: 0; } 75% { opacity: 1; } }
83+
84+
.a-inspector-loader .dots span {
85+
animation: dots-1 2s infinite steps(1);
86+
-webkit-animation: dots-1 2s infinite steps(1);
87+
}
88+
89+
.a-inspector-loader .dots span:first-child + span {
90+
animation-name: dots-2;
91+
-webkit-animation-name: dots-2;
92+
}
93+
94+
.a-inspector-loader .dots span:first-child + span + span {
95+
animation-name: dots-3;
96+
-webkit-animation-name: dots-3;
97+
}
98+
6199
a-scene {
62100
display: block;
63101
position: relative;

0 commit comments

Comments
 (0)