From f2e821a7f76a801e0a75c5248b46af2ffced64fb Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Wed, 4 May 2016 09:47:39 +0200 Subject: [PATCH] Add title to all clickable components --- src/js/clickable-component.js | 12 ++++++++---- test/unit/button.test.js | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/js/clickable-component.js b/src/js/clickable-component.js index 3ee32f7018..2861b3a228 100644 --- a/src/js/clickable-component.js +++ b/src/js/clickable-component.js @@ -78,7 +78,7 @@ class ClickableComponent extends Component { el.appendChild(this.controlTextEl_); } - this.controlText(this.controlText_); + this.controlText(this.controlText_, el); return this.controlTextEl_; } @@ -86,15 +86,19 @@ class ClickableComponent extends Component { /** * 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()) { 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; } diff --git a/test/unit/button.test.js b/test/unit/button.test.js index 9070738606..23887eb5da 100644 --- a/test/unit/button.test.js +++ b/test/unit/button.test.js @@ -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; @@ -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'); });