From 4c2d6041ab986285bbcffb82f40ff71cca00b215 Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Tue, 23 Nov 2021 23:35:01 +0100 Subject: [PATCH] WIP #4822 @8 --- resources/js/media-library.js | 78 +++++++++++----- .../components/media-library/index.blade.php | 25 +++-- .../components/media-library/player.blade.php | 93 +++++++++++++++---- 3 files changed, 147 insertions(+), 49 deletions(-) diff --git a/resources/js/media-library.js b/resources/js/media-library.js index 49a1358..b3f9522 100644 --- a/resources/js/media-library.js +++ b/resources/js/media-library.js @@ -1,16 +1,27 @@ -// Media Library functionality +//==============================// +// Media Library functionality // +//============================// + export default (options = {}) => ({ filters: options.filters || {}, // Filters JSON array is passed in from HTML - gridSelector: options.gridSelector || false, // CSS selector for main Isotope element - filtersOpen: false, + filtersOpen: false, // Visibility of the filters overlay activeTypeFilters: [], activeThemeFilters: [], - isotope: {}, - playerOpen: false, - playerType: 'video', // Can be 'video' or 'audio' - playerSrc: '', - playerPoster: '', - playerMIME: '', + isotope: {}, // Holds the Isotope instance + isotopeOptions: { // Options used for Isotope instantiation (https://isotope.metafizzy.co/options.html) + layoutMode: 'fitRows', + percentPosition: true, + }, + + playerOpen: false, // Visibility of the media player overlay + player: {}, // Holds the Plyr instance + playerOptions: { // Settings used for Plyr instantiation (https://github.com/sampotts/plyr#options) + debug: true, + }, + + /***********\ + | Filtering | + \***********/ get themeFilterList() { // Convert active theme filters array into class string for Isotope @@ -44,17 +55,9 @@ export default (options = {}) => ({ return list.join(); }, - init() { - if (!this.gridSelector) { - console.warn('Error: gridSelector not defined for media grid'); - return false; - } - + initIsotope(element) { // Initialise Isotope - this.isotope = new Isotope(this.gridSelector, { - layoutMode: 'fitRows', - percentPosition: true, - }); + this.isotope = new Isotope(element, this.isotopeOptions); // Update Isotope whenever active filters change this.$watch('activeTypeFilters', () => this.applyFilters()); @@ -62,18 +65,47 @@ export default (options = {}) => ({ }, applyFilters() { - console.log('applying filters', this.themeFilterList) - this.isotope.arrange({ filter: this.themeFilterList }) + //console.log('applying filters', this.themeFilterList); + this.isotope.arrange({ filter: this.themeFilterList }); }, removeTypeFilter(filterID) { // Remove the filter from the array - this.activeTypeFilters = this.activeTypeFilters.filter(item => item !== filterID) + this.activeTypeFilters = this.activeTypeFilters.filter(item => item !== filterID); }, removeThemeFilter(filterID) { // Remove the filter from the array - this.activeThemeFilters = this.activeThemeFilters.filter(item => item !== filterID) + this.activeThemeFilters = this.activeThemeFilters.filter(item => item !== filterID); + }, + + /**************\ + | Media Player | + \**************/ + + initPlayer(selector) { + + // Get custom controls HTML from the