fixed formatting in closepath extension

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2406 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Bruno Heridet 2013-02-16 11:19:25 +00:00
parent 424bf3001b
commit 6b23a26b82
1 changed files with 68 additions and 71 deletions

View File

@ -9,11 +9,11 @@
// This extension adds a simple button to the contextual panel for paths // This extension adds a simple button to the contextual panel for paths
// The button toggles whether the path is open or closed // The button toggles whether the path is open or closed
svgEditor.addExtension("ClosePath", function(S) { svgEditor.addExtension('ClosePath', function() {
var selElems, var selElems,
updateButton = function(path) { updateButton = function(path) {
var seglist = path.pathSegList, var seglist = path.pathSegList,
closed = seglist.getItem(seglist.numberOfItems - 1).pathSegType==1, closed = seglist.getItem(seglist.numberOfItems - 1).pathSegType == 1,
showbutton = closed ? '#tool_openpath' : '#tool_closepath', showbutton = closed ? '#tool_openpath' : '#tool_closepath',
hidebutton = closed ? '#tool_closepath' : '#tool_openpath'; hidebutton = closed ? '#tool_closepath' : '#tool_openpath';
$(hidebutton).hide(); $(hidebutton).hide();
@ -26,17 +26,15 @@ svgEditor.addExtension("ClosePath", function(S) {
if (path) updateButton(path); if (path) updateButton(path);
} }
}, },
toggleClosed = function() { toggleClosed = function() {
var path = selElems[0]; var path = selElems[0];
if (path) { if (path) {
var seglist = path.pathSegList, var seglist = path.pathSegList,
last = seglist.numberOfItems - 1; last = seglist.numberOfItems - 1;
// is closed // is closed
if(seglist.getItem(last).pathSegType == 1) { if (seglist.getItem(last).pathSegType == 1) {
seglist.removeItem(last); seglist.removeItem(last);
} } else {
else {
seglist.appendItem(path.createSVGPathSegClosePath()); seglist.appendItem(path.createSVGPathSegClosePath());
} }
updateButton(path); updateButton(path);
@ -44,26 +42,26 @@ svgEditor.addExtension("ClosePath", function(S) {
}; };
return { return {
name: "ClosePath", name: 'ClosePath',
svgicons: "extensions/closepath_icons.svg", svgicons: 'extensions/closepath_icons.svg',
buttons: [{ buttons: [{
id: "tool_openpath", id: 'tool_openpath',
type: "context", type: 'context',
panel: "closepath_panel", panel: 'closepath_panel',
title: "Open path", title: 'Open path',
events: { events: {
'click': function() { click: function() {
toggleClosed(); toggleClosed();
} }
} }
}, },
{ {
id: "tool_closepath", id: 'tool_closepath',
type: "context", type: 'context',
panel: "closepath_panel", panel: 'closepath_panel',
title: "Close path", title: 'Close path',
events: { events: {
'click': function() { click: function() {
toggleClosed(); toggleClosed();
} }
} }
@ -74,11 +72,10 @@ svgEditor.addExtension("ClosePath", function(S) {
selectedChanged: function(opts) { selectedChanged: function(opts) {
selElems = opts.elems; selElems = opts.elems;
var i = selElems.length; var i = selElems.length;
while (i--) {
while(i--) {
var elem = selElems[i]; var elem = selElems[i];
if(elem && elem.tagName == 'path') { if (elem && elem.tagName == 'path') {
if(opts.selectedElement && !opts.multiselected) { if (opts.selectedElement && !opts.multiselected) {
showPanel(true); showPanel(true);
} else { } else {
showPanel(false); showPanel(false);