|
@@ -3,7 +3,7 @@ import { api } from '@converse/headless';
|
|
import { applyDragResistance, getResizingDirection } from './utils.js';
|
|
import { applyDragResistance, getResizingDirection } from './utils.js';
|
|
|
|
|
|
const DragResizableMixin = {
|
|
const DragResizableMixin = {
|
|
- initDragResize () {
|
|
|
|
|
|
+ initDragResize() {
|
|
const debouncedSetDimensions = debounce(() => this.setDimensions());
|
|
const debouncedSetDimensions = debounce(() => this.setDimensions());
|
|
window.addEventListener('resize', debouncedSetDimensions);
|
|
window.addEventListener('resize', debouncedSetDimensions);
|
|
this.listenTo(this.model, 'destroy', () => window.removeEventListener('resize', debouncedSetDimensions));
|
|
this.listenTo(this.model, 'destroy', () => window.removeEventListener('resize', debouncedSetDimensions));
|
|
@@ -35,15 +35,29 @@ const DragResizableMixin = {
|
|
return this;
|
|
return this;
|
|
},
|
|
},
|
|
|
|
|
|
- resizeChatBox (ev) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param {MouseEvent} ev
|
|
|
|
+ */
|
|
|
|
+ resizeChatBox(ev) {
|
|
let diff;
|
|
let diff;
|
|
const direction = getResizingDirection();
|
|
const direction = getResizingDirection();
|
|
if (direction.indexOf('top') === 0) {
|
|
if (direction.indexOf('top') === 0) {
|
|
|
|
+ const margin = api.settings.get('dragresize_top_margin') ?? 0;
|
|
|
|
+ const max_height = window.innerHeight - margin;
|
|
diff = ev.pageY - this.prev_pageY;
|
|
diff = ev.pageY - this.prev_pageY;
|
|
|
|
+
|
|
if (diff) {
|
|
if (diff) {
|
|
|
|
+
|
|
|
|
+ const new_height = this.height - diff;
|
|
|
|
+ console.log('------------');
|
|
|
|
+ console.log(`window.innerHeight: ${window.innerHeight}`);
|
|
|
|
+ console.log(`max_height: ${max_height}`);
|
|
|
|
+ console.log(`new_height: ${new_height}`);
|
|
|
|
+ console.log(`diff: ${diff}`);
|
|
|
|
+
|
|
this.height =
|
|
this.height =
|
|
this.height - diff > (this.model.get('min_height') || 0)
|
|
this.height - diff > (this.model.get('min_height') || 0)
|
|
- ? this.height - diff
|
|
|
|
|
|
+ ? (new_height <= max_height ? new_height : max_height)
|
|
: this.model.get('min_height');
|
|
: this.model.get('min_height');
|
|
this.prev_pageY = ev.pageY;
|
|
this.prev_pageY = ev.pageY;
|
|
this.setChatBoxHeight(this.height);
|
|
this.setChatBoxHeight(this.height);
|
|
@@ -62,7 +76,7 @@ const DragResizableMixin = {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- 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();
|
|
this.setChatBoxWidth(this.model.get('width'));
|
|
this.setChatBoxWidth(this.model.get('width'));
|
|
@@ -71,32 +85,28 @@ const DragResizableMixin = {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- setChatBoxHeight (height) {
|
|
|
|
- if (height) {
|
|
|
|
- height = applyDragResistance(height, this.model.get('default_height')) + 'px';
|
|
|
|
- } else {
|
|
|
|
- height = '';
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param {number} height
|
|
|
|
+ */
|
|
|
|
+ setChatBoxHeight(height) {
|
|
const flyout_el = this.querySelector('.box-flyout');
|
|
const flyout_el = this.querySelector('.box-flyout');
|
|
if (flyout_el !== null) {
|
|
if (flyout_el !== null) {
|
|
- flyout_el.style.height = height;
|
|
|
|
|
|
+ flyout_el.style.height = height ? applyDragResistance(height, this.model.get('default_height')) + 'px' : '';
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- setChatBoxWidth (width) {
|
|
|
|
- if (width) {
|
|
|
|
- width = applyDragResistance(width, this.model.get('default_width')) + 'px';
|
|
|
|
- } else {
|
|
|
|
- width = '';
|
|
|
|
- }
|
|
|
|
- this.style.width = width;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param {number} width
|
|
|
|
+ */
|
|
|
|
+ setChatBoxWidth(width) {
|
|
|
|
+ this.style.width = width ? applyDragResistance(width, this.model.get('default_width')) + 'px' : '';
|
|
const flyout_el = this.querySelector('.box-flyout');
|
|
const flyout_el = this.querySelector('.box-flyout');
|
|
if (flyout_el !== null) {
|
|
if (flyout_el !== null) {
|
|
flyout_el.style.width = width;
|
|
flyout_el.style.width = width;
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- adjustToViewport () {
|
|
|
|
|
|
+ adjustToViewport() {
|
|
/* Event handler called when viewport gets resized. We remove
|
|
/* Event handler called when viewport gets resized. We remove
|
|
* custom width/height from chat boxes.
|
|
* custom width/height from chat boxes.
|
|
*/
|
|
*/
|
|
@@ -110,7 +120,7 @@ const DragResizableMixin = {
|
|
} else if (viewport_height <= this.model.get('height')) {
|
|
} else if (viewport_height <= this.model.get('height')) {
|
|
this.model.set('height', undefined);
|
|
this.model.set('height', undefined);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ },
|
|
};
|
|
};
|
|
|
|
|
|
export default DragResizableMixin;
|
|
export default DragResizableMixin;
|