Skip to content

Commit

Permalink
feat: add en/disableEdit() method
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoudejie committed Sep 10, 2019
1 parent a16eab8 commit c86a89e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let mind = new MindElixir({
data: MindElixir.example,
locale: 'en',
draggable: true,
editable: true,
contextMenu: true,
toolBar: true,
nodeMenu: true,
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
initRight,
initSide,
setLocale,
enableEdit,
disableEdit,
} from './interact'
import {
insertSibling,
Expand Down Expand Up @@ -77,6 +79,7 @@ let $d = document
direction: 2,
data: data,
draggable: true,
editable: true,
contextMenu: true,
toolBar: true,
nodeMenu: true,
Expand All @@ -91,6 +94,7 @@ function MindElixir({
direction,
locale,
draggable,
editable,
contextMenu,
toolBar,
nodeMenu,
Expand All @@ -110,6 +114,7 @@ function MindElixir({
// record the direction before enter focus mode, must true in focus mode, reset to null after exit focus
this.direction = typeof direction === 'number' ? direction : 1
window.mevar_draggable = draggable === undefined ? true : draggable
this.editable = editable === undefined ? true : editable
this.parentMap = {} // deprecate?

this.currentNode = null // the selected <tpc/> element
Expand Down Expand Up @@ -170,6 +175,8 @@ MindElixir.prototype = {
initRight,
initSide,
setLocale,
enableEdit,
disableEdit,

init: function() {
this.container.className = 'map-container'
Expand Down
21 changes: 21 additions & 0 deletions src/interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ export let getAllData = function() {
})
)
}

/**
* @function
* @instance
* @name enableEdit
* @memberof MapInteraction
*/
export let enableEdit = function() {
this.editable = true
}

/**
* @function
* @instance
* @name disableEdit
* @memberof MapInteraction
*/
export let disableEdit = function() {
this.editable = false
}

/**
* @function
* @instance
Expand Down
1 change: 1 addition & 0 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function(mind) {

mind.map.addEventListener('dblclick', e => {
e.preventDefault()
if (!mind.editable) return
if (
e.target.parentElement.nodeName === 'T' ||
e.target.parentElement.nodeName === 'ROOT'
Expand Down

0 comments on commit c86a89e

Please sign in to comment.