- md5
- c7e48ab3b2faae656de062f558aca5e7
- sha1
- f4682caf4bc839f195e2545ab8fd02a50c8cd41c
- sha256
- 68c78807283e4ee2ceac393e2cb16c5fe50b705d8b8b3a182dcc36e87dbca0ce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
(function() {
'use strict';
document.addEventListener('DOMContentLoaded', function() {
var DURATION = 150,
ringElem = null,
movingId = 0,
prevFocused = null,
keyDownTime = 0,
win = window,
doc = document,
body = doc.body;
doc.addEventListener('keydown', function(event) {
var code = event.which;
// Show animation only upon Tab or Arrow keys press.
if (code === 9 || (code > 36 && code < 41)) {
keyDownTime = Date.now();
}
}, false);
doc.addEventListener('focus', function(event) {
var target = event.target;
if (target.id === 'flying-focus') {
return;
}
var isFirstFocus = false;
if (!ringElem) {
isFirstFocus = true;
initialize();
}
if (body.contains(target))
{
var offset = offsetOf(target);
ringElem.style.left = offset.left + 'px';
ringElem.style.top = offset.top + 'px';
ringElem.style.width = target.offsetWidth + 'px';
ringElem.style.height = target.offsetHeight + 'px';
}
if (isFirstFocus || !isJustPressed()) {
return;
}
onEnd();
target.classList.add('flying-focus_target');
ringElem.classList.add('flying-focus_visible');
prevFocused = target;
movingId = setTimeout(onEnd, DURATION);
}, true);
doc.addEventListener('blur', function() {
onEnd();
}, true);
function initialize() {
// Check if the element already exists to prevent duplicates
if (document.getElementById('flying-focus')) {
return;
}
// Use uniq element name to decrease the chances of a conflict with website styles
ringElem = doc.createElement('flying-focus');
ringElem.id = 'flying-focus';
ringElem.style.transitionDuration = ringElem.style.WebkitTransitionDuration = DURATION / 1000 + 's';
body.appendChild(ringElem);
}
function onEnd() {
if (!movingId) {
return;
}
clearTimeout(movingId);
movingId = 0;
ringElem.classList.remove('flying-focus_visible');
prevFocused.classList.remove('flying-focus_target');
prevFocused = null;
}
function isJustPressed() {
return Date.now() - keyDownTime < 42
}
function offsetOf(elem) {
var rect = elem.getBoundingClientRect();
var clientLeft = doc.clientLeft || body.clientLeft;
var clientTop = doc.clientTop || body.clientTop;
var scrollLeft = win.pageXOffset || doc.scrollLeft || body.scrollLeft;
var scrollTop = win.pageYOffset || doc.scrollTop || body.scrollTop;
var left = rect.left + scrollLeft - clientLeft;
var top = rect.top + scrollTop - clientTop;
return {
top: top || 0,
left: left || 0
};
}
});
})();
The same content is in 2 releases, Joomla 4.0.0-alpha2 to 4.0.0-alpha3. See them all, or every version of this file.