-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-tooltips.js
35 lines (27 loc) · 1.27 KB
/
simple-tooltips.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*! Simple transfert for title contents into data-tooltip attributes by cara-tm.com, MIT license. */
;(function(window) {
'use strict';
// Verifies if querySelectorAll is supported by the browser
if (document.querySelectorAll) {
// Add a new class attribute within the html tag when this script is ready
document.querySelector('html').classList.add('tooltips');
// The variable 't' is an array of all HTML elements with a 'data-tooltip' attribute
var t = document.querySelectorAll('.tooltip');
// Loop into all elements found
for (var i = 0; i < t.length; i++) {
if (Math.max(document.documentElement.clientWidth, window.innerWidth || 0) || document.body.clientWidth >= 680) {
// Stores the 'title' attribute content
var o = t[i].getAttribute('title');
if (o != null) {
// Transferts the 'title' content into a new 'aria-label' attribute attached to the current HTML element
t[i].setAttribute('aria-label', o);
// Adds some attributes for accessibility
t[i].setAttribute('aria-haspopup', 'true');
t[i].setAttribute('role', 'link');
// Removes the 'title' attribute into corresponding elements
t[i].removeAttribute('title');
}
}
}
};
})();