Start Issue 258: dirt-simple extension of a context button to close/open a path. Needs images. And paths that were closed and then opened need some debugging in svgcanvas.js

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1366 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-02-09 21:46:18 +00:00
parent 9df43ee7ba
commit 3ee6a57b96
3 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,75 @@
/*
* ext-closepath.js
*
* Licensed under the Apache License, Version 2
*
* Copyright(c) 2010 Jeff Schiller
*
*/
// This extension adds a simple button to the contextual panel for paths
// The button toggles whether the path is open or closed
$(function() {
svgCanvas.addExtension("ClosePath", function(S) {
var selElems,
updateButton = function(path) {
var seglist = path.pathSegList,
button = $('#closepath_panel > div.tool_button')[0];
$(button).html(seglist.getItem(seglist.numberOfItems - 1).pathSegType==1 ? "open":"close");
},
showPanel = function(on) {
$('#closepath_panel').toggle(on);
if (on) {
var path = selElems[0];
if (path) updateButton(path);
}
},
toggleClosed = function() {
var path = selElems[0];
if (path) {
var seglist = path.pathSegList,
last = seglist.numberOfItems - 1;
// is closed
if(seglist.getItem(last).pathSegType == 1) {
seglist.removeItem(last);
}
else {
seglist.appendItem(path.createSVGPathSegClosePath());
}
updateButton(path);
}
};
return {
name: "ClosePath",
context_tools: [{
type: "tool_button",
panel: "closepath_panel",
title: "Open or Close path",
id: "close",
events: { mousedown: toggleClosed }
}],
callback: function() {
$('#closepath_panel').hide();
},
selectedChanged: function(opts) {
selElems = opts.elems;
var i = selElems.length;
while(i--) {
var elem = selElems[i];
if(elem && elem.tagName == 'path') {
if(opts.selectedElement && !opts.multiselected) {
showPanel(true);
} else {
showPanel(false);
}
} else {
showPanel(false);
}
}
},
};
});
});

View File

@ -18,6 +18,7 @@
<script type="text/javascript" src="locale/locale.js"></script>
<script type="text/javascript" src="svgcanvas.js"></script>
<script type="text/javascript" src="svg-editor.js"></script>
<script type="text/javascript" src="extensions/ext-closepath.js"></script>
<script type="text/javascript" src="extensions/ext-arrows.js"></script>
<script type="text/javascript" src="extensions/ext-connector.js"></script>

View File

@ -540,6 +540,15 @@ function svg_edit_setup() {
// TODO: Allow support for other types, or adding to existing tool
switch (tool.type) {
case 'tool_button':
var html = '<div class="tool_button">' + tool.id + '</div>';
var div = $(html).appendTo(panel);
if (tool.events) {
$.each(tool.events, function(evt, func) {
$(div).bind(evt, func);
});
}
break;
case 'select':
var html = '<label' + cont_id + '>'
+ '<select id="' + tool.id + '">';