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,84 +9,81 @@
// 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();
$(showbutton).show(); $(showbutton).show();
}, },
showPanel = function(on) { showPanel = function(on) {
$('#closepath_panel').toggle(on); $('#closepath_panel').toggle(on);
if (on) { if (on) {
var path = selElems[0];
if (path) updateButton(path);
}
},
toggleClosed = function() {
var path = selElems[0]; var path = selElems[0];
if (path) { if (path) updateButton(path);
var seglist = path.pathSegList, }
last = seglist.numberOfItems - 1; },
// is closed toggleClosed = function() {
if(seglist.getItem(last).pathSegType == 1) { var path = selElems[0];
seglist.removeItem(last); if (path) {
} var seglist = path.pathSegList,
else { last = seglist.numberOfItems - 1;
seglist.appendItem(path.createSVGPathSegClosePath()); // is closed
} if (seglist.getItem(last).pathSegType == 1) {
updateButton(path); seglist.removeItem(last);
} else {
seglist.appendItem(path.createSVGPathSegClosePath());
} }
}; updateButton(path);
}
};
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", {
type: "context", id: 'tool_closepath',
panel: "closepath_panel", type: 'context',
title: "Close path", panel: 'closepath_panel',
events: { title: 'Close path',
'click': function() { events: {
toggleClosed(); click: function() {
} toggleClosed();
} }
}], }
callback: function() { }],
$('#closepath_panel').hide(); callback: function() {
}, $('#closepath_panel').hide();
selectedChanged: function(opts) { },
selElems = opts.elems; selectedChanged: function(opts) {
var i = selElems.length; selElems = opts.elems;
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 {
showPanel(false);
}
} else { } else {
showPanel(false); showPanel(false);
} }
} else {
showPanel(false);
} }
} }
}; }
};
}); });