Skip to content

Commit ca09968

Browse files
authored
feat(fill): make vjs-fill a player mode (#5478)
Like fluid mode, you can enable it with the class or by calling the fill method. Calling fill() will turn off fluid mode and calling fluid() will turn off fill mode. Fluid mode takes precedence over fill mode.
1 parent 966eb56 commit ca09968

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/js/player.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,13 @@ class Player extends Component {
652652
head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
653653
}
654654

655+
this.fill_ = false;
656+
this.fluid_ = false;
657+
655658
// Pass in the width/height/aspectRatio options which will update the style el
656659
this.width(this.options_.width);
657660
this.height(this.options_.height);
661+
this.fill(this.options_.fill);
658662
this.fluid(this.options_.fluid);
659663
this.aspectRatio(this.options_.aspectRatio);
660664

@@ -765,10 +769,12 @@ class Player extends Component {
765769
/**
766770
* A getter/setter/toggler for the vjs-fluid `className` on the `Player`.
767771
*
772+
* Turning this on will turn off fill mode.
773+
*
768774
* @param {boolean} [bool]
769775
* - A value of true adds the class.
770776
* - A value of false removes the class.
771-
* - No value will toggle the fluid class.
777+
* - No value will be a getter.
772778
*
773779
* @return {boolean|undefined}
774780
* - The value of fluid when getting.
@@ -783,13 +789,43 @@ class Player extends Component {
783789

784790
if (bool) {
785791
this.addClass('vjs-fluid');
792+
this.fill(false);
786793
} else {
787794
this.removeClass('vjs-fluid');
788795
}
789796

790797
this.updateStyleEl_();
791798
}
792799

800+
/**
801+
* A getter/setter/toggler for the vjs-fill `className` on the `Player`.
802+
*
803+
* Turning this on will turn off fluid mode.
804+
*
805+
* @param {boolean} [bool]
806+
* - A value of true adds the class.
807+
* - A value of false removes the class.
808+
* - No value will be a getter.
809+
*
810+
* @return {boolean|undefined}
811+
* - The value of fluid when getting.
812+
* - `undefined` when setting.
813+
*/
814+
fill(bool) {
815+
if (bool === undefined) {
816+
return !!this.fill_;
817+
}
818+
819+
this.fill_ = !!bool;
820+
821+
if (bool) {
822+
this.addClass('vjs-fill');
823+
this.fluid(false);
824+
} else {
825+
this.removeClass('vjs-fill');
826+
}
827+
}
828+
793829
/**
794830
* Get/Set the aspect ratio
795831
*
@@ -3658,6 +3694,9 @@ class Player extends Component {
36583694
const tagOptions = Dom.getAttributes(tag);
36593695
const dataSetup = tagOptions['data-setup'];
36603696

3697+
if (Dom.hasClass(tag, 'vjs-fill')) {
3698+
tagOptions.fill = true;
3699+
}
36613700
if (Dom.hasClass(tag, 'vjs-fluid')) {
36623701
tagOptions.fluid = true;
36633702
}

test/unit/player.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,54 @@ QUnit.test('should set fluid to true if element has vjs-fluid class', function(a
404404
player.dispose();
405405
});
406406

407+
QUnit.test('should set fill to true if element has vjs-fill class', function(assert) {
408+
const tag = TestHelpers.makeTag();
409+
410+
tag.className += ' vjs-fill';
411+
412+
const player = TestHelpers.makePlayer({}, tag);
413+
414+
assert.ok(player.fill(), 'fill is true with vjs-fill class');
415+
416+
player.dispose();
417+
});
418+
419+
QUnit.test('fill turns off fluid', function(assert) {
420+
const tag = TestHelpers.makeTag();
421+
422+
tag.className += ' vjs-fluid';
423+
424+
const player = TestHelpers.makePlayer({}, tag);
425+
426+
assert.notOk(player.fill(), 'fill is false');
427+
assert.ok(player.fluid(), 'fluid is true');
428+
429+
player.fill(true);
430+
431+
assert.ok(player.fill(), 'fill is true');
432+
assert.notOk(player.fluid(), 'fluid is false');
433+
434+
player.dispose();
435+
});
436+
437+
QUnit.test('fluid turns off fill', function(assert) {
438+
const tag = TestHelpers.makeTag();
439+
440+
tag.className += ' vjs-fill';
441+
442+
const player = TestHelpers.makePlayer({}, tag);
443+
444+
assert.ok(player.fill(), 'fill is true');
445+
assert.notOk(player.fluid(), 'fluid is false');
446+
447+
player.fluid(true);
448+
449+
assert.notOk(player.fill(), 'fill is false');
450+
assert.ok(player.fluid(), 'fluid is true');
451+
452+
player.dispose();
453+
});
454+
407455
QUnit.test('should use an class name that begins with an alpha character', function(assert) {
408456
const alphaPlayer = TestHelpers.makePlayer({ id: 'alpha1' });
409457
const numericPlayer = TestHelpers.makePlayer({ id: '1numeric' });

0 commit comments

Comments
 (0)