Skip to content

Commit

Permalink
feat: Make pause on open optional for ModalDialog via options (#4187)
Browse files Browse the repository at this point in the history
* The new option is called pauseOnOpen, and defaults to true
* default pauseOnOpen to false in the `ErrorDisplay`
  • Loading branch information
brandonocasey authored Mar 13, 2017
1 parent d2b4f1c commit 4ec3b56
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/js/error-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ErrorDisplay extends ModalDialog {
* @private
*/
ErrorDisplay.prototype.options_ = mergeOptions(ModalDialog.prototype.options_, {
pauseOnOpen: false,
fillAlways: true,
temporary: false,
uncloseable: true
Expand Down
5 changes: 3 additions & 2 deletions src/js/modal-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ModalDialog extends Component {
// playing state.
this.wasPlaying_ = !player.paused();

if (this.wasPlaying_) {
if (this.options_.pauseOnOpen && this.wasPlaying_) {
player.pause();
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class ModalDialog extends Component {
this.trigger('beforemodalclose');
this.opened_ = false;

if (this.wasPlaying_) {
if (this.wasPlaying_ && this.options_.pauseOnOpen) {
player.play();
}

Expand Down Expand Up @@ -427,6 +427,7 @@ class ModalDialog extends Component {
* @private
*/
ModalDialog.prototype.options_ = {
pauseOnOpen: true,
temporary: true
};

Expand Down
29 changes: 29 additions & 0 deletions test/unit/modal-dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,35 @@ QUnit.test('open() pauses playback, close() resumes', function(assert) {
assert.strictEqual(playSpy.callCount, 1, 'player is resumed when the modal closes');
});

QUnit.test('open() does not pause, close() does not play() with pauseOnOpen set to false', function(assert) {
const playSpy = sinon.spy();
const pauseSpy = sinon.spy();

// don't pause the video on modal open
this.modal.options_.pauseOnOpen = false;

// Quick and dirty; make it looks like the player is playing.
this.player.paused = function() {
return false;
};

this.player.play = function() {
playSpy();
};

this.player.pause = function() {
pauseSpy();
};

this.modal.open();

assert.expect(2);
assert.strictEqual(pauseSpy.callCount, 0, 'player remains playing when the modal opens');

this.modal.close();
assert.strictEqual(playSpy.callCount, 0, 'player is resumed when the modal closes');
});

QUnit.test('open() hides controls, close() shows controls', function(assert) {
this.modal.open();

Expand Down

0 comments on commit 4ec3b56

Please sign in to comment.