From bc5be3e4c1ea638d0994f2d95151013bb951e960 Mon Sep 17 00:00:00 2001 From: Pat O'Neill Date: Fri, 2 Oct 2015 15:11:55 -0400 Subject: [PATCH 01/36] Add CloseButton component --- src/js/close-button.js | 28 +++++++++++++++++++++ test/unit/close-button.test.js | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/js/close-button.js create mode 100644 test/unit/close-button.test.js diff --git a/src/js/close-button.js b/src/js/close-button.js new file mode 100644 index 0000000000..7c1d8dd33b --- /dev/null +++ b/src/js/close-button.js @@ -0,0 +1,28 @@ +import Button from './button'; +import Component from './component'; + +/** + * The `CloseButton` component is a button which fires a "close" event + * when it is activated. + * + * @extends Button + * @class CloseButton + */ +class CloseButton extends Button { + + constructor(player, options) { + super(player, options); + this.controlText(options && options.controlText || this.localize('Close')); + } + + buildCSSClass() { + return `vjs-close ${super.buildCSSClass()}`; + } + + handleClick() { + this.trigger({type: 'close', bubbles: false}); + } +} + +Component.registerComponent('CloseButton', CloseButton); +export default CloseButton; diff --git a/test/unit/close-button.test.js b/test/unit/close-button.test.js new file mode 100644 index 0000000000..48f74cf360 --- /dev/null +++ b/test/unit/close-button.test.js @@ -0,0 +1,45 @@ +import CloseButton from '../../src/js/close-button'; +import TestHelpers from './test-helpers'; + +q.module('CloseButton', { + + beforeEach: function() { + this.player = TestHelpers.makePlayer(); + this.btn = new CloseButton(this.player); + }, + + afterEach: function() { + this.player.dispose(); + this.btn.dispose(); + } +}); + +q.test('should create the expected element', function(assert) { + var classes = ['button', 'close', 'control']; + + assert.expect(2 + classes.length); + assert.strictEqual(this.btn.el().tagName.toLowerCase(), 'button', 'is a