Added Spinner class
This commit is contained in:
parent
80745bc81d
commit
75d3ed9a43
3 changed files with 49 additions and 3 deletions
|
@ -1,11 +1,13 @@
|
|||
/* global Flash */
|
||||
|
||||
import Spinner from '../../spinner';
|
||||
import sqljs from 'sql.js';
|
||||
|
||||
class BalsamiqViewer {
|
||||
constructor(viewer) {
|
||||
this.viewer = viewer;
|
||||
this.endpoint = this.viewer.dataset.endpoint;
|
||||
this.spinner = new Spinner(this.viewer);
|
||||
}
|
||||
|
||||
loadFile() {
|
||||
|
@ -17,10 +19,14 @@ class BalsamiqViewer {
|
|||
xhr.onload = this.renderFile.bind(this);
|
||||
xhr.onerror = BalsamiqViewer.onError;
|
||||
|
||||
this.spinner.start();
|
||||
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
renderFile(loadEvent) {
|
||||
this.spinner.stop();
|
||||
|
||||
const container = document.createElement('ul');
|
||||
|
||||
this.initDatabase(loadEvent.target.response);
|
||||
|
@ -29,7 +35,7 @@ class BalsamiqViewer {
|
|||
const renderedPreviews = previews.map(preview => this.renderPreview(preview, container));
|
||||
|
||||
container.innerHTML = renderedPreviews.join('');
|
||||
container.classList.add('list-inline');
|
||||
container.classList.add('list-inline', 'previews');
|
||||
|
||||
this.viewer.appendChild(container);
|
||||
}
|
||||
|
@ -41,14 +47,15 @@ class BalsamiqViewer {
|
|||
}
|
||||
|
||||
getPreviews() {
|
||||
const thumnails = this.database.exec('SELECT * FROM thumbnails');
|
||||
const thumbnails = this.database.exec('SELECT * FROM thumbnails');
|
||||
|
||||
return thumnails[0].values.map(BalsamiqViewer.parsePreview);
|
||||
return thumbnails[0].values.map(BalsamiqViewer.parsePreview);
|
||||
}
|
||||
|
||||
renderPreview(preview) {
|
||||
const previewElement = document.createElement('li');
|
||||
|
||||
previewElement.classList.add('preview');
|
||||
previewElement.innerHTML = this.renderTemplate(preview);
|
||||
|
||||
return previewElement.outerHTML;
|
||||
|
|
28
app/assets/javascripts/spinner.js
Normal file
28
app/assets/javascripts/spinner.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
class Spinner {
|
||||
constructor(renderable) {
|
||||
this.renderable = renderable;
|
||||
|
||||
this.container = Spinner.createContainer();
|
||||
}
|
||||
|
||||
start() {
|
||||
this.renderable.prepend(this.container);
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.container.remove();
|
||||
}
|
||||
|
||||
static createContainer() {
|
||||
const container = document.createElement('div');
|
||||
container.classList.add('loading');
|
||||
|
||||
container.innerHTML = Spinner.TEMPLATE;
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
Spinner.TEMPLATE = '<i class="fa fa-spinner fa-spin"></i>';
|
||||
|
||||
export default Spinner;
|
|
@ -168,6 +168,17 @@
|
|||
&.code {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.list-inline.previews {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
padding: $gl-padding;
|
||||
|
||||
.preview {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue