FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Method-Draw/method-draw/lib/contextmenu.js at master · folkcode/Method-Draw · GitHub
folkcode
/
Method-Draw
Public
forked from
methodofaction/Method-Draw
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Method-Draw
/
method-draw
/
lib
/
contextmenu.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (65 loc) · 2.64 KB
Breadcrumbs
Method-Draw
/
method-draw
/
lib
/
contextmenu.js
Copy path
File metadata and controls
68 lines (65 loc) · 2.64 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Package: svgedit.contextmenu
*
* Licensed under the Apache License, Version 2
*
* Author: Adam Bender
*/
// Dependencies:
// 1) jQuery (for dom injection of context menus)\
var
svgedit
=
svgedit
||
{
}
;
(
function
(
)
{
var
self
=
this
;
if
(
!
svgedit
.
contextmenu
)
{
svgedit
.
contextmenu
=
{
}
;
}
self
.
contextMenuExtensions
=
{
}
var
addContextMenuItem
=
function
(
menuItem
)
{
// menuItem: {id, label, shortcut, action}
if
(
!
menuItemIsValid
(
menuItem
)
)
{
console
.
error
(
"Menu items must be defined and have at least properties: id, label, action, where action must be a function"
)
;
return
;
}
if
(
menuItem
.
id
in
self
.
contextMenuExtensions
)
{
console
.
error
(
'Cannot add extension "'
+
menuItem
.
id
+
'", an extension by that name already exists"'
)
;
return
;
}
// Register menuItem action, see below for deferred menu dom injection
console
.
log
(
"Registed contextmenu item: {id:"
+
menuItem
.
id
+
", label:"
+
menuItem
.
label
+
"}"
)
;
self
.
contextMenuExtensions
[
menuItem
.
id
]
=
menuItem
;
//TODO: Need to consider how to handle custom enable/disable behavior
}
var
hasCustomHandler
=
function
(
handlerKey
)
{
return
self
.
contextMenuExtensions
[
handlerKey
]
&&
true
;
}
var
getCustomHandler
=
function
(
handlerKey
)
{
return
self
.
contextMenuExtensions
[
handlerKey
]
.
action
;
}
var
injectExtendedContextMenuItemIntoDom
=
function
(
menuItem
)
{
if
(
Object
.
keys
(
self
.
contextMenuExtensions
)
.
length
==
0
)
{
// all menuItems appear at the bottom of the menu in their own container.
// if this is the first extension menu we need to add the separator.
$
(
"#cmenu_canvas"
)
.
append
(
"<li class='separator'>"
)
;
}
var
shortcut
=
menuItem
.
shortcut
||
""
;
$
(
"#cmenu_canvas"
)
.
append
(
"<li class='disabled'><a href='#"
+
menuItem
.
id
+
"'>"
+
menuItem
.
label
+
"<span class='shortcut'>"
+
shortcut
+
"</span></a></li>"
)
;
}
var
menuItemIsValid
=
function
(
menuItem
)
{
return
menuItem
&&
menuItem
.
id
&&
menuItem
.
label
&&
menuItem
.
action
&&
typeof
menuItem
.
action
==
'function'
;
}
// Defer injection to wait out initial menu processing. This probably goes away once all context
// menu behavior is brought here.
methodDraw
.
ready
(
function
(
)
{
for
(
menuItem
in
contextMenuExtensions
)
{
injectExtendedContextMenuItemIntoDom
(
contextMenuExtensions
[
menuItem
]
)
;
}
}
)
;
svgedit
.
contextmenu
.
resetCustomMenus
=
function
(
)
{
self
.
contextMenuExtensions
=
{
}
}
svgedit
.
contextmenu
.
add
=
addContextMenuItem
;
svgedit
.
contextmenu
.
hasCustomHandler
=
hasCustomHandler
;
svgedit
.
contextmenu
.
getCustomHandler
=
getCustomHandler
;
}
)
(
)
;
Back
|
FazBrowse Home
|
New Git URL