|
@@ -45,42 +45,6 @@ converse.plugins.add('converse-dragresize', {
|
|
// Overrides mentioned here will be picked up by converse.js's
|
|
// Overrides mentioned here will be picked up by converse.js's
|
|
// plugin architecture they will replace existing methods on the
|
|
// plugin architecture they will replace existing methods on the
|
|
// relevant objects or classes.
|
|
// relevant objects or classes.
|
|
- //
|
|
|
|
- // New functions which don't exist yet can also be added.
|
|
|
|
-
|
|
|
|
- registerGlobalEventHandlers () {
|
|
|
|
- const that = this;
|
|
|
|
-
|
|
|
|
- document.addEventListener('mousemove', function (ev) {
|
|
|
|
- if (!that.resizing || !that.allow_dragresize) { return true; }
|
|
|
|
- ev.preventDefault();
|
|
|
|
- that.resizing.chatbox.resizeChatBox(ev);
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- document.addEventListener('mouseup', function (ev) {
|
|
|
|
- if (!that.resizing || !that.allow_dragresize) { return true; }
|
|
|
|
- ev.preventDefault();
|
|
|
|
- const height = that.applyDragResistance(
|
|
|
|
- that.resizing.chatbox.height,
|
|
|
|
- that.resizing.chatbox.model.get('default_height')
|
|
|
|
- );
|
|
|
|
- const width = that.applyDragResistance(
|
|
|
|
- that.resizing.chatbox.width,
|
|
|
|
- that.resizing.chatbox.model.get('default_width')
|
|
|
|
- );
|
|
|
|
- if (that.connection.connected) {
|
|
|
|
- that.resizing.chatbox.model.save({'height': height});
|
|
|
|
- that.resizing.chatbox.model.save({'width': width});
|
|
|
|
- } else {
|
|
|
|
- that.resizing.chatbox.model.set({'height': height});
|
|
|
|
- that.resizing.chatbox.model.set({'width': width});
|
|
|
|
- }
|
|
|
|
- that.resizing = null;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return this.__super__.registerGlobalEventHandlers.apply(this, arguments);
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
ChatBox: {
|
|
ChatBox: {
|
|
initialize () {
|
|
initialize () {
|
|
const { _converse } = this.__super__;
|
|
const { _converse } = this.__super__;
|
|
@@ -102,9 +66,24 @@ converse.plugins.add('converse-dragresize', {
|
|
'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
},
|
|
},
|
|
|
|
|
|
- initialize () {
|
|
|
|
- window.addEventListener('resize', _.debounce(this.setDimensions.bind(this), 100));
|
|
|
|
- this.__super__.initialize.apply(this, arguments);
|
|
|
|
|
|
+ render () {
|
|
|
|
+ const result = this.__super__.render.apply(this, arguments);
|
|
|
|
+ renderDragResizeHandles(this.__super__._converse, this);
|
|
|
|
+ this.setWidth();
|
|
|
|
+ return result;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ _show () {
|
|
|
|
+ this.initDragResize().setDimensions();
|
|
|
|
+ this.__super__._show.apply(this, arguments);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ HeadlinesBoxView: {
|
|
|
|
+ events: {
|
|
|
|
+ 'mousedown .dragresize-top': 'onStartVerticalResize',
|
|
|
|
+ 'mousedown .dragresize-left': 'onStartHorizontalResize',
|
|
|
|
+ 'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
},
|
|
},
|
|
|
|
|
|
render () {
|
|
render () {
|
|
@@ -112,27 +91,70 @@ converse.plugins.add('converse-dragresize', {
|
|
renderDragResizeHandles(this.__super__._converse, this);
|
|
renderDragResizeHandles(this.__super__._converse, this);
|
|
this.setWidth();
|
|
this.setWidth();
|
|
return result;
|
|
return result;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ ControlBoxView: {
|
|
|
|
+ events: {
|
|
|
|
+ 'mousedown .dragresize-top': 'onStartVerticalResize',
|
|
|
|
+ 'mousedown .dragresize-left': 'onStartHorizontalResize',
|
|
|
|
+ 'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
},
|
|
},
|
|
|
|
|
|
- setWidth () {
|
|
|
|
- // If a custom width is applied (due to drag-resizing),
|
|
|
|
- // then we need to set the width of the .chatbox element as well.
|
|
|
|
- if (this.model.get('width')) {
|
|
|
|
- this.el.style.width = this.model.get('width');
|
|
|
|
- }
|
|
|
|
|
|
+ render () {
|
|
|
|
+ const result = this.__super__.render.apply(this, arguments);
|
|
|
|
+ renderDragResizeHandles(this.__super__._converse, this);
|
|
|
|
+ this.setWidth();
|
|
|
|
+ return result;
|
|
},
|
|
},
|
|
|
|
|
|
- _show () {
|
|
|
|
|
|
+ renderLoginPanel () {
|
|
|
|
+ const result = this.__super__.renderLoginPanel.apply(this, arguments);
|
|
this.initDragResize().setDimensions();
|
|
this.initDragResize().setDimensions();
|
|
- this.__super__._show.apply(this, arguments);
|
|
|
|
|
|
+ return result;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ renderControlBoxPane () {
|
|
|
|
+ const result = this.__super__.renderControlBoxPane.apply(this, arguments);
|
|
|
|
+ this.initDragResize().setDimensions();
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ ChatRoomView: {
|
|
|
|
+ events: {
|
|
|
|
+ 'mousedown .dragresize-top': 'onStartVerticalResize',
|
|
|
|
+ 'mousedown .dragresize-left': 'onStartHorizontalResize',
|
|
|
|
+ 'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ render () {
|
|
|
|
+ const result = this.__super__.render.apply(this, arguments);
|
|
|
|
+ renderDragResizeHandles(this.__super__._converse, this);
|
|
|
|
+ this.setWidth();
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ initialize () {
|
|
|
|
+ /* The initialize function gets called as soon as the plugin is
|
|
|
|
+ * loaded by converse.js's plugin machinery.
|
|
|
|
+ */
|
|
|
|
+ const { _converse } = this;
|
|
|
|
+
|
|
|
|
+ _converse.api.settings.update({
|
|
|
|
+ 'allow_dragresize': true,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ const dragResizable = {
|
|
|
|
+
|
|
initDragResize () {
|
|
initDragResize () {
|
|
/* Determine and store the default box size.
|
|
/* Determine and store the default box size.
|
|
* We need this information for the drag-resizing feature.
|
|
* We need this information for the drag-resizing feature.
|
|
*/
|
|
*/
|
|
- const { _converse } = this.__super__,
|
|
|
|
- flyout = this.el.querySelector('.box-flyout'),
|
|
|
|
|
|
+ const flyout = this.el.querySelector('.box-flyout'),
|
|
style = window.getComputedStyle(flyout);
|
|
style = window.getComputedStyle(flyout);
|
|
|
|
|
|
if (_.isUndefined(this.model.get('height'))) {
|
|
if (_.isUndefined(this.model.get('height'))) {
|
|
@@ -157,6 +179,34 @@ converse.plugins.add('converse-dragresize', {
|
|
return this;
|
|
return this;
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ resizeChatBox (ev) {
|
|
|
|
+ let diff;
|
|
|
|
+ if (_converse.resizing.direction.indexOf('top') === 0) {
|
|
|
|
+ diff = ev.pageY - this.prev_pageY;
|
|
|
|
+ if (diff) {
|
|
|
|
+ this.height = ((this.height-diff) > (this.model.get('min_height') || 0)) ? (this.height-diff) : this.model.get('min_height');
|
|
|
|
+ this.prev_pageY = ev.pageY;
|
|
|
|
+ this.setChatBoxHeight(this.height);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (_.includes(_converse.resizing.direction, 'left')) {
|
|
|
|
+ diff = this.prev_pageX - ev.pageX;
|
|
|
|
+ if (diff) {
|
|
|
|
+ this.width = ((this.width+diff) > (this.model.get('min_width') || 0)) ? (this.width+diff) : this.model.get('min_width');
|
|
|
|
+ this.prev_pageX = ev.pageX;
|
|
|
|
+ this.setChatBoxWidth(this.width);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ setWidth () {
|
|
|
|
+ // If a custom width is applied (due to drag-resizing),
|
|
|
|
+ // then we need to set the width of the .chatbox element as well.
|
|
|
|
+ if (this.model.get('width')) {
|
|
|
|
+ this.el.style.width = this.model.get('width');
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
setDimensions () {
|
|
setDimensions () {
|
|
// Make sure the chat box has the right height and width.
|
|
// Make sure the chat box has the right height and width.
|
|
this.adjustToViewport();
|
|
this.adjustToViewport();
|
|
@@ -165,7 +215,6 @@ converse.plugins.add('converse-dragresize', {
|
|
},
|
|
},
|
|
|
|
|
|
setChatBoxHeight (height) {
|
|
setChatBoxHeight (height) {
|
|
- const { _converse } = this.__super__;
|
|
|
|
if (height) {
|
|
if (height) {
|
|
height = _converse.applyDragResistance(height, this.model.get('default_height'))+'px';
|
|
height = _converse.applyDragResistance(height, this.model.get('default_height'))+'px';
|
|
} else {
|
|
} else {
|
|
@@ -178,7 +227,6 @@ converse.plugins.add('converse-dragresize', {
|
|
},
|
|
},
|
|
|
|
|
|
setChatBoxWidth (width) {
|
|
setChatBoxWidth (width) {
|
|
- const { _converse } = this.__super__;
|
|
|
|
if (width) {
|
|
if (width) {
|
|
width = _converse.applyDragResistance(width, this.model.get('default_width'))+'px';
|
|
width = _converse.applyDragResistance(width, this.model.get('default_width'))+'px';
|
|
} else {
|
|
} else {
|
|
@@ -208,7 +256,6 @@ converse.plugins.add('converse-dragresize', {
|
|
},
|
|
},
|
|
|
|
|
|
onStartVerticalResize (ev) {
|
|
onStartVerticalResize (ev) {
|
|
- const { _converse } = this.__super__;
|
|
|
|
if (!_converse.allow_dragresize) { return true; }
|
|
if (!_converse.allow_dragresize) { return true; }
|
|
// Record element attributes for mouseMove().
|
|
// Record element attributes for mouseMove().
|
|
const flyout = this.el.querySelector('.box-flyout'),
|
|
const flyout = this.el.querySelector('.box-flyout'),
|
|
@@ -222,7 +269,6 @@ converse.plugins.add('converse-dragresize', {
|
|
},
|
|
},
|
|
|
|
|
|
onStartHorizontalResize (ev) {
|
|
onStartHorizontalResize (ev) {
|
|
- const { _converse } = this.__super__;
|
|
|
|
if (!_converse.allow_dragresize) { return true; }
|
|
if (!_converse.allow_dragresize) { return true; }
|
|
const flyout = this.el.querySelector('.box-flyout'),
|
|
const flyout = this.el.querySelector('.box-flyout'),
|
|
style = window.getComputedStyle(flyout);
|
|
style = window.getComputedStyle(flyout);
|
|
@@ -235,116 +281,13 @@ converse.plugins.add('converse-dragresize', {
|
|
},
|
|
},
|
|
|
|
|
|
onStartDiagonalResize (ev) {
|
|
onStartDiagonalResize (ev) {
|
|
- const { _converse } = this.__super__;
|
|
|
|
this.onStartHorizontalResize(ev);
|
|
this.onStartHorizontalResize(ev);
|
|
this.onStartVerticalResize(ev);
|
|
this.onStartVerticalResize(ev);
|
|
_converse.resizing.direction = 'topleft';
|
|
_converse.resizing.direction = 'topleft';
|
|
},
|
|
},
|
|
|
|
+ };
|
|
|
|
+ Object.assign(_converse.ChatBoxView.prototype, dragResizable);
|
|
|
|
|
|
- resizeChatBox (ev) {
|
|
|
|
- let diff;
|
|
|
|
- const { _converse } = this.__super__;
|
|
|
|
- if (_converse.resizing.direction.indexOf('top') === 0) {
|
|
|
|
- diff = ev.pageY - this.prev_pageY;
|
|
|
|
- if (diff) {
|
|
|
|
- this.height = ((this.height-diff) > (this.model.get('min_height') || 0)) ? (this.height-diff) : this.model.get('min_height');
|
|
|
|
- this.prev_pageY = ev.pageY;
|
|
|
|
- this.setChatBoxHeight(this.height);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (_.includes(_converse.resizing.direction, 'left')) {
|
|
|
|
- diff = this.prev_pageX - ev.pageX;
|
|
|
|
- if (diff) {
|
|
|
|
- this.width = ((this.width+diff) > (this.model.get('min_width') || 0)) ? (this.width+diff) : this.model.get('min_width');
|
|
|
|
- this.prev_pageX = ev.pageX;
|
|
|
|
- this.setChatBoxWidth(this.width);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- HeadlinesBoxView: {
|
|
|
|
- events: {
|
|
|
|
- 'mousedown .dragresize-top': 'onStartVerticalResize',
|
|
|
|
- 'mousedown .dragresize-left': 'onStartHorizontalResize',
|
|
|
|
- 'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- initialize () {
|
|
|
|
- window.addEventListener('resize', _.debounce(this.setDimensions.bind(this), 100));
|
|
|
|
- return this.__super__.initialize.apply(this, arguments);
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- render () {
|
|
|
|
- const result = this.__super__.render.apply(this, arguments);
|
|
|
|
- renderDragResizeHandles(this.__super__._converse, this);
|
|
|
|
- this.setWidth();
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- ControlBoxView: {
|
|
|
|
- events: {
|
|
|
|
- 'mousedown .dragresize-top': 'onStartVerticalResize',
|
|
|
|
- 'mousedown .dragresize-left': 'onStartHorizontalResize',
|
|
|
|
- 'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- initialize () {
|
|
|
|
- window.addEventListener('resize', _.debounce(this.setDimensions.bind(this), 100));
|
|
|
|
- this.__super__.initialize.apply(this, arguments);
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- render () {
|
|
|
|
- const result = this.__super__.render.apply(this, arguments);
|
|
|
|
- renderDragResizeHandles(this.__super__._converse, this);
|
|
|
|
- this.setWidth();
|
|
|
|
- return result;
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- renderLoginPanel () {
|
|
|
|
- const result = this.__super__.renderLoginPanel.apply(this, arguments);
|
|
|
|
- this.initDragResize().setDimensions();
|
|
|
|
- return result;
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- renderControlBoxPane () {
|
|
|
|
- const result = this.__super__.renderControlBoxPane.apply(this, arguments);
|
|
|
|
- this.initDragResize().setDimensions();
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- ChatRoomView: {
|
|
|
|
- events: {
|
|
|
|
- 'mousedown .dragresize-top': 'onStartVerticalResize',
|
|
|
|
- 'mousedown .dragresize-left': 'onStartHorizontalResize',
|
|
|
|
- 'mousedown .dragresize-topleft': 'onStartDiagonalResize'
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- initialize () {
|
|
|
|
- window.addEventListener('resize', _.debounce(this.setDimensions.bind(this), 100));
|
|
|
|
- this.__super__.initialize.apply(this, arguments);
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- render () {
|
|
|
|
- const result = this.__super__.render.apply(this, arguments);
|
|
|
|
- renderDragResizeHandles(this.__super__._converse, this);
|
|
|
|
- this.setWidth();
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- initialize () {
|
|
|
|
- /* The initialize function gets called as soon as the plugin is
|
|
|
|
- * loaded by converse.js's plugin machinery.
|
|
|
|
- */
|
|
|
|
- const { _converse } = this;
|
|
|
|
-
|
|
|
|
- _converse.api.settings.update({
|
|
|
|
- allow_dragresize: true,
|
|
|
|
- });
|
|
|
|
|
|
|
|
_converse.applyDragResistance = function (value, default_value) {
|
|
_converse.applyDragResistance = function (value, default_value) {
|
|
/* This method applies some resistance around the
|
|
/* This method applies some resistance around the
|
|
@@ -363,6 +306,45 @@ converse.plugins.add('converse-dragresize', {
|
|
}
|
|
}
|
|
return value;
|
|
return value;
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /************************ BEGIN Event Handlers ************************/
|
|
|
|
+ function registerGlobalEventHandlers () {
|
|
|
|
+
|
|
|
|
+ document.addEventListener('mousemove', function (ev) {
|
|
|
|
+ if (!_converse.resizing || !_converse.allow_dragresize) { return true; }
|
|
|
|
+ ev.preventDefault();
|
|
|
|
+ _converse.resizing.chatbox.resizeChatBox(ev);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ document.addEventListener('mouseup', function (ev) {
|
|
|
|
+ if (!_converse.resizing || !_converse.allow_dragresize) { return true; }
|
|
|
|
+ ev.preventDefault();
|
|
|
|
+ const height = _converse.applyDragResistance(
|
|
|
|
+ _converse.resizing.chatbox.height,
|
|
|
|
+ _converse.resizing.chatbox.model.get('default_height')
|
|
|
|
+ );
|
|
|
|
+ const width = _converse.applyDragResistance(
|
|
|
|
+ _converse.resizing.chatbox.width,
|
|
|
|
+ _converse.resizing.chatbox.model.get('default_width')
|
|
|
|
+ );
|
|
|
|
+ if (_converse.connection.connected) {
|
|
|
|
+ _converse.resizing.chatbox.model.save({'height': height});
|
|
|
|
+ _converse.resizing.chatbox.model.save({'width': width});
|
|
|
|
+ } else {
|
|
|
|
+ _converse.resizing.chatbox.model.set({'height': height});
|
|
|
|
+ _converse.resizing.chatbox.model.set({'width': width});
|
|
|
|
+ }
|
|
|
|
+ _converse.resizing = null;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ _converse.api.listen.on('registeredGlobalEventHandlers', registerGlobalEventHandlers);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ _converse.api.listen.on('chatBoxInitialized', view => {
|
|
|
|
+ window.addEventListener('resize', _.debounce(() => view.setDimensions(), 100));
|
|
|
|
+ });
|
|
|
|
+ /************************ END Event Handlers ************************/
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|