show the load indicator when beginning to preload

This commit is contained in:
Bala Clark 2015-07-15 09:47:28 +02:00
parent a422c90982
commit 7772805c25
6 changed files with 33 additions and 14 deletions

View file

@ -13,6 +13,12 @@ module.exports = class ComicBook extends EventEmitter {
this.pages = new Map()
this.loadIndicator = new LoadIndicator()
this.addEventListeners()
}
addEventListeners () {
this.on('preload:start', this.loadIndicator.show.bind(this.loadIndicator))
}
preload () {

13
dist/comicbook.js vendored
View file

@ -3,7 +3,7 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
@ -15,7 +15,9 @@ var LoadIndicator = require('./view/load-indicator');
module.exports = (function (_EventEmitter) {
_inherits(ComicBook, _EventEmitter);
function ComicBook(srcs) {
function ComicBook() {
var srcs = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
_classCallCheck(this, ComicBook);
_get(Object.getPrototypeOf(ComicBook.prototype), 'constructor', this).call(this);
@ -27,9 +29,16 @@ module.exports = (function (_EventEmitter) {
this.pages = new Map();
this.loadIndicator = new LoadIndicator();
this.addEventListeners();
}
_createClass(ComicBook, [{
key: 'addEventListeners',
value: function addEventListeners() {
this.on('preload:start', this.loadIndicator.show.bind(this.loadIndicator));
}
}, {
key: 'preload',
value: function preload() {
this.emit('preload:start');

File diff suppressed because one or more lines are too long

10
dist/comicbook.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -33,10 +33,7 @@ describe('ComicBook', function () {
it('should emit a preload:start event', function (done) {
let comic = new ComicBook(srcs)
comic.on('preload:start', function () {
assert(true, 'start event should have been emitted')
done()
})
comic.on('preload:start', () => done())
comic.preload()
})
@ -44,5 +41,12 @@ describe('ComicBook', function () {
it('should emit a preload:ready event')
it('preload:ready should make sure that double page mode can show two images')
it('should show the load indicator on preload:start', function (done) {
let comic = new ComicBook(srcs)
assert.equal(comic.loadIndicator.el.style.display, 'none')
comic.loadIndicator.on('show', () => done())
comic.preload()
})
})
})