How Do I … ? / Add file loading images |
Add a file loading image that displays in the center of the page when file loading is in progress in your Genero Browser Client (GBC) applications.
"use strict"; modulum('MyApplicationHostMenuRuntimeWidget', ['WidgetBase', 'WidgetFactory'], /** * @param {gbc} context * @param {classes} cls */ function(context, cls) { /** * @class classes.MyApplicationHostMenuRuntimeWidget * @extends classes.WidgetBase */ cls.MyApplicationHostMenuRuntimeWidget = context.oo.Class(cls.WidgetBase, function($super) { /** @lends classes.MyApplicationHostMenuRuntimeWidget.prototype */ return { __name: "MyApplicationHostMenuRuntimeWidget", _waitingTime: 100, _timer: null, _initElement: function() { $super._initElement.call(this); this._waitingTime = 1000*parseFloat(gbc.constants.theme["gbc-loader-threshold"]); }, setIdle: function() { if(this._timer){ window.clearTimeout(this._timer); this._timer = null; } this.removeClass("processing"); }, setProcessing: function() { if(this._timer){ window.clearTimeout(this._timer); this._timer = null; } this._timer = window.setTimeout(function(){ this.addClass("processing"); }.bind(this),this._waitingTime); } }; }); cls.WidgetFactory.register('ApplicationHostMenuRuntime', cls.MyApplicationHostMenuRuntimeWidget); });
"use strict"; modulum('MyApplicationHostMenuWidget', ['ApplicationHostMenuWidget', 'WidgetFactory'], /** * @param {gbc} context * @param {classes} cls */ function(context, cls) { /** * @class classes.MyApplicationHostMenuWidget * @extends classes.ApplicationHostMenuWidget */ cls.MyApplicationHostMenuWidget = context.oo.Class(cls.ApplicationHostMenuWidget, function($super) { /** @lends classes.MyApplicationHostMenuWidget.prototype */ return { __name: "MyApplicationHostMenuWidget", __templateName: "ApplicationHostMenuWidget", _initElement:function(){ $super._initElement.call(this); this._element.addClass("gbc_ApplicationHostMenuWidget"); }, _createMenuItems: function() { this._uploadStatus = cls.WidgetFactory.create('ApplicationHostUploadsMenu'); this.addChildWidget(this._uploadStatus); this._runtimeStatus = cls.WidgetFactory.create('ApplicationHostMenuRuntime'); document.body.appendChild(this._runtimeStatus._element); this._aboutMenu = cls.WidgetFactory.create('ApplicationHostAboutMenu'); this.addChildWidget(this._aboutMenu); this._settingsMenu = cls.WidgetFactory.create('ApplicationHostSettingsMenu'); this.addChildWidget(this._settingsMenu); //debug this._proxyLogMenu = cls.WidgetFactory.create('ApplicationHostMenuProxyLog'); this.addChildWidget(this._proxyLogMenu); this._vmLogMenu = cls.WidgetFactory.create('ApplicationHostMenuVmLog'); this.addChildWidget(this._vmLogMenu); this._runInGwcMenu = cls.WidgetFactory.create('ApplicationHostMenuRunInGwc'); this.addChildWidget(this._runInGwcMenu); this._runInGdcMenu = cls.WidgetFactory.create('ApplicationHostMenuRunInGdc'); this.addChildWidget(this._runInGdcMenu); this._debugMenu = cls.WidgetFactory.create('ApplicationHostDebugMenu'); this.addChildWidget(this._debugMenu); }, _destroyMenuItems: function(){ this._runtimeStatus.getElement().remove(); $super._destroyMenuItems.call(this); } }; }); cls.WidgetFactory.register('ApplicationHostMenu', cls.MyApplicationHostMenuWidget); });
In the _createMenuItems function the runtimeStatus element (shown highlighted) is appended to the document body element.
.gbc_MyApplicationHostMenuRuntimeWidget.processing { opacity: 0; position: fixed; z-index: 9999; top: 40%; left: 50%; & > *:hover { cursor: default; } &.processing { //animation: pulse 200ms infinite; opacity: 1; } $base-line-height: 100px; $white: rgb(158,158,158); $off-white: rgba($white, 0.2); $spin-duration: 1s; $pulse-duration: 750ms; @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .loading { border-radius: 50%; width: $base-line-height; height: $base-line-height; border: .5rem solid $off-white; border-top-color: $white; animation: spin $spin-duration infinite linear; &--double { border-style: double; border-width: .5rem; } } }
This style example defines the animation icon and its behavior:
<div> <div class="loading" title="1"> </div> </div>The div class attribute references the loading style you created in the MyApplicationHostMenuRuntimeWidget.scss file.
{ "gbc-loader-threshold": "0.5s" }The value (0.5s) specifies a delay (in seconds) for the timer function loading the icon.
@import "MyApplicationHostMenuRuntimeWidget";In this example we import the MyApplicationHostMenuRuntimeWidget style.
Figure 1. Icon centered in the browser window