dragresize: Unregister global event handlers
This commit is contained in:
parent
97b8ecbbdf
commit
7866247f5d
@ -331,16 +331,14 @@ converse.plugins.add('converse-dragresize', {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/************************ BEGIN Event Handlers ************************/
|
function onMouseMove (ev) {
|
||||||
function registerGlobalEventHandlers () {
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', function (ev) {
|
|
||||||
if (!_converse.resizing || !_converse.allow_dragresize) { return true; }
|
if (!_converse.resizing || !_converse.allow_dragresize) { return true; }
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
_converse.resizing.chatbox.resizeChatBox(ev);
|
_converse.resizing.chatbox.resizeChatBox(ev);
|
||||||
});
|
}
|
||||||
|
|
||||||
document.addEventListener('mouseup', function (ev) {
|
|
||||||
|
function onMouseUp (ev) {
|
||||||
if (!_converse.resizing || !_converse.allow_dragresize) { return true; }
|
if (!_converse.resizing || !_converse.allow_dragresize) { return true; }
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const height = u.applyDragResistance(
|
const height = u.applyDragResistance(
|
||||||
@ -359,9 +357,21 @@ converse.plugins.add('converse-dragresize', {
|
|||||||
_converse.resizing.chatbox.model.set({'width': width});
|
_converse.resizing.chatbox.model.set({'width': width});
|
||||||
}
|
}
|
||||||
_converse.resizing = null;
|
_converse.resizing = null;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************************ BEGIN Event Handlers ************************/
|
||||||
|
function registerGlobalEventHandlers () {
|
||||||
|
document.addEventListener('mousemove', onMouseMove);
|
||||||
|
document.addEventListener('mouseup', onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unregisterGlobalEventHandlers () {
|
||||||
|
document.removeEventListener('mousemove', onMouseMove);
|
||||||
|
document.removeEventListener('mouseup', onMouseUp);
|
||||||
|
}
|
||||||
|
|
||||||
_converse.api.listen.on('registeredGlobalEventHandlers', registerGlobalEventHandlers);
|
_converse.api.listen.on('registeredGlobalEventHandlers', registerGlobalEventHandlers);
|
||||||
|
_converse.api.listen.on('unregisteredGlobalEventHandlers', unregisterGlobalEventHandlers);
|
||||||
_converse.api.listen.on('beforeShowingChatView', view => view.initDragResize().setDimensions());
|
_converse.api.listen.on('beforeShowingChatView', view => view.initDragResize().setDimensions());
|
||||||
/************************ END Event Handlers ************************/
|
/************************ END Event Handlers ************************/
|
||||||
}
|
}
|
||||||
|
@ -836,7 +836,7 @@ async function finishInitialization () {
|
|||||||
await initStorage();
|
await initStorage();
|
||||||
initClientConfig();
|
initClientConfig();
|
||||||
initPlugins();
|
initPlugins();
|
||||||
_converse.registerGlobalEventHandlers();
|
registerGlobalEventHandlers();
|
||||||
|
|
||||||
if (!Backbone.History.started) {
|
if (!Backbone.History.started) {
|
||||||
Backbone.history.start();
|
Backbone.history.start();
|
||||||
@ -927,6 +927,21 @@ async function getLoginCredentialsFromBrowser () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function registerGlobalEventHandlers () {
|
||||||
|
document.addEventListener("visibilitychange", _converse.saveWindowState);
|
||||||
|
_converse.saveWindowState({'type': document.hidden ? "blur" : "focus"}); // Set initial state
|
||||||
|
/**
|
||||||
|
* Called once Converse has registered its global event handlers
|
||||||
|
* (for events such as window resize or unload).
|
||||||
|
* Plugins can listen to this event as cue to register their own
|
||||||
|
* global event handlers.
|
||||||
|
* @event _converse#registeredGlobalEventHandlers
|
||||||
|
* @example _converse.api.listen.on('registeredGlobalEventHandlers', () => { ... });
|
||||||
|
*/
|
||||||
|
_converse.api.trigger('registeredGlobalEventHandlers');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function unregisterGlobalEventHandlers () {
|
function unregisterGlobalEventHandlers () {
|
||||||
document.removeEventListener("visibilitychange", _converse.saveWindowState);
|
document.removeEventListener("visibilitychange", _converse.saveWindowState);
|
||||||
_converse.api.trigger('unregisteredGlobalEventHandlers');
|
_converse.api.trigger('unregisteredGlobalEventHandlers');
|
||||||
@ -1174,20 +1189,6 @@ _converse.initialize = async function (settings, callback) {
|
|||||||
_converse.api.trigger('windowStateChanged', {state});
|
_converse.api.trigger('windowStateChanged', {state});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.registerGlobalEventHandlers = function () {
|
|
||||||
document.addEventListener("visibilitychange", _converse.saveWindowState);
|
|
||||||
_converse.saveWindowState({'type': document.hidden ? "blur" : "focus"}); // Set initial state
|
|
||||||
/**
|
|
||||||
* Called once Converse has registered its global event handlers
|
|
||||||
* (for events such as window resize or unload).
|
|
||||||
* Plugins can listen to this event as cue to register their own
|
|
||||||
* global event handlers.
|
|
||||||
* @event _converse#registeredGlobalEventHandlers
|
|
||||||
* @example _converse.api.listen.on('registeredGlobalEventHandlers', () => { ... });
|
|
||||||
*/
|
|
||||||
_converse.api.trigger('registeredGlobalEventHandlers');
|
|
||||||
};
|
|
||||||
|
|
||||||
this.bindResource = async function () {
|
this.bindResource = async function () {
|
||||||
/**
|
/**
|
||||||
* Synchronous event triggered before we send an IQ to bind the user's
|
* Synchronous event triggered before we send an IQ to bind the user's
|
||||||
|
Loading…
Reference in New Issue
Block a user