From 3f3008f180d6530901a96810d31030c02871fe11 Mon Sep 17 00:00:00 2001 From: edsilv Date: Thu, 13 Sep 2018 11:37:13 +0100 Subject: [PATCH] added public reset method --- dist/iiif-av-component.bundle.js | 4 ++-- dist/iiif-av-component.d.ts | 3 ++- dist/iiif-av-component.js | 5 ++++- dist/iiif-av-component.min.js | 6 +++--- examples/js/iiif-av-component.js | 5 ++++- package.json | 2 +- src/AVComponent.ts | 4 ++++ 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dist/iiif-av-component.bundle.js b/dist/iiif-av-component.bundle.js index 9acbf79..434a99d 100644 --- a/dist/iiif-av-component.bundle.js +++ b/dist/iiif-av-component.bundle.js @@ -60,5 +60,5 @@ var _Components; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}]},{},[1])(1) }); -!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{var g;g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,g.iiifAvComponent=f()}}(function(){return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i0&&(this._data.canvasId=this.canvasInstances[0].getCanvasId()),this._checkAllMediaReadyInterval=setInterval(this._checkAllMediaReady.bind(this),100),this._checkAllWaveformsReadyInterval=setInterval(this._checkAllWaveformsReady.bind(this),100),this._$posterContainer=$('
'),this._$element.append(this._$posterContainer),this._$posterImage=$('
'),this._$posterExpandButton=$('\n \n "),this._$posterImage.append(this._$posterExpandButton),this._$posterImage.on("touchstart click",function(e){e.preventDefault();var target=_this._getPosterImageCss(!_this._posterImageExpanded);if(_this._$posterImage.animate(target),_this._posterImageExpanded=!_this._posterImageExpanded,_this._posterImageExpanded){var label=_this.options.data.content.collapse;_this._$posterExpandButton.prop("title",label),_this._$posterExpandButton.find("i").switchClass("expand","collapse")}else{var label=_this.options.data.content.expand;_this._$posterExpandButton.prop("title",label),_this._$posterExpandButton.find("i").switchClass("collapse","expand")}});var posterCanvas=this._data.helper.getPosterCanvas();if(posterCanvas){this._posterCanvasWidth=posterCanvas.getWidth(),this._posterCanvasHeight=posterCanvas.getHeight();var posterImage=this._data.helper.getPosterImage();if(posterImage){this._$posterContainer.append(this._$posterImage);var css=this._getPosterImageCss(this._posterImageExpanded);css=Object.assign({},css,{"background-image":"url("+posterImage+")"}),this._$posterImage.css(css)}}}},AVComponent.prototype._checkAllMediaReady=function(){console.log("loading media"),this._readyMedia===this.canvasInstances.length&&(console.log("all media ready"),clearInterval(this._checkAllMediaReadyInterval),this.fire(AVComponent.Events.MEDIA_READY),this.resize())},AVComponent.prototype._checkAllWaveformsReady=function(){console.log("loading waveforms"),this._readyWaveforms===this._getCanvasInstancesWithWaveforms().length&&(console.log("waveforms ready"),clearInterval(this._checkAllWaveformsReadyInterval),this.fire(AVComponent.Events.WAVEFORMS_READY),this.resize())},AVComponent.prototype._getCanvasInstancesWithWaveforms=function(){return this.canvasInstances.filter(function(c){return c.waveforms.length>0})},AVComponent.prototype._getCanvases=function(){return this._data.helper?this._data.helper.getCanvases():[]},AVComponent.prototype._initCanvas=function(canvas){var _this=this,canvasInstance=new IIIFComponents.CanvasInstance({target:document.createElement("div"),data:Object.assign({},{canvas:canvas},this._data)});canvasInstance.logMessage=this._logMessage.bind(this),this._$element.append(canvasInstance.$playerElement),canvasInstance.init(),this.canvasInstances.push(canvasInstance),canvasInstance.on(AVComponent.Events.MEDIA_READY,function(){_this._readyMedia++},!1),canvasInstance.on(AVComponent.Events.WAVEFORM_READY,function(){_this._readyWaveforms++},!1),canvasInstance.on(IIIFComponents.AVComponentCanvasInstance.Events.PREVIOUS_RANGE,function(){_this._prevRange()},!1),canvasInstance.on(IIIFComponents.AVComponentCanvasInstance.Events.NEXT_RANGE,function(){_this._nextRange()},!1),canvasInstance.on(AVComponent.Events.RANGE_CHANGED,function(rangeId){_this.fire(AVComponent.Events.RANGE_CHANGED,rangeId)},!1),canvasInstance.on(IIIFComponents.AVVolumeControl.Events.VOLUME_CHANGED,function(volume){_this._setCanvasInstanceVolumes(volume),_this.fire(IIIFComponents.AVVolumeControl.Events.VOLUME_CHANGED,volume)},!1)},AVComponent.prototype._prevRange=function(){if(this._data&&this._data.helper){var prevRange=this._data.helper.getPreviousRange();prevRange?this.playRange(prevRange.id):this._rewind()}},AVComponent.prototype._nextRange=function(){if(this._data&&this._data.helper){var nextRange=this._data.helper.getNextRange();nextRange&&this.playRange(nextRange.id)}},AVComponent.prototype._setCanvasInstanceVolumes=function(volume){this.canvasInstances.forEach(function(canvasInstance){canvasInstance.set({volume:volume})})},AVComponent.prototype._getCanvasInstanceById=function(canvasId){if(canvasId=canvasId.includes("://")?Manifesto.Utils.normaliseUrl(canvasId):canvasId,this._data.virtualCanvasEnabled)for(var i=0;ithis._posterCanvasHeight?(ratio=this._posterCanvasHeight/this._posterCanvasWidth,width=containerWidth*this._data.posterImageRatio,height=width*ratio):(ratio=this._posterCanvasWidth/this._posterCanvasHeight,height=containerHeight*this._data.posterImageRatio,width=height*ratio),{top:0,left:containerWidth-width,width:width,height:height}}return null},AVComponent.prototype.resize=function(){this.canvasInstances.forEach(function(canvasInstance){canvasInstance.resize()});var currentCanvas=this._getCurrentCanvas();currentCanvas&&this._$posterImage&&this._$posterImage.is(":visible")&&(this._posterImageExpanded?this._$posterImage.css(this._getPosterImageCss(!0)):this._$posterImage.css(this._getPosterImageCss(!1)))},AVComponent}(_Components.BaseComponent);IIIFComponents.AVComponent=AVComponent}(IIIFComponents||(IIIFComponents={})),function(IIIFComponents){var AVComponent;!function(AVComponent){var Events=function(){function Events(){}return Events.MEDIA_READY="mediaready",Events.LOG="log",Events.RANGE_CHANGED="rangechanged",Events.WAVEFORM_READY="waveformready",Events.WAVEFORMS_READY="waveformsready",Events}();AVComponent.Events=Events}(AVComponent=IIIFComponents.AVComponent||(IIIFComponents.AVComponent={}))}(IIIFComponents||(IIIFComponents={})),function(g){g.IIIFComponents?g.IIIFComponents.AVComponent=IIIFComponents.AVComponent:g.IIIFComponents=IIIFComponents}(global);var IIIFComponents,__extends=this&&this.__extends||function(){var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};return function(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}();!function(IIIFComponents){var AVVolumeControl=function(_super){function AVVolumeControl(options){var _this=_super.call(this,options)||this;return _this._lastVolume=1,_this._data={volume:1},_this._init(),_this._resize(),_this}return __extends(AVVolumeControl,_super),AVVolumeControl.prototype._init=function(){var _this=this,success=_super.prototype._init.call(this);success||console.error("Component failed to initialise"),this._$volumeMute=$('\n "),this._$volumeSlider=$('
'),this._$element.append(this._$volumeMute,this._$volumeSlider);var that=this;return this._$volumeMute.on("touchstart click",function(e){e.preventDefault(),0!==_this._data.volume?(_this._lastVolume=_this._data.volume,_this._data.volume=0):_this._data.volume=_this._lastVolume,_this.fire(AVVolumeControl.Events.VOLUME_CHANGED,_this._data.volume)}),this._$volumeSlider.slider({value:that._data.volume,step:.1,orientation:"horizontal",range:"min",min:0,max:1,animate:!1,create:function(evt,ui){},slide:function(evt,ui){that._data.volume=ui.value,0===that._data.volume&&(that._lastVolume=0),that.fire(AVVolumeControl.Events.VOLUME_CHANGED,that._data.volume)},stop:function(evt,ui){}}),success},AVVolumeControl.prototype.set=function(data){this._data=Object.assign(this._data,data),this._render()},AVVolumeControl.prototype._render=function(){if(void 0!==this._data.volume)if(this._$volumeSlider.slider({value:this._data.volume}),0===this._data.volume){var label=this.options.data.content.unmute;this._$volumeMute.prop("title",label),this._$volumeMute.find("i").switchClass("on","off")}else{var label=this.options.data.content.mute;this._$volumeMute.prop("title",label),this._$volumeMute.find("i").switchClass("off","on")}},AVVolumeControl.prototype._resize=function(){},AVVolumeControl}(_Components.BaseComponent);IIIFComponents.AVVolumeControl=AVVolumeControl}(IIIFComponents||(IIIFComponents={})),function(IIIFComponents){var AVVolumeControl;!function(AVVolumeControl){var Events=function(){function Events(){}return Events.VOLUME_CHANGED="volumechanged",Events}();AVVolumeControl.Events=Events}(AVVolumeControl=IIIFComponents.AVVolumeControl||(IIIFComponents.AVVolumeControl={}))}(IIIFComponents||(IIIFComponents={}));var IIIFComponents,__extends=this&&this.__extends||function(){var extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)b.hasOwnProperty(p)&&(d[p]=b[p])};return function(d,b){function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}();!function(IIIFComponents){var CanvasInstance=function(_super){function CanvasInstance(options){var _this=_super.call(this,options)||this;return _this._canvasClockFrequency=25,_this._canvasClockStartDate=0,_this._canvasClockTime=0,_this._canvasHeight=0,_this._canvasWidth=0,_this._data=_this.data(),_this._highPriorityFrequency=25,_this._isPlaying=!1,_this._isStalled=!1,_this._lowPriorityFrequency=250,_this._mediaSyncMarginSecs=1,_this._rangeSpanPadding=.25,_this._readyMediaCount=0,_this._stallRequestedBy=[],_this._wasPlaying=!1,_this.ranges=[],_this.waveforms=[],_this._scaleY=function(amplitude,height){var range=256;return Math.max(_this._data.waveformBarWidth,amplitude*height/range)},_this._data=_this.options.data,_this.$playerElement=$('
'),_this}return __extends(CanvasInstance,_super),CanvasInstance.prototype.init=function(){var _this=this;if(!this._data||!this._data.content||!this._data.canvas)return void console.warn("unable to initialise, missing canvas or content");this._$hoverPreviewTemplate=$('
'),this._$canvasContainer=$('
'),this._$optionsContainer=$('
'),this._$rangeTimelineContainer=$('
'),this._$canvasTimelineContainer=$('
'),this._$canvasHoverPreview=this._$hoverPreviewTemplate.clone(),this._$canvasHoverHighlight=$('
'),this._$rangeHoverPreview=this._$hoverPreviewTemplate.clone(),this._$rangeHoverHighlight=$('
'),this._$durationHighlight=$('
'),this._$timelineItemContainer=$('
'),this._$controlsContainer=$('
'),this._$prevButton=$('\n "),this._$playButton=$('\n "),this._$nextButton=$('\n "),this._$timeDisplay=$('
/
'),this._$canvasTime=this._$timeDisplay.find(".canvas-time"),this._$canvasDuration=this._$timeDisplay.find(".canvas-duration"),this.isVirtual()&&this.$playerElement.addClass("virtual");var $volume=$('
');if(this._volume=new IIIFComponents.AVVolumeControl({target:$volume[0],data:Object.assign({},this._data)}),this._volume.on(IIIFComponents.AVVolumeControl.Events.VOLUME_CHANGED,function(value){_this.fire(IIIFComponents.AVVolumeControl.Events.VOLUME_CHANGED,value)},!1),this._$controlsContainer.append(this._$prevButton,this._$playButton,this._$nextButton,this._$timeDisplay,$volume),this._$canvasTimelineContainer.append(this._$canvasHoverPreview,this._$canvasHoverHighlight,this._$durationHighlight),this._$rangeTimelineContainer.append(this._$rangeHoverPreview,this._$rangeHoverHighlight),this._$optionsContainer.append(this._$canvasTimelineContainer,this._$rangeTimelineContainer,this._$timelineItemContainer,this._$controlsContainer),this.$playerElement.append(this._$canvasContainer,this._$optionsContainer),this._$canvasHoverPreview.hide(),this._$rangeHoverPreview.hide(),this._data&&this._data.helper&&this._data.canvas){var ranges_1=[];this.isVirtual()?this._data.canvas.canvases.forEach(function(canvas){if(_this._data&&_this._data.helper){var r=_this._data.helper.getCanvasRanges(canvas),clonedRanges_1=[];r.forEach(function(range){var clonedRange=jQuery.extend(!0,{},range);if(clonedRanges_1.push(clonedRange),clonedRange.canvases&&clonedRange.canvases.length)for(var i=0;itotalLength||endfullWidth&&(left=fullWidth-hoverPreviewWidth,arrowLeft=hoverPreviewWidth-(fullWidth-x)-6),$hoverPreview.css({left:left,top:hoverPreviewHeight*-1+"px"}).show(),$hoverArrow.css({left:arrowLeft})},CanvasInstance.prototype._previous=function(isDouble){this._data.limitToRange?isDouble?this._isNavigationConstrainedToRange()?this._rewind():this.fire(IIIFComponents.AVComponentCanvasInstance.Events.PREVIOUS_RANGE):this._rewind():this._data.range?isDouble?(this.set({range:void 0}),this._rewind()):this.fire(IIIFComponents.AVComponentCanvasInstance.Events.PREVIOUS_RANGE):this._rewind()},CanvasInstance.prototype._next=function(){this._data.limitToRange&&this._isNavigationConstrainedToRange()?this._fastforward():this.fire(IIIFComponents.AVComponentCanvasInstance.Events.NEXT_RANGE)},CanvasInstance.prototype.destroy=function(){window.clearInterval(this._highPriorityInterval),window.clearInterval(this._lowPriorityInterval),window.clearInterval(this._canvasClockInterval)},CanvasInstance.prototype._convertToPercentage=function(pixelValue,maxValue){var percentage=pixelValue/maxValue*100;return percentage},CanvasInstance.prototype._renderMediaElement=function(data){var $mediaElement,_this=this,type=data.type.toString().toLowerCase();switch(type){case"image":$mediaElement=$('');break;case"video":$mediaElement=$('