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 title to all clickable components #3296

Closed
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
12 changes: 8 additions & 4 deletions src/js/clickable-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,27 @@ class ClickableComponent extends Component {
el.appendChild(this.controlTextEl_);
}

this.controlText(this.controlText_);
this.controlText(this.controlText_, el);

return this.controlTextEl_;
}

/**
* Controls text - both request and localize
*
* @param {String} text Text for element
* @param {String} text Text for element
* @param {Element=} el Element to set the title on
* @return {String}
* @method controlText
*/
controlText(text) {
controlText(text, el=this.el()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible that this.el() will end up returning nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only during the first call, because that is made from createEl, at which time this.el() does not eixst yet. Afterwards it should always exist, right?

if (!text) return this.controlText_ || 'Need Text';

const localizedText = this.localize(text);

this.controlText_ = text;
this.controlTextEl_.innerHTML = this.localize(this.controlText_);
this.controlTextEl_.innerHTML = localizedText;
el.setAttribute('title', localizedText);

return this;
}
Expand Down
5 changes: 3 additions & 2 deletions test/unit/button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TestHelpers from './test-helpers.js';
q.module('Button');

test('should localize its text', function(){
expect(2);
expect(3);

var player, testButton, el;

Expand All @@ -22,5 +22,6 @@ test('should localize its text', function(){
el = testButton.createEl();

ok(el.nodeName.toLowerCase().match('button'));
ok(el.innerHTML.match('Juego'));
ok(el.innerHTML.match('vjs-control-text">Juego'));
equal(el.getAttribute('title'), 'Juego');
});