diff --git a/editor/src/index.js b/editor/src/index.js index 0c143e6..ea77bd9 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -9,7 +9,6 @@ import search from './search'; import createPageSearch from './fuse'; import util from './util'; import Mustache from 'mustache'; -import 'jquery-contextmenu'; import getCaretCoordinates from './caret-position' import moment from 'moment' import mermaid from 'mermaid' @@ -22,7 +21,7 @@ import 'prismjs/components/prism-perl' import 'prismjs/components/prism-css' import 'prismjs/components/prism-markup-templating' import 'prismjs/components/prism-jq' - +import menu from './menu.js' import './styles.scss' moment.locale('nl') @@ -450,19 +449,8 @@ if (holder) { renderGraphs(); }) }) - $.contextMenu({ - selector: '.marker', - items: { - copy: { - name: 'Copy', - callback: function (key, opt) { - editor.copy(this).then(result => { - console.log(result) - }) - } - } - } - }); + + menu.connectContextMenu(editor) } let timeout = null; diff --git a/editor/src/menu.js b/editor/src/menu.js new file mode 100644 index 0000000..b5fc4e4 --- /dev/null +++ b/editor/src/menu.js @@ -0,0 +1,44 @@ +import $ from 'jquery' +import 'jquery-contextmenu' + +function buildContextMenu(editor, store) { + return function (triggeringElement, event) { + return { + items: { + createNewPage: { + name: 'Create page from item', + callback: function (key, opt) { + console.log('Create page from item', key, opt) + } + }, + copy: { + name: 'Copy', + callback: function (key, opt) { + editor.copy(this, {recursive: true}).then(result => { + console.log(result) + }) + } + }, + copyLine: { + name: 'Copy line', + callback: function (key, opt) { + editor.copy(this, {recursive: false}).then(result => { + console.log(result) + }) + } + } + } + } + } +} + +function connectContextMenu(editor) { + $.contextMenu({ + selector: '.marker', + build: buildContextMenu(editor), + }); +} + +export default { + connectContextMenu: connectContextMenu +}