Added IE11 polyfills for common-tags
Load video.js if previews are present
This commit is contained in:
parent
c2ae011223
commit
6712cb4412
|
@ -1,3 +1,6 @@
|
||||||
|
import 'core-js/modules/es7.array.includes.js';
|
||||||
|
import 'core-js/modules/es6.string.includes.js';
|
||||||
|
import 'core-js/modules/es6.number.is-nan.js';
|
||||||
import * as Handlebars from 'handlebars';
|
import * as Handlebars from 'handlebars';
|
||||||
import { ISearchResult } from '../../models/ISearchResult';
|
import { ISearchResult } from '../../models/ISearchResult';
|
||||||
import { html } from 'common-tags';
|
import { html } from 'common-tags';
|
||||||
|
@ -12,6 +15,7 @@ declare var System: any;
|
||||||
|
|
||||||
abstract class BaseTemplateService {
|
abstract class BaseTemplateService {
|
||||||
private _helper = null;
|
private _helper = null;
|
||||||
|
private _videoJs = null;
|
||||||
public CurrentLocale = "en";
|
public CurrentLocale = "en";
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -32,7 +36,6 @@ abstract class BaseTemplateService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the default Handlebars list item template used in list layout
|
* Gets the default Handlebars list item template used in list layout
|
||||||
* @returns the template HTML markup
|
* @returns the template HTML markup
|
||||||
|
@ -218,7 +221,7 @@ abstract class BaseTemplateService {
|
||||||
* @returns the template HTML markup
|
* @returns the template HTML markup
|
||||||
*/
|
*/
|
||||||
public static getBlankDefaultTemplate(): string {
|
public static getBlankDefaultTemplate(): string {
|
||||||
return html`
|
return `
|
||||||
<style>
|
<style>
|
||||||
/* Insert your CSS here */
|
/* Insert your CSS here */
|
||||||
</style>
|
</style>
|
||||||
|
@ -326,6 +329,9 @@ abstract class BaseTemplateService {
|
||||||
// Process the Handlebars template
|
// Process the Handlebars template
|
||||||
let template = Handlebars.compile(templateContent);
|
let template = Handlebars.compile(templateContent);
|
||||||
let result = template(templateContext);
|
let result = template(templateContext);
|
||||||
|
if (result.indexOf("-preview-item") != -1) {
|
||||||
|
await this._loadVideoLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -345,7 +351,6 @@ abstract class BaseTemplateService {
|
||||||
* Initializes the previews on search results for documents and videos. Called when a template is updated/changed
|
* Initializes the previews on search results for documents and videos. Called when a template is updated/changed
|
||||||
*/
|
*/
|
||||||
public initPreviewElements(): void {
|
public initPreviewElements(): void {
|
||||||
|
|
||||||
this._initVideoPreviews();
|
this._initVideoPreviews();
|
||||||
this._initDocumentPreviews();
|
this._initDocumentPreviews();
|
||||||
}
|
}
|
||||||
|
@ -415,7 +420,7 @@ abstract class BaseTemplateService {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _initVideoPreviews() {
|
private async _loadVideoLibrary(){
|
||||||
|
|
||||||
// Load Videos-Js on Demand
|
// Load Videos-Js on Demand
|
||||||
// Webpack will create a other bundle loaded on demand just for this library
|
// Webpack will create a other bundle loaded on demand just for this library
|
||||||
|
@ -424,8 +429,10 @@ abstract class BaseTemplateService {
|
||||||
'video.js',
|
'video.js',
|
||||||
);
|
);
|
||||||
|
|
||||||
const Video = videoJs.default;
|
this._videoJs = videoJs.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _initVideoPreviews() {
|
||||||
const nodes = document.querySelectorAll('.video-preview-item');
|
const nodes = document.querySelectorAll('.video-preview-item');
|
||||||
|
|
||||||
DomHelper.forEach(nodes, ((index, el) => {
|
DomHelper.forEach(nodes, ((index, el) => {
|
||||||
|
@ -442,14 +449,14 @@ abstract class BaseTemplateService {
|
||||||
const previewContainedId = `${playerId}_container`;
|
const previewContainedId = `${playerId}_container`;
|
||||||
let containerElt = document.getElementById(previewContainedId);
|
let containerElt = document.getElementById(previewContainedId);
|
||||||
|
|
||||||
let player = Video.getPlayer(`#${playerId}`);
|
let player = this._videoJs.getPlayer(`#${playerId}`);
|
||||||
|
|
||||||
// Case when the player is still registered in Video.js but does not exist in the DOM (due to page mode switch or tempalte update)
|
// Case when the player is still registered in Video.js but does not exist in the DOM (due to page mode switch or tempalte update)
|
||||||
if (player && !document.getElementById(playerId)) {
|
if (player && !document.getElementById(playerId)) {
|
||||||
|
|
||||||
// In this case, we simply delete the player instance and recreate it
|
// In this case, we simply delete the player instance and recreate it
|
||||||
player.dispose();
|
player.dispose();
|
||||||
player = Video.getPlayer(`#${playerId}`);
|
player = this._videoJs.getPlayer(`#${playerId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove exiting instance if there is already a player registered with id
|
// Remove exiting instance if there is already a player registered with id
|
||||||
|
@ -476,7 +483,7 @@ abstract class BaseTemplateService {
|
||||||
DomHelper.insertAfter(newEl, thumbnailElt.parentElement);
|
DomHelper.insertAfter(newEl, thumbnailElt.parentElement);
|
||||||
|
|
||||||
// Instantiate a new player with Video.js
|
// Instantiate a new player with Video.js
|
||||||
const videoPlayer = new Video(playerId, {
|
const videoPlayer = new this._videoJs(playerId, {
|
||||||
controls: true,
|
controls: true,
|
||||||
autoplay: false,
|
autoplay: false,
|
||||||
preload: "metadata",
|
preload: "metadata",
|
||||||
|
|
Loading…
Reference in New Issue