Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onEmbedCreated passthrough. #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ReactPlayerLoader extends React.Component {
// user-provided callbacks for use later.
const userSuccess = this.props.onSuccess;
const userFailure = this.props.onFailure;
const userOnEmbedCreated = this.props.onEmbedCreated;

const options = Object.assign({}, this.props, {
refNode: this.refNode,
Expand Down Expand Up @@ -122,6 +123,12 @@ class ReactPlayerLoader extends React.Component {

// Fall back to throwing an error;
throw new Error(error);
},
onEmbedCreated: (element) => {

if (typeof userOnEmbedCreated === 'function') {
userOnEmbedCreated(element);
}
}
});

Expand Down
21 changes: 21 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ QUnit.module('ReactPlayerLoader', {
assert.ok(this.fixture.querySelector('div[foo="bar"]'), 'foo="bar" div exists');
});

QUnit.test('can set attributes on the embed element', function(assert) {
const done = assert.async();

assert.expect(1);

ReactDOM.render(
React.createElement(ReactPlayerLoader, {
accountId: '1',
onSuccess: ({ref, type}) => {
window.setTimeout(done, 1);
},
onEmbedCreated: (element) => {
element.setAttribute('data-attribute', '1');
}
}),
this.fixture
);

assert.ok(this.fixture.querySelector('video-js[data-attribute="1"]'), 'found data attribute');
});

QUnit.test('className defaults to "brightcove-react-player-loader"', function(assert) {
const done = assert.async();

Expand Down