From: Stephen Cameron Date: Tue, 30 May 2017 16:52:13 +0000 (+0200) Subject: WIP #897 @7 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e45e68efb4ac2c42abb2510a5d663138732a46d8;p=fluidbook-html5.git WIP #897 @7 --- diff --git a/_index.html b/_index.html index ba0555e0..9a3dff1c 100644 --- a/_index.html +++ b/_index.html @@ -8,7 +8,7 @@ + content="default-src * gap://ready file:; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.youtube.com *.ytimg.com; img-src * data:"> diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 76188f01..dbe857e4 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -184,6 +184,9 @@ Fluidbook.prototype = { $("#pages ." + position).hide(); }, initVideos: function () { + + console.info('fluidbook.initVideos called'); + var $this = this; $(".videoContainer").each(function () { $this.video.initVideo(this); @@ -860,6 +863,9 @@ Fluidbook.prototype = { } }, openVideo: function (video, callback) { + + this.video.removeAllVideos(); + var a = $('a[href="#/video/' + video + '"]'); var markup = decodeURIComponent($(a).attr('data-video')); var view = '
' + this.l10n.__('back') + '
'; diff --git a/js/libs/fluidbook/fluidbook.links.js b/js/libs/fluidbook/fluidbook.links.js index c636b964..ee62c2f6 100644 --- a/js/libs/fluidbook/fluidbook.links.js +++ b/js/libs/fluidbook/fluidbook.links.js @@ -62,6 +62,7 @@ FluidbookLinks.prototype = { this.animateLinks(); } setTimeout(function () { + console.info('initVideos called from fluidbook.links'); $this.fluidbook.initVideos(); }, 1000); $(fluidbook).trigger('fluidbooklinksready'); diff --git a/js/libs/fluidbook/fluidbook.resize.js b/js/libs/fluidbook/fluidbook.resize.js index f7b1ee97..1a586f58 100644 --- a/js/libs/fluidbook/fluidbook.resize.js +++ b/js/libs/fluidbook/fluidbook.resize.js @@ -128,10 +128,12 @@ FluidbookResize.prototype = { // console.log('marginbottom : ' + this.marginbottom); // console.log('marginleft : ' + this.marginleft); // console.log('marginright : ' + this.marginright); - console.log('marginLeft : ' + marginLeft); - console.log('marginTop : ' + marginTop); - console.log('marginBottom : ' + marginBottom); - console.log('marginRight : ' + marginRight); + + + // console.log('marginLeft : ' + marginLeft); + // console.log('marginTop : ' + marginTop); + // console.log('marginBottom : ' + marginBottom); + // console.log('marginRight : ' + marginRight); this.bookScale = Math.min(aw / fww, ah / fhh); @@ -244,7 +246,7 @@ FluidbookResize.prototype = { getPopupVideoHeight: function () { this.updateWindow(); - return this.hh - 80; + return this.hh - 104; }, getPopupWebVideoHeight: function () { @@ -272,7 +274,7 @@ FluidbookResize.prototype = { var w; var h; - $(".mview .videoContainer video").each(function () { + $(".mview .video-js").each(function () { if ($(this).data('width') !== null) { w = parseInt($(this).data('width')); h = parseInt($(this).data('height')); @@ -291,6 +293,8 @@ FluidbookResize.prototype = { } $(this).css({ + margin: '0 auto', // Centering + height: '100%', maxHeight: maxh, maxWidth: maxw }); @@ -396,6 +400,7 @@ FluidbookResize.prototype = { }); }, handleOrientation: function () { + var $this = this; var changeOrientation = this.orientation != ''; var o = this.fluidbook.support.getOrientation(); var newo; diff --git a/js/libs/fluidbook/fluidbook.video.js b/js/libs/fluidbook/fluidbook.video.js index 7c0e00af..218519a7 100644 --- a/js/libs/fluidbook/fluidbook.video.js +++ b/js/libs/fluidbook/fluidbook.video.js @@ -1,5 +1,20 @@ function FluidbookVideo(fluidbook) { - this.fluidbook = fluidbook; + + var $this = this; + + this.players = {}; + + console.info('**** SETUP FluidbookVideo module ****'); + + $(fluidbook).on('changePage', function (e, page) { + $this.removeAllVideos(); + }); + + $(window).on('fluidbookresize', function (e) { + $this.resizeControls(); + }); + + this.fluidbook = fluidbook; this.flash = FlashDetect.installed && FlashDetect.major >= 9; this.video = (Modernizr.video && (Modernizr.video.h264 || Modernizr.video.webm || Modernizr.video.ogg)) != false; @@ -8,9 +23,9 @@ function FluidbookVideo(fluidbook) { var probably = []; var maybe = []; var not = []; - if (Modernizr.ftouch && this.flash) { - maybe.push('flv'); - } + // if (Modernizr.ftouch && this.flash) { + // maybe.push('flv'); + // } if (this.video) { var formats = this.fluidbook.datas.videoFormats; @@ -38,9 +53,9 @@ function FluidbookVideo(fluidbook) { } } } - if (!Modernizr.ftouch && this.flash) { - maybe.push('flv'); - } + // if (!Modernizr.ftouch && this.flash) { + // maybe.push('flv'); + // } this.videoFormats = $.merge(probably, maybe, not); @@ -50,18 +65,46 @@ function FluidbookVideo(fluidbook) { FluidbookVideo.prototype = { initVideo: function (e) { + + var $this = this; + if ($(e).html() != '') { return; } - var width = parseFloat($(e).attr('data-width')); - var height = parseFloat($(e).attr('data-height')); - var name = $(e).attr('data-name'); - var controls = $(e).attr('data-controls'); - var loop = $(e).attr('data-loop'); - var sound = $(e).attr('data-sound'); - var autoplay = $(e).attr('data-autoplay'); - var path; + // if ($('#videoPopup').length == 0) { + // $('body').append('
'); + // + // $(document).on('click touchend', '.videoPopupLink', function(e) { + // e.preventDefault(); + // $this.openVideo(this); + // return false; + // }); + // } + + var id = $(e).data('id'), + width = parseFloat($(e).data('width')), + height = parseFloat($(e).data('height')), + name = $(e).data('name'), + controls = $(e).data('controls'), + loop = $(e).data('loop'), + sound = $(e).data('sound'), + autoplay = $(e).data('autoplay'), + setup = $(e).data('setup'), + path, + poster, + html, + player; + + fb('Initialising video ID: ' + id); + + // Player might be active but not visible so we need to dispose of it before re-initialising the element + if (videojs.players[id]) { + fb(id + ' player already active. Disposing...'); + videojs(id).dispose(); + } + + if (fluidbook.datas.mobileVideosPath == '') { path = "data/links/" + name; } else { @@ -70,72 +113,174 @@ FluidbookVideo.prototype = { path = '../' + path; } } - var poster = path + '.jpg'; - - if (this.preferedFormat == 'flv') { - var fv = {}; - fv.video = '../' + path + '.flv'; - fv.poster = '../' + poster; - fv.controls = controls; - fv.autoPlay = autoplay; - fv.loop = loop; - fv.soundOn = sound; - var flashvars = []; - $.each(fv, function (k, v) { - flashvars.push(k + '=' + encodeURIComponent(v)); + + if (name !== '') { + poster = path + '.jpg'; + } + + html = ''; + + $(e).html(html); + + player = videojs(id, setup); + player.ready(function() { + fb(id + ' player is ready'); + + $this.resizeControls(); // Make sure player controls are the right size + + if (fluidbook.video.players[id]) { + fb('found saved settings for player ID ' + id); + var settings = fluidbook.video.players[id]; + console.log(settings); + + // Restore settings + player.volume(settings.volume); + player.muted(settings.muted); + player.currentTime(settings.currentTime); + player.play(); // Start player to go to current position - necessary even if it will be paused immediately + if (settings.paused) { + player.pause(); + } + + // var playPromise = player.play(); + // if (settings.paused) { + // if (playPromise && (typeof Promise !== 'undefined') && (playPromise instanceof Promise)) { + // playPromise.then((result) => { + // setTimeout(player.pause, 100); + // }); + // } else { + // player.pause(); + // } + // } } - if (isNaN(height)) { - height = '100%'; + + }); + + player.on('pause', function() { + fb(id + ' player paused'); + // Todo: show/hide play button: http://stackoverflow.com/a/25296575 + }); + + // player.on('fullscreenchange', function() { + // fb('Entering or exiting fullscreen... resetting control sizes #' + player.id()); + // Note: this doesn't work because the fluidbookresize gets called multiple times after this fires and that overrides this change + // $('#' + player.id()).attr('style', ''); // Reset inline styles + // }); + + }, + openVideo: function(link) { + if (link === undefined) return false; + + console.info('openVideo...'); + + link = $(link); + + var popup = $('#videoPopup'), + html, + width = parseFloat(link.data('width')), + height = parseFloat(link.data('height')), + name = link.data('name'), + controls = link.data('controls'), + loop = link.data('loop'), + sound = link.data('sound'), + autoplay = link.data('autoplay'), + path, + poster; + + console.info(width, height, name, loop); + + if (fluidbook.datas.mobileVideosPath == '') { + path = "data/links/" + name; + } else { + path = fluidbook.datas.mobileVideosPath + name; + if (!fluidbook.datas.standalone && path.substr(0, 3) == '../') { + path = '../' + path; } + } + poster = path + '.jpg'; + + // Build