Skip to content

Commit

Permalink
added canvasready event
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Jan 9, 2018
1 parent c083bde commit a42011e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/iiif-av-component.bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/iiif-av-component.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// iiif-av-component v0.0.7 https://github.com/iiif-commons/iiif-av-component#readme
// iiif-av-component v0.0.8 https://github.com/iiif-commons/iiif-av-component#readme

/// <reference types="base-component" />
declare namespace IIIFComponents {
Expand Down Expand Up @@ -53,6 +53,7 @@ declare namespace IIIFComponents {
isPlaying: boolean;
isStalled: boolean;
logMessage: (message: string) => void;
readyCanvasesCount: number;
stallRequestedBy: any[];
wasPlaying: boolean;
constructor(canvas: Manifesto.ICanvas);
Expand Down
12 changes: 10 additions & 2 deletions dist/iiif-av-component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// iiif-av-component v0.0.7 https://github.com/iiif-commons/iiif-av-component#readme
// iiif-av-component v0.0.8 https://github.com/iiif-commons/iiif-av-component#readme
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.iiifAvComponent = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
/// <reference types="exjs" />
Expand Down Expand Up @@ -146,7 +146,7 @@ var IIIFComponents;
canvasInstance.setVolume(Number(this.value));
});
var that = this;
canvasInstance.$playerElement[0].addEventListener('loadedmetadata', function () {
canvasInstance.on('canvasready', function () {
canvasInstance.setCurrentTime(0);
if (that.options.data.autoPlay) {
canvasInstance.play();
Expand Down Expand Up @@ -262,6 +262,7 @@ var IIIFComponents;
this.data = null;
this.isPlaying = false;
this.isStalled = false;
this.readyCanvasesCount = 0;
this.stallRequestedBy = []; //todo: type
this.wasPlaying = false;
this.data = canvas;
Expand Down Expand Up @@ -408,6 +409,7 @@ var IIIFComponents;
targetElement.append($mediaElement);
}
if (data.type == 'Video' || data.type == 'Audio') {
var that_2 = this;
var self_1 = data;
$mediaElement.on('loadstart', function () {
//console.log('loadstart');
Expand All @@ -421,6 +423,12 @@ var IIIFComponents;
//console.log('seeking');
//self.checkForStall();
});
$mediaElement.on('loadedmetadata', function () {
that_2.readyCanvasesCount++;
if (that_2.readyCanvasesCount === that_2._mediaElements.length) {
that_2.fire(IIIFComponents.AVComponent.Events.CANVASREADY);
}
});
$mediaElement.attr('preload', 'auto');
$mediaElement.get(0).load(); // todo: type
}
Expand Down
4 changes: 2 additions & 2 deletions dist/iiif-av-component.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ <h3 class="title"></h3>
logMessage(message);
});

avcomponent.on('canvasready', function() {
console.log('canvas ready');
});

treecomponent = new IIIFComponents.TreeComponent({
target: document.querySelector('#tree')
});
Expand All @@ -136,9 +140,9 @@ <h3 class="title"></h3>

$('.canvasNavigationContainer').empty();

for (var i=0; i<canvases.length; i++) {
for (var i = 0; i < canvases.length; i++) {

var canvasLabel = i+1;
var canvasLabel = i + 1;
var canvasNavigationButton = $('<button class="canvasNavigationButton" data-canvas-id="'+ canvases[i].id +'">Canvas '+ canvasLabel +'</button>');

canvasNavigationButton.click(function() {
Expand Down
12 changes: 10 additions & 2 deletions examples/js/iiif-av-component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// iiif-av-component v0.0.7 https://github.com/iiif-commons/iiif-av-component#readme
// iiif-av-component v0.0.8 https://github.com/iiif-commons/iiif-av-component#readme
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.iiifAvComponent = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
/// <reference types="exjs" />
Expand Down Expand Up @@ -146,7 +146,7 @@ var IIIFComponents;
canvasInstance.setVolume(Number(this.value));
});
var that = this;
canvasInstance.$playerElement[0].addEventListener('loadedmetadata', function () {
canvasInstance.on('canvasready', function () {
canvasInstance.setCurrentTime(0);
if (that.options.data.autoPlay) {
canvasInstance.play();
Expand Down Expand Up @@ -262,6 +262,7 @@ var IIIFComponents;
this.data = null;
this.isPlaying = false;
this.isStalled = false;
this.readyCanvasesCount = 0;
this.stallRequestedBy = []; //todo: type
this.wasPlaying = false;
this.data = canvas;
Expand Down Expand Up @@ -408,6 +409,7 @@ var IIIFComponents;
targetElement.append($mediaElement);
}
if (data.type == 'Video' || data.type == 'Audio') {
var that_2 = this;
var self_1 = data;
$mediaElement.on('loadstart', function () {
//console.log('loadstart');
Expand All @@ -421,6 +423,12 @@ var IIIFComponents;
//console.log('seeking');
//self.checkForStall();
});
$mediaElement.on('loadedmetadata', function () {
that_2.readyCanvasesCount++;
if (that_2.readyCanvasesCount === that_2._mediaElements.length) {
that_2.fire(IIIFComponents.AVComponent.Events.CANVASREADY);
}
});
$mediaElement.attr('preload', 'auto');
$mediaElement.get(0).load(); // todo: type
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iiif-av-component",
"version": "0.0.8",
"version": "0.0.9",
"description": "",
"main": "index.js",
"types": "./dist/iiif-av-component.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/AVComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ namespace IIIFComponents {

const that = this;

canvasInstance.$playerElement[0].addEventListener('loadedmetadata', function() {
canvasInstance.on('canvasready', function() {

canvasInstance.setCurrentTime(0);

if (that.options.data.autoPlay) {
Expand Down
16 changes: 16 additions & 0 deletions src/CanvasInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace IIIFComponents {
public isPlaying: boolean = false;
public isStalled: boolean = false;
public logMessage: (message: string) => void;
public readyCanvasesCount: number = 0;
public stallRequestedBy: any[] = []; //todo: type
public wasPlaying: boolean = false;

Expand Down Expand Up @@ -208,20 +209,35 @@ namespace IIIFComponents {
}

if (data.type == 'Video' || data.type == 'Audio') {

const that = this;
const self = data;

$mediaElement.on('loadstart', function() {
//console.log('loadstart');
self.checkForStall();
});

$mediaElement.on('waiting', function() {
//console.log('waiting');
self.checkForStall();
});

$mediaElement.on('seeking', function() {
//console.log('seeking');
//self.checkForStall();
});

$mediaElement.on('loadedmetadata', function() {
that.readyCanvasesCount++;

if (that.readyCanvasesCount === that._mediaElements.length) {
that.fire(AVComponent.Events.CANVASREADY);
}
});

$mediaElement.attr('preload', 'auto');

(<any>$mediaElement.get(0)).load(); // todo: type
}

Expand Down

0 comments on commit a42011e

Please sign in to comment.