From 72d3fbb69cf0e445a6636701e8ea35bd7320c7d9 Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Mon, 20 Dec 2021 20:40:51 +0100 Subject: [PATCH] Allow deep-linking to media items. WIP #4973 @2 --- resources/js/media-library.js | 40 ++++++++++++++++++- .../components/media-library/index.blade.php | 29 +++++++++----- resources/views/layouts/app.blade.php | 3 +- 3 files changed, 59 insertions(+), 13 deletions(-) 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