Focus handlers

This commit is contained in:
Mo Bitar
2018-01-31 10:40:26 -06:00
parent 4281ed730c
commit e20c1224d2
4 changed files with 51 additions and 4 deletions

View File

@@ -15,6 +15,20 @@ class ComponentManager {
this.contextStreamObservers = [];
this.activeComponents = [];
const detectFocusChange = (event) => {
for(var component of this.activeComponents) {
if(document.activeElement == this.iframeForComponent(component)) {
this.timeout(() => {
this.focusChangedForComponent(component);
})
break;
}
}
}
window.addEventListener ? window.addEventListener('focus', detectFocusChange, true) : window.attachEvent('onfocusout', detectFocusChange);
window.addEventListener ? window.addEventListener('blur', detectFocusChange, true) : window.attachEvent('onblur', detectFocusChange);
desktopManager.registerUpdateObserver((component) => {
// Reload theme if active
if(component.active && component.isTheme()) {
@@ -766,6 +780,14 @@ class ComponentManager {
}
}
focusChangedForComponent(component) {
let focused = document.activeElement == this.iframeForComponent(component);
for(var handler of this.handlers) {
// Notify all handlers, and not just ones that match this component type
handler.focusHandler && handler.focusHandler(component, focused);
}
}
handleSetSizeEvent(component, data) {
var setSize = function(element, size) {
var widthString = typeof size.width === 'string' ? size.width : `${data.width}px`;