* Enable/disable dragging the whole canvas with mouse. * @param {boolean} enabled
(enabled)
| 729 | * @param {boolean} enabled |
| 730 | */ |
| 731 | setup_canvas_draggable(enabled) { |
| 732 | this.opts.draggable = enabled; |
| 733 | if (!this._initialized) { |
| 734 | let dragging = false; |
| 735 | let x, y; |
| 736 | if (this.opts.hide_scrollbars_when_draggable) { |
| 737 | // Avoid scrollbars when mind map is larger than the container (e_panel = id jsmind-inner) |
| 738 | this.e_panel.style = 'overflow: hidden'; |
| 739 | } |
| 740 | // Move the whole mind map with mouse moves, while button is down. |
| 741 | $.on(this.container, 'mousedown', eventDown => { |
| 742 | if (this.opts.draggable) { |
| 743 | dragging = true; |
| 744 | // Record current mouse position. |
| 745 | x = eventDown.clientX; |
| 746 | y = eventDown.clientY; |
| 747 | } |
| 748 | }); |
| 749 | // Stop moving mind map once mouse button is released. |
| 750 | $.on(this.container, 'mouseup', () => { |
| 751 | dragging = false; |
| 752 | }); |
| 753 | // Follow current mouse position and move mind map accordingly. |
| 754 | $.on(this.container, 'mousemove', eventMove => { |
| 755 | if (this.opts.draggable) { |
| 756 | if (dragging) { |
| 757 | this.e_panel.scrollBy(x - eventMove.clientX, y - eventMove.clientY); |
| 758 | // Record new current position. |
| 759 | x = eventMove.clientX; |
| 760 | y = eventMove.clientY; |
| 761 | } |
| 762 | } |
| 763 | }); |
| 764 | } |
| 765 | } |
| 766 | /** @param {import('./jsmind.node.js').Node} node */ |
| 767 | center_node(node) { |
| 768 | if (!this.layout.is_visible(node)) { |
no outgoing calls
no test coverage detected