diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 997797b8..96e5ee0a 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -382,7 +382,7 @@ function svg_edit_setup() { } var extAdded = function(window, ext) { - if("buttons" in ext) { + if(ext.buttons) { var fallback_obj = {}, placement_obj = {}, svgicons = ext.svgicons; @@ -518,6 +518,28 @@ function svg_edit_setup() { }); } + if(ext.context_panels) { + $.each(ext.context_panels, function(i, panel) { + // Add select panel + + // TODO: Allow support for other types, or adding to existing panel + if(panel.type == "select") { + var html = '
"; + // Creates the panel, hides & adds it, returns the select element + var sel = $(html).hide().appendTo("#tools_top").find("select"); + $.each(panel.events, function(evt, func) { + $(sel).bind(evt, func); + }); + } + + }); + } }; var getPaint = function(color, opac) { @@ -1864,7 +1886,7 @@ function svg_edit_setup() { var bNoFill = (svgCanvas.getFillColor() == 'none'); var bNoStroke = (svgCanvas.getStrokeColor() == 'none'); var buttonsNeedingStroke = [ '#tool_fhpath', '#tool_line' ]; - var buttonsNeedingFillAndStroke = [ '#tools_rect .tool_button', '#tools_ellipse .tool_button', '#tool_text' ]; + var buttonsNeedingFillAndStroke = [ '#tools_rect .tool_button', '#tools_ellipse .tool_button', '#tool_text', '#tool_path']; if (bNoStroke) { for (index in buttonsNeedingStroke) { var button = buttonsNeedingStroke[index]; diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 6eb4a47e..3516de41 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -984,27 +984,6 @@ function BatchCommand(text) { return result; } - this.addExtension = function(name, ext_func) { - if(!(name in extensions)) { - // Provide constants here (or should these be accessed through getSomething()? - var ext = ext_func({ - content: svgcontent, - root: svgroot, - call: call, - getNextId: getNextId, - getElem: getElem, - addSvgElementFromJson: addSvgElementFromJson, - selectorManager: selectorManager, - findDefs: findDefs, - recalculateDimensions: recalculateDimensions - }); - extensions[name] = ext; - call("extension_added", ext); - } else { - console.log('Cannot add extension "' + name + '", an extension by that name already exists"'); - } - }; - // This method rounds the incoming value to the nearest value based on the current_zoom var round = function(val){ return parseInt(val*current_zoom)/current_zoom; @@ -7439,6 +7418,78 @@ function BatchCommand(text) { // return svgdoc.getElementById(id); } + // Being able to access private methods publicly seems wrong somehow, + // but currently appears to be the best way to allow testing and provide + // access to them to plugins. + this.getPrivateMethods = function() { + return { + addCommandToHistory: addCommandToHistory, + addGradient: addGradient, + addSvgElementFromJson: addSvgElementFromJson, + assignAttributes: assignAttributes, + BatchCommand: BatchCommand, + call: call, + ChangeElementCommand: ChangeElementCommand, + cleanupElement: cleanupElement, + copyElem: copyElem, + ffClone: ffClone, + findDefs: findDefs, + findDuplicateGradient: findDuplicateGradient, + fromXml: fromXml, + getElem: getElem, + getId: getId, + getIntersectionList: getIntersectionList, + getNextId: getNextId, + getPathBBox: getPathBBox, + getUrlFromAttr: getUrlFromAttr, + hasMatrixTransform: hasMatrixTransform, + identifyLayers: identifyLayers, + InsertElementCommand: InsertElementCommand, + isIdentity: isIdentity, + logMatrix: logMatrix, + matrixMultiply: matrixMultiply, + MoveElementCommand: MoveElementCommand, + preventClickDefault: preventClickDefault, + recalculateAllSelectedDimensions: recalculateAllSelectedDimensions, + recalculateDimensions: recalculateDimensions, + remapElement: remapElement, + RemoveElementCommand: RemoveElementCommand, + removeUnusedGrads: removeUnusedGrads, + resetUndoStack: resetUndoStack, + round: round, + runExtensions: runExtensions, + sanitizeSvg: sanitizeSvg, + Selector: Selector, + SelectorManager: SelectorManager, + shortFloat: shortFloat, + svgCanvasToString: svgCanvasToString, + SVGEditTransformList: SVGEditTransformList, + svgToString: svgToString, + toString: toString, + toXml: toXml, + transformBox: transformBox, + transformListToTransform: transformListToTransform, + transformPoint: transformPoint, + transformToObj: transformToObj, + walkTree: walkTree + } + } + + this.addExtension = function(name, ext_func) { + if(!(name in extensions)) { + // Provide private vars/funcs here. Is there a better way to do this? + var ext = ext_func($.extend(canvas.getPrivateMethods(), { + svgroot: svgroot, + svgcontent: svgcontent, + selectorManager: selectorManager + })); + extensions[name] = ext; + call("extension_added", ext); + } else { + console.log('Cannot add extension "' + name + '", an extension by that name already exists"'); + } + }; + // Test support for features/bugs (function() { // segList functions (for FF1.5 and 2.0) diff --git a/extensions/ext-arrows.js b/extensions/ext-arrows.js index 62a33251..97e7ea1b 100644 --- a/extensions/ext-arrows.js +++ b/extensions/ext-arrows.js @@ -9,8 +9,7 @@ $(function() { svgCanvas.addExtension("Arrows", function(S) { - var svgcontent = S.content, - getElem = S.getElem, + var svgcontent = S.svgcontent, addElem = S.addSvgElementFromJson, selElems; @@ -64,7 +63,7 @@ $(function() { function addMarker(id, type) { // TODO: Make marker (or use?) per arrow type, since refX can be different - var marker = getElem(id); + var marker = S.getElem(id); var pathdata = { se_arrow_fw: {d:"m0,0l10,5l-10,5l5,-5l-5,-5z", refx:8}, @@ -104,7 +103,8 @@ $(function() { marker.setAttribute('refX', data.refx); } - function setArrow(type) { + function setArrow() { + var type = this.value; resetMarker(); if(type == "none") { @@ -114,7 +114,6 @@ $(function() { var fw_id = "se_arrow_fw"; var bk_id = "se_arrow_bk"; - // Set marker on element var id = fw_id; if(type == "mid_bk") { @@ -134,24 +133,25 @@ $(function() { S.call("changed", selElems); } - // Init code - (function() { - var conn_tools = $('