| 1 |
function closeContextMenu() { |
| 2 |
var g = getE('cMenu'); |
| 3 |
g && g.parentNode.removeChild(g); |
| 4 |
} |
| 5 |
function setContextMenu(de,t,e) { |
| 6 |
var te, g, mh = 0, mw = {$number:min_width}, link, text, line = 0, |
| 7 |
bb, r, pos = svgCursorCoords(e,de), x = pos[0], y = pos[1], |
| 8 |
spacing = {$number:spacing}, |
| 9 |
shadow, shadow_opacity = {$number:shadow_opacity}, target = '{$string:link_target}'; |
| 10 |
g = newel('g', { id: 'cMenu', 'font-size': {$number:font_size}, 'font-family': |
| 11 |
'{$string:font}', 'font-weight': '{$string:font_weight}', fill:'{$string:colour}'}); |
| 12 |
for(te in t) { |
| 13 |
text = newel('text', { x: '0px', y: '0px' }); |
| 14 |
text.appendChild(newtext(t[te][0])); |
| 15 |
g.appendChild(text); |
| 16 |
de.appendChild(g); |
| 17 |
bb = text.getBBox(); |
| 18 |
de.removeChild(g); |
| 19 |
g.removeChild(text); |
| 20 |
if(bb.width > mw) |
| 21 |
mw = bb.width; |
| 22 |
} |
| 23 |
for(te in t) { |
| 24 |
text = newel('text', { x: {$number:pad_x} + 'px', y: ({$number:text_start} + line * spacing) + 'px' }); |
| 25 |
text.appendChild(newtext(t[te][0])); |
| 26 |
if(t[te][1]) { |
| 27 |
link = newel('a', { 'fill' : '{$string:link_colour}'{$string:underline_part} }); |
| 28 |
link.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', t[te][1]); |
| 29 |
target && setattr(link, 'target', target); |
| 30 |
r = newel('rect', { x: {$number:pad_x} + 'px', y: ({$number:rect_start} + line * spacing) + 'px', |
| 31 |
width: mw + 'px', height: spacing + 'px', fill: '#000', opacity: 0}); |
| 32 |
link.appendChild(r); |
| 33 |
link.appendChild(text); |
| 34 |
g.appendChild(link); |
| 35 |
link.addEventListener('mouseover', function(e) { |
| 36 |
setattr(this, 'fill', '{$string:link_hover_colour}'); |
| 37 |
setattr(this.querySelector('rect'), 'opacity', 0.1); |
| 38 |
}); |
| 39 |
link.addEventListener('mouseout', function(e) { |
| 40 |
setattr(this, 'fill', '{$string:link_colour}'); |
| 41 |
setattr(this.querySelector('rect'), 'opacity', 0); |
| 42 |
}); |
| 43 |
} else { |
| 44 |
g.appendChild(text); |
| 45 |
} |
| 46 |
++line; |
| 47 |
} |
| 48 |
mw += {$number:pad_x} * 2; |
| 49 |
mh = (line * spacing) + {$number:pad_y} * 2; |
| 50 |
r = newel('rect', { x: '0px', y: '0px', width: mw + 'px', height: mh + 'px', |
| 51 |
'stroke-width': {$number:stroke_width} + 'px', |
| 52 |
fill: '{$string:back_colour}', stroke: '{$string:colour}'{$string:round_part}}); |
| 53 |
g.insertBefore(r, g.childNodes[0]); |
| 54 |
x = Math.min(de.width.baseVal.value - mw - {$number:off_right},x); |
| 55 |
y = (de.height.baseVal.value - mh - {$number:off_bottom} < y ? y - mh : y); |
| 56 |
if(shadow_opacity > 0) { |
| 57 |
shadow = newel('rect',{ fill: '#000', opacity: {$number:shadow_opacity}, |
| 58 |
'stroke-width': {$number:stroke_width} + 'px', stroke: '#000'{$string:round_part}, |
| 59 |
x:'{$number:cmoffs}px',y:'{$number:cmoffs}px', width: mw + 'px', height: mh + 'px'}); |
| 60 |
g.insertBefore(shadow, g.childNodes[0]); |
| 61 |
} |
| 62 |
setattr(g, 'transform', 'translate(' + x + ',' + y + ')'); |
| 63 |
de.appendChild(g); |
| 64 |
} |
| 65 |
function contextMenuInit() { |
| 66 |
var c, e, nn = '{$string:namespace}svg'; |
| 67 |
for(c in menus) { |
| 68 |
e = getE(c); |
| 69 |
e && e.addEventListener && e.addEventListener('contextmenu', function(e) { |
| 70 |
e.preventDefault(); |
| 71 |
e.stopPropagation(); |
| 72 |
var t = finditem(e,menus), de = svgNode(e,1), g = getE('cMenu'); |
| 73 |
g && g.parentNode.removeChild(g); |
| 74 |
setContextMenu(de,t,e); |
| 75 |
return false; |
| 76 |
},false); |
| 77 |
} |
| 78 |
e = document.querySelectorAll(nn); |
| 79 |
for(c = 0; c < e.length; ++c) { |
| 80 |
e[c].addEventListener('click', closeContextMenu, false); |
| 81 |
{$string:mouseleave} |
| 82 |
e[c].addEventListener('keydown', function(e) { |
| 83 |
if(e.keyCode == 27) |
| 84 |
closeContextMenu(); |
| 85 |
},false); |
| 86 |
e[c].addEventListener('contextmenu', rootContextMenu, false); |
| 87 |
} |
| 88 |
} |
| 89 |
|