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

@@ -110,6 +110,12 @@ angular.module('app')
this.showExtensions = false;
}
this.closeAllMenus = function() {
this.showEditorMenu = false;
this.showMenu = false;
this.showExtensions = false;
}
this.editorMenuOnSelect = function(component) {
if(!component || component.area == "editor-editor") {
// if plain editor or other editor
@@ -419,7 +425,7 @@ angular.module('app')
Components
*/
componentManager.registerHandler({identifier: "editor", areas: ["note-tags", "editor-stack", "editor-editor"], activationHandler: function(component){
componentManager.registerHandler({identifier: "editor", areas: ["note-tags", "editor-stack", "editor-editor"], activationHandler: (component) => {
if(component.area === "note-tags") {
// Autocomplete Tags
this.tagsComponent = component.active ? component : null;
@@ -433,9 +439,13 @@ angular.module('app')
} else if(component.area == "editor-stack") {
this.reloadComponentContext();
}
}.bind(this), contextRequestHandler: function(component){
}, contextRequestHandler: (component) => {
return this.note;
}.bind(this), actionHandler: function(component, action, data){
}, focusHandler: (component, focused) => {
if(component.isEditor() && focused) {
this.closeAllMenus();
}
}, actionHandler: (component, action, data) => {
if(action === "set-size") {
var setSize = function(element, size) {
var widthString = typeof size.width === 'string' ? size.width : `${data.width}px`;
@@ -481,7 +491,7 @@ angular.module('app')
}
}
}
}.bind(this)});
}});
this.reloadComponentContext = function() {
// componentStack is used by the template to ng-repeat

View File

@@ -126,8 +126,18 @@ angular.module('app')
if(action == "set-size") {
component.setLastSize(data);
}
}, focusHandler: (component, focused) => {
if(component.isEditor() && focused) {
this.closeAllRooms();
this.closeAccountMenu();
}
}});
$rootScope.$on("editorFocused", () => {
this.closeAllRooms();
this.closeAccountMenu();
})
this.onRoomDismiss = function(room) {
room.showRoom = false;
}

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`;

View File

@@ -68,6 +68,11 @@ class DesktopManager {
let permissableKeys = ["package_info", "local_url"];
var component = this.modelManager.findItem(componentData.uuid);
if(!component) {
console.error("desktop_onComponentInstallationComplete component is null for uuid", componentData.uuid);
return;
}
if(error) {
component.setAppDataItem("installError", error);
} else {