From: Stephen Cameron Date: Mon, 20 Dec 2021 19:40:51 +0000 (+0100) Subject: Allow deep-linking to media items. WIP #4973 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=72d3fbb69cf0e445a6636701e8ea35bd7320c7d9;p=odl.git Allow deep-linking to media items. WIP #4973 @2 --- diff --git a/resources/js/media-library.js b/resources/js/media-library.js index 313442e..3317a15 100644 --- a/resources/js/media-library.js +++ b/resources/js/media-library.js @@ -13,6 +13,7 @@ export default (options = {}) => ({ }, player: {}, // Holds the Plyr instance + playerInitialised: false, playerOptions: { // Settings used for Plyr instantiation (https://github.com/sampotts/plyr#options) debug: false, loadSprite: false, // Custom SVG sprite is already embedded in the page @@ -23,6 +24,25 @@ export default (options = {}) => ({ playerTitle: '', playerImage: '', + /****************\ + | Initialisation | + \****************/ + + init() { + // Open player if querystring is already set + let querystring = new URLSearchParams(location.search); + let ID = querystring.get('id'); + if (ID) { + let media = document.querySelector(`#media_${ID}`) + if (media) { + this.maskContents = true; // Hide page contents while player loads + this.initPlayer('#player'); + this.openPlayer(JSON.parse(media.dataset.player), false); + this.maskContents = false; + } + } + }, + /***********\ | Filtering | \***********/ @@ -93,6 +113,10 @@ export default (options = {}) => ({ initPlayer(selector) { + if (this.playerInitialised) { + return true; // Don't initialise player more than once + } + // Get custom controls HTML from the