From db22a8e9c47b373d47652b2cc653f53e0b452de0 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 30 Jul 2018 23:20:27 +0200 Subject: [PATCH 1/2] Improve handling of the 'controls' argument --- src/js/controls.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/js/controls.js b/src/js/controls.js index e95cfc86..c01e3584 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -1117,11 +1117,6 @@ const controls = { // Build the default HTML // TODO: Set order based on order in the config.controls array? create(data) { - // Do nothing if we want no controls - if (is.empty(this.config.controls)) { - return null; - } - // Create the container const container = createElement('div', getAttributesFromSelector(this.config.selectors.controls.wrapper)); @@ -1401,13 +1396,19 @@ const controls = { }; let update = true; - if (is.string(this.config.controls) || is.element(this.config.controls)) { - // String or HTMLElement passed as the option + // If function, run it and use output + if (is.function(this.config.controls)) { + this.config.controls = this.config.controls.call(this.props); + } + + // Convert falsy controls to empty array (primarily for empty strings) + if (!this.config.controls) { + this.config.controls = []; + } + + if (is.element(this.config.controls) || is.string(this.config.controls)) { + // HTMLElement or Non-empty string passed as the option container = this.config.controls; - } else if (is.function(this.config.controls)) { - // A custom function to build controls - // The function can return a HTMLElement or String - container = this.config.controls.call(this, props); } else { // Create controls container = controls.create.call(this, { From c230ccce866711e977af44ca955e56a0db43d0a4 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 30 Jul 2018 23:42:36 +0200 Subject: [PATCH 2/2] Update controls.md docs --- controls.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controls.md b/controls.md index 63b17fa3..263e12f3 100644 --- a/controls.md +++ b/controls.md @@ -3,7 +3,9 @@ This is the markup that is rendered for the Plyr controls. You can use the default controls or provide a customized version of markup based on your needs. You can pass the following to the `controls` option: - `Array` of options (this builds the default controls based on your choices) +- `Element` with the controls - `String` containing the desired HTML +- `false` (or empty string or array) to disable all controls - `Function` that will be executed and should return one of the above ## Using default controls