2016-03-24 12:52:33 +00:00
# SvgCanvas
The main SvgCanvas class that manages all SVG-related functions
2017-08-03 23:49:39 +00:00
## Parameters
2016-03-24 12:52:33 +00:00
* `container` The container HTML element that should hold the SVG root element
* `config` An object that contains configuration data
2017-08-03 23:49:39 +00:00
## Summary
2016-03-24 12:52:33 +00:00
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### SvgCanvas - The main SvgCanvas class that manages all SVG-related functions
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`Utils.toXml` ](#utilstoxml ) | Converts characters in a string to XML-friendly entities.
[`Utils.fromXml` ](#utilsfromxml ) | Converts XML entities in a string to single characters.
[`Utils.encode64` ](#utilsfromxml ) | Converts a string to base64
[`Utils.decode64` ](#utilsdecode64 ) | Converts a string from base64
[`Utils.convertToXMLReferences` ](#utilsconverttoxmlreferences ) | Converts a string to use XML references
[`rectsIntersect` ](#rectsintersect ) | Check if two rectangles (BBoxes objects) intersect each other
[`snapToAngle` ](#snaptoangle ) | Returns a 45 degree angle coordinate associated with the two given coordinates
[`text2xml` ](#text2xml ) | Cross-browser compatible method of converting a string to an XML tree found this function [here ](http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f )
2017-08-03 23:49:39 +00:00
### Unit conversion functions
2016-03-24 12:52:33 +00:00
Function | Descrption
---------|-----------
[`convertToNum` ](#converttonum ) | Converts given values to numbers.
[`setUnitAttr` ](#setunitattr ) | Sets an element’ s attribute based on the unit in its current value.
[`isValidUnit` ](#isvalidunit ) | Check if an attribute’ s value is in a valid format
2017-08-03 23:49:39 +00:00
### Undo/Redo history management
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`ChangeElementCommand` ](#changeelementcommand ) | History command to make a change to an element.
[`ChangeElementCommand.apply` ](#changeelementcommandapply ) | Performs the stored change action
[`ChangeElementCommand.unapply` ](#changeelementcommandunapply ) | Reverses the stored change action
[`ChangeElementCommand.elements` ](#changeelementcommandelements ) |Returns array with element associated with this command
[`InsertElementCommand` ](#insertelementcommand ) | History command for an element that was added to the DOM
[`InsertElementCommand.apply` ](#insertelementcommandapply ) | Re-Inserts the new element
[`InsertElementCommand.unapply` ](#insertelementcommandunapply ) | Removes the element
[`InsertElementCommand.elements` ](#insertelementcommandelements ) |Returns array with element associated with this command
[`RemoveElementCommand` ](#removeelementcommand ) | History command for an element removed from the DOM
[`RemoveElementCommand.apply` ](#removeelementcommandapply ) | Re-removes the new element
[`RemoveElementCommand.unapply` ](#removeelementcommandunapply ) | Re-adds the new element
[`RemoveElementCommand.elements` ](#removeelementcommandelements ) | Returns array with element associated with this command
[`MoveElementCommand` ](#moveelementcommand ) | History command for an element that had its DOM position changed
[`MoveElementCommand.unapply` ](#moveelementcommandunapply ) | Re-positions the element
[`MoveElementCommand.unapply` ](#moveelementcommandunapply ) | Positions the element back to its original location
[`MoveElementCommand.elements` ](#moveelementcommandelements ) | Returns array with element associated with this command
[`BatchCommand` ](#batchcommand ) | History command that can contain/execute multiple other commands
[`BatchCommand.apply` ](#batchcommandapply ) | Runs "apply" on all subcommands
[`BatchCommand.unapply` ](#batchcommandunapply ) | Runs "unapply" on all subcommands
[`BatchCommand.elements` ](#batchcommandelements ) | Iterate through all our subcommands and returns all the elements we are changing
[`BatchCommand.addSubCommand` ](#batchcommandaddsubcommand ) | Adds a given command to the history stack
[`BatchCommand.isEmpty` ](#batchcommandisempty ) | Returns a boolean indicating whether or not the batch command is empty
[`resetUndoStack` ](#resetundostack ) | Resets the undo stack, effectively clearing the undo/redo history
[`undoMgr.getUndoStackSize` ](#undomgrgetundostacksize ) | Integer with the current size of the undo history stack
[`undoMgr.getRedoStackSize` ](#undomgrgetredostacksize ) | Integer with the current size of the redo history stack
[`undoMgr.getNextUndoCommandText` ](#undomgrgetnextundocommandtext ) | String associated with the next undo command
[`undoMgr.getNextRedoCommandText` ](#undomgrgetnextredocommandtext ) | String associated with the next redo command
[`undoMgr.undo` ](#undomgrundo ) | Performs an undo step
[`undoMgr.redo` ](#undomgrredo ) | Performs a redo step
[`addCommandToHistory` ](#resetundostack ) | Adds a command object to the undo history stack
[`beginUndoableChange` ](#beginundoablechange ) | This function tells the canvas to remember the old values of the attrName attribute for each element sent in.
[`finishUndoableChange` ](#finishundoablechange ) | This function returns a BatchCommand object which summarizes the change since `beginUndoableChange` was called.
2017-08-03 23:49:39 +00:00
### [`Selector`](#selector) - Private class for DOM element selection boxes
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`Selector.reset` ](#selectorreset ) | Used to reset the id and element that the selector is attached to
[`Selector.showGrips` ](#selectorshowgrips ) | Show the resize grips of this selector
[`Selector.updateGripCursors` ](selectorupdategripcursors ) | Updates cursors for corner grips on rotation so arrows point the right way
[`Selector.resize` ](#selectorresize ) | Updates the selector to match the element’ s size
2017-08-03 23:49:39 +00:00
### [ `SelectorManager`](#selectormanager) - Public class to manage all selector objects (selection boxes)
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`SelectorManager.initGroup` ](#selectormanagerinitgroup ) | Resets the parent selector group element
[`SelectorManager.requestSelector` ](#selectormanagerrequestselector ) | Returns the selector based on the given element
[`SelectorManager.releaseSelector` ](#selectormanagerreleaseselector ) | Removes the selector of the given element (hides selection box)
[`SelectorManager.getRubberBandBox` ](#selectormanagergetrubberbandbox` ) | Returns the rubberBandBox DOM element.
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Helper functions
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`walkTree` ](#walktree ) | Walks the tree and executes the callback on each element in a top-down fashion
[`walkTreePost` ](#walktreepost ) | Walks the tree and executes the callback on each element in a depth-first fashion
[`assignAttributes` ](#assignattributes ) | Assigns multiple attributes to an element.
[`cleanupElement` ](#cleanupelement ) | Remove unneeded (default) attributes, makes resulting SVG smaller
[`addSvgElementFromJson` ](#addsvgelementfromjson ) | Create a new SVG element based on the given object keys/values and add it to the current layer The element will be ran through cleanupElement before being returned
[`addExtension` ](#addextension ) | Add an extension to the editor
[`shortFloat` ](#shortfloat ) | Rounds a given value to a float with number of digits defined in save_options
[`getStrokedBBox` ](#getstrokedbbox ) | Get the bounding box for one or more stroked and/or transformed elements
[`getVisibleElements` ](#getvisibleelements ) | Get all elements that have a BBox (excludes `<defs>` , `<title>` , etc).
[`copyElem` ](#copyelem ) | Create a clone of an element, updating its ID and its children’ s IDs when needed
[`getElem` ](#getelem ) | Get a DOM element by ID within the SVG root element.
[`getId` ](#getid ) | Returns the last created DOM element ID string
[`getNextId` ](#getnextid ) | Creates and returns a unique ID string for a DOM element
[`bind` ](#bind ) | Attaches a callback function to an event
[`setIdPrefix` ](#setidprefix ) | Changes the ID prefix to the given value
[`sanitizeSvg` ](#sanitizesvg ) | Sanitizes the input node and its children It only keeps what is allowed from our whitelist defined above
[`getUrlFromAttr` ](#geturlfromattr ) | Extracts the URL from the `url(...)`
[`getBBox` ](#getbbox ) | Get the given/selected element’ s bounding box object, convert it to be more usable when necessary
[`ffClone` ](#ffclone ) | Hack for Firefox bugs where text element features aren't updated.
[`getPathBBox` ](#getpathbbox ) | Get correct BBox for a path in Webkit Converted from code found [here ](http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html )
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Element Transforms
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`getRotationAngle` ](#getrotationangle ) | Get the rotation angle of the given/selected DOM element
[`setRotationAngle` ](#setrotationangle ) | Removes any old rotations if present, prepends a new rotation at the transformed center
[`getTransformList` ](#gettransformlist ) | Returns an object that behaves like a SVGTransformList for the given DOM element
[`recalculateAllSelectedDimensions` ](#recalculateallselecteddimensions ) | Runs recalculateDimensions on the selected elements, adding the changes to a single batch command
[`remapElement` ](#remapelement ) | Applies coordinate changes to an element based on the given matrix
[`recalculateDimensions` ](#recalculatedimensions ) | Decides the course of action based on the element’ s transform list
[`transformPoint` ](#transformpoint ) | A (hopefully) quicker function to transform a point by a matrix (this function avoids any DOM calls and just does the math)
[`isIdentity` ](#isidentity ) | Helper function to check if the matrix performs no actual transform (i.e.
[`matrixMultiply` ](#matrixmultiply ) | This function tries to return a SVGMatrix that is the multiplication m1*m2.
[`transformListToTransform` ](#transformlisttotransform ) | This returns a single matrix Transform for a given Transform List (this is the equivalent of `SVGTransformList.consolidate()` but unlike that method, this one does not modify the actual `SVGTransformList` ) This function is very liberal with its `min` ,`max` arguments
[`hasMatrixTransform` ](#hasmatrixtransform ) | See if the given transformlist includes a non-indentity matrix transform
[`getMatrix` ](#getmatrix ) | Get the matrix object for a given element
[`transformBox` ](#transformbox ) | Transforms a rectangle based on the given matrix
2017-08-03 23:49:39 +00:00
### Selection
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`clearSelection` ](#clearselection ) | Clears the selection.
[`addToSelection` ](#addtoselection ) | Adds a list of elements to the selection.
[`removeFromSelection` ](#removefromselection ) | Removes elements from the selection.
[`selectAllInCurrentLayer` ](#selectallincurrentlayer ) | Clears the selection, then adds all elements in the current layer to the selection.
[`smoothControlPoints` ](#smoothcontrolpoints ) | Takes three points and creates a smoother line based on them
[`getMouseTarget` ](#getmousetarget ) | Gets the desired element from a mouse event
[`preventClickDefault` ](#preventclickdefault ) | Prevents default browser click behaviour on the given element
2017-08-03 23:49:39 +00:00
### Text edit functions - Functions relating to editing text elements
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
### Path edit functions - Functions relating to editing path elements
2016-03-24 12:52:33 +00:00
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Serialization
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`removeUnusedDefElems` ](#removeunuseddefelems ) | Looks at DOM elements inside the < defs > to see if they are referred to, removes them from the DOM if they are not.
[`svgCanvasToString` ](#svgcanvastostring ) | Main function to set up the SVG content for output
[`svgToString` ](#svgtostring ) | Sub function ran on each SVG element to convert it to a string as desired
[`embedImage` ](#embedimage ) | Converts a given image file to a data URL when possible, then runs a given callback
[`save` ](#save ) | Serializes the current drawing into SVG XML text and returns it to the ‘ saved’ handler.
[`rasterExport` ](#rasterexport ) | Generates a PNG Data URL based on the current image, then calls “exported” with an object including the string and any issues found
[`getSvgString` ](#getsvgstring ) | Returns the current drawing as raw SVG XML text.
[`setSvgString` ](#setsvgstring ) | This function sets the current drawing as the input SVG XML.
[`importSvgString` ](#importsvgstring ) | This function imports the input SVG XML into the current layer in the drawing
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Layers
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`identifyLayers` ](#identifylayers ) | Updates layer system
[`createLayer` ](#createlayer ) | Creates a new top-level layer in the drawing with the given name, sets the current layer to it, and then clears the selection This function then calls the ‘ changed’ handler.
[`deleteCurrentLayer` ](#deletecurrentlayer ) | Deletes the current layer from the drawing and then clears the selection.
[`getNumLayers` ](#getnumlayers ) | Returns the number of layers in the current drawing.
[`getLayer` ](#getlayer ) | Returns the name of the ith layer.
[`getCurrentLayer` ](#getcurrentlayer ) | Returns the name of the currently selected layer.
[`setCurrentLayer` ](#setcurrentlayer ) | Sets the current layer.
[`renameCurrentLayer` ](#renamecurrentlayer ) | Renames the current layer.
[`setCurrentLayerPosition` ](#setcurrentlayerposition ) | Changes the position of the current layer to the new value.
[`getLayerVisibility` ](#getlayervisibility ) | Returns whether the layer is visible.
[`setLayerVisibility` ](#setlayervisibility ) | Sets the visibility of the layer.
[`moveSelectedToLayer` ](#moveselectedtolayer ) | Moves the selected elements to layername.
[`getLayerOpacity` ](#getlayeropacity ) | Returns the opacity of the given layer.
[`setLayerOpacity` ](#setlayeropacity ) | Sets the opacity of the given layer.
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Document functions
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`clear` ](#clear ) | Clears the current document.
[`linkControlPoints` ](#linkcontrolpoints ) | Alias function
[`getContentElem` ](#getcontentelem ) | Returns the content DOM element
[`getRootElem` ](#getrootelem ) | Returns the root DOM element
[`getSelectedElems` ](#getselectedelems ) | Returns the array with selected DOM elements
[`getResolution` ](#getresolution ) | Returns the current dimensions and zoom level in an object
[`getZoom` ](#getzoom ) | Returns the current zoom level
[`getVersion` ](#getversion ) | Returns a string which describes the revision number of SvgCanvas.
[`setUiStrings` ](#setuistrings ) | Update interface strings with given values
[`setConfig` ](#setconfig ) | Update configuration options with given values
[`getDocumentTitle` ](#getdocumenttitle ) | Returns the current document title or an empty string if not found
[`setDocumentTitle` ](#setdocumenttitle ) | Adds/updates a title element for the document with the given name.
[`getEditorNS` ](#geteditorns ) | Returns the editor’ s namespace URL, optionally adds it to root element
[`setResolution` ](#setresolution ) | Changes the document’ s dimensions to the given size
[`getOffset` ](#getoffset ) | Returns an object with x, y values indicating the svgcontent element’ s position in the editor’ s canvas.
[`setBBoxZoom` ](#setbboxzoom ) | Sets the zoom level on the canvas-side based on the given value
[`setZoom` ](#setzoom ) | Sets the zoom to the given level
[`getMode` ](#getmode ) | Returns the current editor mode string
[`setMode` ](#setmode ) | Sets the editor’ s mode to the given string
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Element Styling
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`getColor` ](#getcolor ) | Returns the current fill/stroke option
[`setColor` ](#setcolor ) | Change the current stroke/fill color/gradient value
[`findDefs` ](#finddefs ) | Return the document’ s `<defs>` element, create it first if necessary
[`setGradient` ](#setgradient ) | Apply the current gradient to selected element’ s fill or stroke
[`findDuplicateGradient` ](#findduplicategradient ) | Check if exact gradient already exists
[`setPaint` ](#setpaint ) | Set a color/gradient to a fill/stroke
[`getStrokeWidth` ](#getstrokewidth ) | Returns the current stroke-width value
[`setStrokeWidth` ](#setstrokewidth ) | Sets the stroke width for the current selected elements When attempting to set a line’ s width to 0, this changes it to 1 instead
[`setStrokeAttr` ](#setstrokeattr ) | Set the given stroke-related attribute the given value for selected elements
[`getOpacity` ](#getopacity ) | Returns the current opacity
[`setOpacity` ](#setopacity ) | Sets the given opacity to the current selected elements
[`getOpacity` ](#getopacity ) | Returns the current fill opacity
[`getStrokeOpacity` ](#getstrokeopacity ) | Returns the current stroke opacity
[`setPaintOpacity` ](#setpaintopacity ) | Sets the current fill/stroke opacity
[`getBlur` ](#getblur ) | Gets the `stdDeviation` blur value of the given element
[`setBlurNoUndo` ](#setblurnoundo ) | Sets the `stdDeviation` blur value on the selected element without being undoable
[`setBlurOffsets` ](#setbluroffsets ) | Sets the x, y, with, height values of the filter element in order to make the blur not be clipped.
[`setBlur` ](#setblur ) | Adds/updates the blur filter to the selected element
[`getBold` ](#getbold ) | Check whether selected element is bold or not
[`setBold` ](#setbold ) | Make the selected element bold or normal
[`getItalic` ](#getitalic ) | Check whether selected element is italic or not
[`setItalic` ](#setitalic ) | Make the selected element italic or normal
[`getFontFamily` ](#getfontfamily ) | Returns the current font family
[`setFontFamily` ](#setfontfamily ) | Set the new font family
[`getFontSize` ](#getfontsize ) | Returns the current font size
[`setFontSize` ](#setfontsize ) | Applies the given font size to the selected element
[`getText` ](#gettext ) | Returns the current text (textContent) of the selected element
[`setTextContent` ](#settextcontent ) | Updates the text element with the given string
[`setImageURL` ](#setimageurl ) | Sets the new image URL for the selected image element.
[`setRectRadius` ](#setrectradius ) | Sets the rx & ry values to the selected rect element to change its corner radius
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Element manipulation
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`setSegType` ](#setsegtype ) | Sets the new segment type to the selected segment(s).
[`convertToPath` ](#converttopath ) | Convert selected element to a path, or get the BBox of an element-as-path
[`changeSelectedAttributeNoUndo` ](#changeselectedattributenoundo ) | This function makes the changes to the elements.
[`changeSelectedAttribute` ](#changeselectedattribute ) | Change the given/selected element and add the original value to the history stack If you want to change all selectedElements, ignore the elems argument.
[`deleteSelectedElements` ](#deleteselectedelements ) | Removes all selected elements from the DOM and adds the change to the history stack
[`groupSelectedElements` ](#groupselectedelements ) | Wraps all the selected elements in a group (g) element
[`ungroupSelectedElement` ](#ungroupselectedelement ) | Unwraps all the elements in a selected group (g) element.
[`moveToTopSelectedElement` ](#movetotopselectedelement ) | Repositions the selected element to the bottom in the DOM to appear on top of other elements
[`moveToBottomSelectedElement` ](#movetobottomselectedelement ) | Repositions the selected element to the top in the DOM to appear under other elements
[`moveSelectedElements` ](#moveselectedelements ) | Moves selected elements on the X/Y axis
[`cloneSelectedElements` ](#cloneselectedelements ) | Create deep DOM copies (clones) of all selected elements and move them slightly from their originals
[`alignSelectedElements` ](#alignselectedelements ) | Aligns selected elements
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
### Additional editor tools
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`updateCanvas` ](#updatecanvas ) | Updates the editor canvas width/height/position after a zoom has occurred
[`setBackground` ](#setbackground ) | Set the background of the editor (NOT the actual document)
[`cycleElement` ](#cycleelement ) | Select the next/previous element within the current layer
2017-08-03 23:49:39 +00:00
## `Utils.toXml`
2016-03-24 12:52:33 +00:00
Converts characters in a string to XML-friendly entities. Example: `&` becomes `&`
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
`str` The string to be converted
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The converted string
2017-08-03 23:49:39 +00:00
## `Utils.fromXml`
2016-03-24 12:52:33 +00:00
Converts XML entities in a string to single characters. Example: `&` becomes `&`
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
`str` The string to be converted
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
The converted string
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `Utils.encode64`
2016-03-24 12:52:33 +00:00
Converts a string to base64
2017-08-03 23:49:39 +00:00
## `Utils.decode64`
2016-03-24 12:52:33 +00:00
Converts a string from base64
2017-08-03 23:49:39 +00:00
## `Utils.convertToXMLReferences`
2016-03-24 12:52:33 +00:00
Converts a string to use XML references
2017-08-03 23:49:39 +00:00
## `rectsIntersect`
2016-03-24 12:52:33 +00:00
"rectsIntersect": function( r1,r2 )
Check if two rectangles (BBoxes objects) intersect each other
2017-08-03 23:49:39 +00:00
#### Paramaters
2016-03-24 12:52:33 +00:00
`r1` The first BBox-like object
`r2` The second BBox-like object
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Boolean that’ s true if rectangles intersect
2017-08-03 23:49:39 +00:00
## `snapToAngle`
2016-03-24 12:52:33 +00:00
"snapToAngle": function( x1, y1, x2, y2 )
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
2016-03-24 12:52:33 +00:00
Returns a 45 degree angle coordinate associated with the two given coordinates
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `x1` First coordinate’ s x value
* `x2` Second coordinate’ s x value
* `y1` First coordinate’ s y value
* `y2` Second coordinate’ s y value
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Object with the following values: x - The angle-snapped x value y - The angle-snapped y value snapangle - The angle at which to snap
2017-08-03 23:49:39 +00:00
## `text2xml`
2016-03-24 12:52:33 +00:00
"text2xml": function(sXML)
Cross-browser compatible method of converting a string to an XML tree found this function [here ](http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f )
2017-08-03 23:49:39 +00:00
# Unit conversion functions
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `convertToNum`
2016-03-24 12:52:33 +00:00
convertToNum = function( attr, val )
Converts given values to numbers. Attributes must be supplied in case a percentage is given
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attr` String with the name of the attribute associated with the value
* `val` String with the attribute value to convert
2017-08-03 23:49:39 +00:00
## `setUnitAttr`
2016-03-24 12:52:33 +00:00
setUnitAttr = function( elem, attr, val )
Sets an element’ s attribute based on the unit in its current value.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` DOM element to be changed
* `attr` String with the name of the attribute associated with the value
* `val` String with the attribute value to convert
2017-08-03 23:49:39 +00:00
## `isValidUnit`
2016-03-24 12:52:33 +00:00
canvas.isValidUnit = function( attr,val )
Check if an attribute’ s value is in a valid format
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attr` String with the name of the attribute associated with the value
* `val` String with the attribute value to check
2017-08-03 23:49:39 +00:00
# Undo/Redo history management
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `ChangeElementCommand`
2016-03-24 12:52:33 +00:00
var ChangeElementCommand = this.undoCmd.changeElement = function( elem, attrs, text )
History command to make a change to an element. Usually an attribute change, but can also be textcontent.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` The DOM element that was changed
* `attrs` An object with the attributes to be changed and the values they had before the change
* `text` An optional string visible to user related to this change
2017-08-03 23:49:39 +00:00
## `ChangeElementCommand.apply`
2016-03-24 12:52:33 +00:00
Performs the stored change action
2017-08-03 23:49:39 +00:00
## `ChangeElementCommand.unapply`
2016-03-24 12:52:33 +00:00
Reverses the stored change action
2017-08-03 23:49:39 +00:00
## `ChangeElementCommand.elements`
2016-03-24 12:52:33 +00:00
Returns array with element associated with this command
2017-08-03 23:49:39 +00:00
## `InsertElementCommand`
2016-03-24 12:52:33 +00:00
var InsertElementCommand = this.undoCmd.insertElement = function( elem, text )
History command for an element that was added to the DOM
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem ` The newly added DOM element
* `text` An optional string visible to user related to this change
2017-08-03 23:49:39 +00:00
## `InsertElementCommand.apply`
2016-03-24 12:52:33 +00:00
Re-Inserts the new element
2017-08-03 23:49:39 +00:00
## `InsertElementCommand.unapply`
2016-03-24 12:52:33 +00:00
Removes the element
2017-08-03 23:49:39 +00:00
## `InsertElementCommand.elements`
2016-03-24 12:52:33 +00:00
Returns array with element associated with this command
2017-08-03 23:49:39 +00:00
## `RemoveElementCommand`
2016-03-24 12:52:33 +00:00
var RemoveElementCommand = this.undoCmd.removeElement = function( elem, parent, text )
History command for an element removed from the DOM
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem ` The removed DOM element
* `parent` The DOM element’ s parent
* `text` An optional string visible to user related to this change
2017-08-03 23:49:39 +00:00
## `RemoveElementCommand.apply`
2016-03-24 12:52:33 +00:00
Re-removes the new element
2017-08-03 23:49:39 +00:00
## `RemoveElementCommand.unapply`
2016-03-24 12:52:33 +00:00
Re-adds the new element
2017-08-03 23:49:39 +00:00
## `RemoveElementCommand.elements`
2016-03-24 12:52:33 +00:00
Returns array with element associated with this command
2017-08-03 23:49:39 +00:00
## `MoveElementCommand`
2016-03-24 12:52:33 +00:00
var MoveElementCommand = this.undoCmd.moveElement = function( elem, oldNextSibling, oldParent, text )
History command for an element that had its DOM position changed
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem ` The DOM element that was moved
* `oldNextSibling` The element’ s next sibling before it was moved
* `oldParent` The element’ s parent before it was moved
* `text` An optional string visible to user related to this change
2017-08-03 23:49:39 +00:00
## `MoveElementCommand.unapply`
2016-03-24 12:52:33 +00:00
Re-positions the element
2017-08-03 23:49:39 +00:00
## `MoveElementCommand.unapply`
2016-03-24 12:52:33 +00:00
Positions the element back to its original location
2017-08-03 23:49:39 +00:00
## `MoveElementCommand.elements`
2016-03-24 12:52:33 +00:00
Returns array with element associated with this command
2017-08-03 23:49:39 +00:00
## `BatchCommand`
2016-03-24 12:52:33 +00:00
var BatchCommand = this.undoCmd.batch = function( text )
History command that can contain/execute multiple other commands
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `text` An optional string visible to user related to this change
2017-08-03 23:49:39 +00:00
## `BatchCommand.apply`
2016-03-24 12:52:33 +00:00
Runs “apply” on all subcommands
2017-08-03 23:49:39 +00:00
## `BatchCommand.unapply`
2016-03-24 12:52:33 +00:00
Runs “unapply” on all subcommands
2017-08-03 23:49:39 +00:00
## `BatchCommand.elements`
2016-03-24 12:52:33 +00:00
Iterate through all our subcommands and returns all the elements we are changing
2017-08-03 23:49:39 +00:00
## `BatchCommand.addSubCommand`
2016-03-24 12:52:33 +00:00
Adds a given command to the history stack
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `cmd` The undo command object to add
2017-08-03 23:49:39 +00:00
## `BatchCommand.isEmpty`
2016-03-24 12:52:33 +00:00
Returns a boolean indicating whether or not the batch command is empty
2017-08-03 23:49:39 +00:00
## `resetUndoStack`
2016-03-24 12:52:33 +00:00
resetUndoStack = function()
Resets the undo stack, effectively clearing the undo/redo history
2017-08-03 23:49:39 +00:00
## `undoMgr.getUndoStackSize`
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Integer with the current size of the undo history stack
2017-08-03 23:49:39 +00:00
## `undoMgr.getRedoStackSize`
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Integer with the current size of the redo history stack
2017-08-03 23:49:39 +00:00
## `undoMgr.getNextUndoCommandText`
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
String associated with the next undo command
2017-08-03 23:49:39 +00:00
## `undoMgr.getNextRedoCommandText`
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
String associated with the next redo command
2017-08-03 23:49:39 +00:00
## `undoMgr.undo`
2016-03-24 12:52:33 +00:00
Performs an undo step
2017-08-03 23:49:39 +00:00
## `undoMgr.redo`
2016-03-24 12:52:33 +00:00
Performs a redo step
2017-08-03 23:49:39 +00:00
## `addCommandToHistory`
2016-03-24 12:52:33 +00:00
addCommandToHistory = c.undoCmd.add = function( cmd )
Adds a command object to the undo history stack
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `cmd` The command object to add
2017-08-03 23:49:39 +00:00
## `beginUndoableChange`
2016-03-24 12:52:33 +00:00
c.beginUndoableChange = function( attrName, elems )
This function tells the canvas to remember the old values of the attrName attribute for each element sent in. The elements and values are stored on a stack, so the next call to `finishUndoableChange()` will pop the elements and old values off the stack, gets the current values from the DOM and uses all of these to construct the undo-able command.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attrName` The name of the attribute being changed
* `elems` Array of DOM elements being changed
2017-08-03 23:49:39 +00:00
## `finishUndoableChange`
2016-03-24 12:52:33 +00:00
c.finishUndoableChange = function()
This function returns a BatchCommand object which summarizes the change since beginUndoableChange was called. The command can then be added to the command history
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Batch command object with resulting changes
2017-08-03 23:49:39 +00:00
## `Selector`
2016-03-24 12:52:33 +00:00
Private class for DOM element selection boxes
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `id` integer to internally indentify the selector
* `elem` DOM element associated with this selector
2017-08-03 23:49:39 +00:00
#### Summary
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`Selector.reset` ](#selectorreset ) | Used to reset the id and element that the selector is attached to
[`Selector.showGrips` ](#selectorshowgrips ) | Show the resize grips of this selector
[`Selector.updateGripCursors` ](selectorupdategripcursors ) | Updates cursors for corner grips on rotation so arrows point the right way
[`Selector.resize` ](#selectorresize ) | Updates the selector to match the element’ s size
2017-08-03 23:49:39 +00:00
## Functions
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `Selector.reset`
2016-03-24 12:52:33 +00:00
Used to reset the id and element that the selector is attached to
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `e` DOM element associated with this selector
2017-08-03 23:49:39 +00:00
## `Selector.showGrips`
2016-03-24 12:52:33 +00:00
Show the resize grips of this selector
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `show` boolean indicating whether grips should be shown or not
2017-08-03 23:49:39 +00:00
## `Selector.updateGripCursors`
2016-03-24 12:52:33 +00:00
Updates cursors for corner grips on rotation so arrows point the right way
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `angle` Float indicating current rotation angle in degrees
2017-08-03 23:49:39 +00:00
## `Selector.resize`
2016-03-24 12:52:33 +00:00
Updates the selector to match the element’ s size
2017-08-03 23:49:39 +00:00
## `SelectorManager`
2016-03-24 12:52:33 +00:00
Public class to manage all selector objects (selection boxes)
2017-08-03 23:49:39 +00:00
## Summary
2016-03-24 12:52:33 +00:00
Function | Description
---------|------------
[`SelectorManager.initGroup` ](#selectormanagerinitgroup ) | Resets the parent selector group element
[`SelectorManager.requestSelector` ](#selectormanagerrequestselector ) | Returns the selector based on the given element
[`SelectorManager.releaseSelector` ](#selectormanagerreleaseselector ) | Removes the selector of the given element (hides selection box)
[`SelectorManager.getRubberBandBox` ](#selectormanagergetrubberbandbox` ) | Returns the rubberBandBox DOM element.
2017-08-03 23:49:39 +00:00
## `SelectorManager.initGroup`
2016-03-24 12:52:33 +00:00
Resets the parent selector group element
2017-08-03 23:49:39 +00:00
## `SelectorManager.requestSelector`
2016-03-24 12:52:33 +00:00
Returns the selector based on the given element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` DOM element to get the selector for
2017-08-03 23:49:39 +00:00
## `SelectorManager.releaseSelector`
2016-03-24 12:52:33 +00:00
Removes the selector of the given element (hides selection box)
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` DOM element to remove the selector for
2017-08-03 23:49:39 +00:00
## `SelectorManager.getRubberBandBox`
2016-03-24 12:52:33 +00:00
Returns the rubberBandBox DOM element. This is the rectangle drawn by the user for selecting/zooming
2017-08-03 23:49:39 +00:00
# Helper functions
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `walkTree`
2016-03-24 12:52:33 +00:00
function walkTree( elem, cbFn )
Walks the tree and executes the callback on each element in a top-down fashion
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` DOM element to traverse
* `cbFn` Callback function to run on each element
2017-08-03 23:49:39 +00:00
## `walkTreePost`
2016-03-24 12:52:33 +00:00
function walkTreePost( elem, cbFn )
Walks the tree and executes the callback on each element in a depth-first fashion
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem ` DOM element to traverse
* `cbFn` Callback function to run on each element
2017-08-03 23:49:39 +00:00
## `assignAttributes`
2016-03-24 12:52:33 +00:00
var assignAttributes = this.assignAttributes = function( node, attrs, suspendLength, unitCheck )
Assigns multiple attributes to an element.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `node` DOM element to apply new attribute values to
* `attrs` Object with attribute keys/values
* `suspendLength` Optional integer of milliseconds to suspend redraw
* `unitCheck` Boolean to indicate the need to use setUnitAttr
2017-08-03 23:49:39 +00:00
## `cleanupElement`
2016-03-24 12:52:33 +00:00
var cleanupElement = this.cleanupElement = function( element )
Remove unneeded (default) attributes, makes resulting SVG smaller
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `element` DOM element to clean up
2017-08-03 23:49:39 +00:00
## `addSvgElementFromJson`
2016-03-24 12:52:33 +00:00
var addSvgElementFromJson = this.addSvgElementFromJson = function( data )
Create a new SVG element based on the given object keys/values and add it to the current layer The element will be ran through `cleanupElement` before being returned
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `data` Object with the following keys/values:
* `element` - DOM element to create
* `attr` - Object with attributes/values to assign to the new element
* `curStyles` - Boolean indicating that current style attributes should be applied first
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The new element
2017-08-03 23:49:39 +00:00
## `addExtension`
2016-03-24 12:52:33 +00:00
this.addExtension = function( name, ext_func )
Add an extension to the editor
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `name` String with the ID of the extension
* `ext_func` Function supplied by the extension with its data
2017-08-03 23:49:39 +00:00
## `shortFloat`
2016-03-24 12:52:33 +00:00
var shortFloat = function( val )
Rounds a given value to a float with number of digits defined in save_options
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` The value as a String, Number or Array of two numbers to be rounded
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
If a string/number was given, returns a Float. If an array, return a string with comma-seperated floats
2017-08-03 23:49:39 +00:00
## `getStrokedBBox`
2016-03-24 12:52:33 +00:00
var getStrokedBBox = this.getStrokedBBox = function( elems )
Get the bounding box for one or more stroked and/or transformed elements
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elems` Array with DOM elements to check
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
A single bounding box object
2017-08-03 23:49:39 +00:00
## `getVisibleElements`
2016-03-24 12:52:33 +00:00
var getVisibleElements = this.getVisibleElements = function( parent, includeBBox )
Get all elements that have a BBox (excludes `<defs>` , `<title>` , etc). Note that 0-opacity, off-screen etc elements are still considered “visible” for this function
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `parent` The parent DOM element to search within
* `includeBBox` Boolean to indicate that an object should return with the element and its bbox
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
An array with all “visible” elements, or if includeBBox is true, an array with objects that include:
* `elem` - The element
* `bbox` - The element’ s BBox as retrieved from getStrokedBBox
2017-08-03 23:49:39 +00:00
## `copyElem`
2016-03-24 12:52:33 +00:00
var copyElem = function( el )
Create a clone of an element, updating its ID and its children’ s IDs when needed
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `el` DOM element to clone
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The cloned element
2017-08-03 23:49:39 +00:00
## `getElem`
2016-03-24 12:52:33 +00:00
function getElem( id )
Get a DOM element by ID within the SVG root element.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `id` String with the element’ s new ID
2017-08-03 23:49:39 +00:00
## `getId`
2016-03-24 12:52:33 +00:00
getId = c.getId = function()
Returns the last created DOM element ID string
2017-08-03 23:49:39 +00:00
## `getNextId`
2016-03-24 12:52:33 +00:00
getNextId = c.getNextId = function()
Creates and returns a unique ID string for a DOM element
2017-08-03 23:49:39 +00:00
## `bind`
2016-03-24 12:52:33 +00:00
c.bind = function( event, f )
Attaches a callback function to an event
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `event` String indicating the name of the event
* `f` The callback function to bind to the event
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The previous event
2017-08-03 23:49:39 +00:00
## `setIdPrefix`
2016-03-24 12:52:33 +00:00
c.setIdPrefix = function( p )
Changes the ID prefix to the given value
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `p` String with the new prefix
2017-08-03 23:49:39 +00:00
## `sanitizeSvg`
2016-03-24 12:52:33 +00:00
var sanitizeSvg = this.sanitizeSvg = function( node )
Sanitizes the input node and its children It only keeps what is allowed from our whitelist defined above
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `node` The DOM element to be checked, will also check its children
2017-08-03 23:49:39 +00:00
## `getUrlFromAttr`
2016-03-24 12:52:33 +00:00
var getUrlFromAttr = this.getUrlFromAttr = function( attrVal )
Extracts the URL from the `url(...)` syntax of some attributes. Three variants:
* `<circle fill="url(someFile.svg#foo)" />`
* `<circle fill="url(‘ someFile.svg#foo’ )" />`
* `<circle fill=’ url("someFile.svg#foo")’ />`
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attrVal` The attribute value as a string
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
String with just the URL, like `someFile.svg#foo`
2017-08-03 23:49:39 +00:00
## `getBBox`
2016-03-24 12:52:33 +00:00
var getBBox = this.getBBox = function( elem )
Get the given/selected element’ s bounding box object, convert it to be more usable when necessary
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` Optional DOM element to get the BBox for
2017-08-03 23:49:39 +00:00
## `ffClone`
2016-03-24 12:52:33 +00:00
var ffClone = function( elem )
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
Hack for Firefox bugs where text element features aren’ t updated. This function clones the element and re-selects it
2016-03-24 12:52:33 +00:00
> TODO: Test for this bug on load and add it to “support” object instead of browser sniffing
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` The (text) DOM element to clone
2017-08-03 23:49:39 +00:00
## `getPathBBox`
2016-03-24 12:52:33 +00:00
var getPathBBox = function( path )
Get correct BBox for a path in Webkit Converted from code found [here ](http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html )
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `path` The path DOM element to get the BBox for
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
A BBox-like object
2017-08-03 23:49:39 +00:00
# Element Transforms
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `getRotationAngle`
2016-03-24 12:52:33 +00:00
var getRotationAngle = this.getRotationAngle = function( elem, to_rad )
Get the rotation angle of the given/selected DOM element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` Optional DOM element to get the angle for
* `to_rad` Boolean that when true returns the value in radians rather than degrees
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Float with the angle in degrees or radians
2017-08-03 23:49:39 +00:00
## `setRotationAngle`
2016-03-24 12:52:33 +00:00
this.setRotationAngle = function( val, preventUndo )
Removes any old rotations if present, prepends a new rotation at the transformed center
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` The new rotation angle in degrees
* `preventUndo` Boolean indicating whether the action should be undoable or not
2017-08-03 23:49:39 +00:00
## `getTransformList`
2016-03-24 12:52:33 +00:00
var getTransformList = this.getTransformList = function( elem )
Returns an object that behaves like a SVGTransformList for the given DOM element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` DOM element to get a transformlist from
2017-08-03 23:49:39 +00:00
## `recalculateAllSelectedDimensions`
2016-03-24 12:52:33 +00:00
var recalculateAllSelectedDimensions = this.recalculateAllSelectedDimensions = function()
Runs recalculateDimensions on the selected elements, adding the changes to a single batch command
2017-08-03 23:49:39 +00:00
## `remapElement`
2016-03-24 12:52:33 +00:00
var remapElement = this.remapElement = function( selected, changes, m )
Applies coordinate changes to an element based on the given matrix
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `selected` DOM element to be changed
* `changes` Object with changes to be remapped
* `m` Matrix object to use for remapping coordinates
2017-08-03 23:49:39 +00:00
## `recalculateDimensions`
2016-03-24 12:52:33 +00:00
var recalculateDimensions = this.recalculateDimensions = function( selected )
Decides the course of action based on the element’ s transform list
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `selected` The DOM element to recalculate
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Undo command object with the resulting change
2017-08-03 23:49:39 +00:00
## `transformPoint`
2016-03-24 12:52:33 +00:00
var transformPoint = function( x, y, m )
A (hopefully) quicker function to transform a point by a matrix (this function avoids any DOM calls and just does the math)
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `x` Float representing the x coordinate
* `y` Float representing the y coordinate
* `m` Matrix object to transform the point with Returns a x,y object representing the transformed point
2017-08-03 23:49:39 +00:00
## `isIdentity`
2016-03-24 12:52:33 +00:00
var isIdentity = function( m )
Helper function to check if the matrix performs no actual transform (i.e. exists for identity purposes)
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `m` The matrix object to check
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Boolean indicating whether or not the matrix is `1,0,0,1,0,0`
2017-08-03 23:49:39 +00:00
## `matrixMultiply`
2016-03-24 12:52:33 +00:00
var matrixMultiply = this.matrixMultiply = function()
This function tries to return a SVGMatrix that is the multiplication `m1*m2` . We also round to zero when it’ s near zero
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
`= 2 Matrix objects to multiply`
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The matrix object resulting from the calculation
2017-08-03 23:49:39 +00:00
## `transformListToTransform`
2016-03-24 12:52:33 +00:00
var transformListToTransform = this.transformListToTransform = function( tlist, min, max )
This returns a single matrix Transform for a given Transform List (this is the equivalent of `SVGTransformList.consolidate()` but unlike that method, this one does not modify the actual `SVGTransformList` ) This function is very liberal with its `min` , `max` arguments
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `tlist` The transformlist object
* `min` Optional integer indicating start transform position
* `max` Optional integer indicating end transform position
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
A single matrix transform object
2017-08-03 23:49:39 +00:00
## `hasMatrixTransform`
2016-03-24 12:52:33 +00:00
var hasMatrixTransform = this.hasMatrixTransform = function( tlist )
See if the given transformlist includes a non-indentity matrix transform
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `tlist` The transformlist to check
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Boolean on whether or not a matrix transform was found
2017-08-03 23:49:39 +00:00
## `getMatrix`
2016-03-24 12:52:33 +00:00
var getMatrix = function( elem )
Get the matrix object for a given element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` The DOM element to check
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The matrix object associated with the element’ s transformlist
2017-08-03 23:49:39 +00:00
## `transformBox`
2016-03-24 12:52:33 +00:00
var transformBox = this.transformBox = function( l, t, w, h, m )
Transforms a rectangle based on the given matrix
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `l` Float with the box’ s left coordinate
* `t` Float with the box’ s top coordinate
* `w` Float with the box width
* `h` Float with the box height
* `m` Matrix object to transform the box by
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
An object with the following values:
* `tl` - The top left coordinate (x,y object)
* `tr` - The top right coordinate (x,y object)
* `bl` - The bottom left coordinate (x,y object)
* `br` - The bottom right coordinate (x,y object)
* `aabox` - Object with the following values:
* Float with the axis-aligned x coordinate
* Float with the axis-aligned y coordinate
* Float with the axis-aligned width coordinate
* Float with the axis-aligned height coordinate
2017-08-03 23:49:39 +00:00
# Selection
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `clearSelection`
2016-03-24 12:52:33 +00:00
var clearSelection = this.clearSelection = function( noCall )
Clears the selection. The `selected` handler is then called. Parameters: `noCall` - Optional boolean that when true does not call the “selected” handler
2017-08-03 23:49:39 +00:00
## `addToSelection`
2016-03-24 12:52:33 +00:00
var addToSelection = this.addToSelection = function( elemsToAdd, showGrips )
Adds a list of elements to the selection. The ‘ selected’ handler is then called.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elemsToAdd` an array of DOM elements to add to the selection
* `showGrips` a boolean flag indicating whether the resize grips should be shown
2017-08-03 23:49:39 +00:00
## `removeFromSelection`
2016-03-24 12:52:33 +00:00
var removeFromSelection = this.removeFromSelection = function( elemsToRemove )
Removes elements from the selection.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elemsToRemove` an array of elements to remove from selection
2017-08-03 23:49:39 +00:00
## `selectAllInCurrentLayer`
2016-03-24 12:52:33 +00:00
this.selectAllInCurrentLayer = function()
Clears the selection, then adds all elements in the current layer to the selection. This function then fires the selected event.
2017-08-03 23:49:39 +00:00
## `smoothControlPoints`
2016-03-24 12:52:33 +00:00
var smoothControlPoints = this.smoothControlPoints = function( ct1, ct2, pt )
Takes three points and creates a smoother line based on them
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `ct1` Object with x and y values (first control point)
* `ct2` Object with x and y values (second control point)
* `pt` Object with x and y values (third point)
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Array of two “smoothed” point objects
2017-08-03 23:49:39 +00:00
## `getMouseTarget`
2016-03-24 12:52:33 +00:00
var getMouseTarget = this.getMouseTarget = function( evt )
Gets the desired element from a mouse event
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `evt` Event object from the mouse event
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
DOM element we want
2017-08-03 23:49:39 +00:00
## `preventClickDefault`
2016-03-24 12:52:33 +00:00
var preventClickDefault = function( img )
Prevents default browser click behaviour on the given element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `img` The DOM element to prevent the cilck on
2017-08-03 23:49:39 +00:00
# Text edit functions
2016-03-24 12:52:33 +00:00
Functions relating to editing text elements
2017-08-03 23:49:39 +00:00
# Path edit functions
2016-03-24 12:52:33 +00:00
Functions relating to editing path elements
2017-08-03 23:49:39 +00:00
# Serialization
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `removeUnusedDefElems`
2016-03-24 12:52:33 +00:00
var removeUnusedDefElems = this.removeUnusedDefElems = function()
Looks at DOM elements inside the < defs > to see if they are referred to, removes them from the DOM if they are not.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The amount of elements that were removed
2017-08-03 23:49:39 +00:00
## `svgCanvasToString`
2016-03-24 12:52:33 +00:00
var svgCanvasToString = this.svgCanvasToString = function()
Main function to set up the SVG content for output
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
String containing the SVG image for output
2017-08-03 23:49:39 +00:00
## `svgToString`
2016-03-24 12:52:33 +00:00
var svgToString = this.svgToString = function( elem, indent )
Sub function ran on each SVG element to convert it to a string as desired
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` The SVG element to convert
* `indent` Integer with the amount of spaces to indent this tag
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
String with the given element as an SVG tag
2017-08-03 23:49:39 +00:00
## `embedImage`
2016-03-24 12:52:33 +00:00
this.embedImage = function( val, callback )
Converts a given image file to a data URL when possible, then runs a given callback
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` String with the path/URL of the image
* `callback` Optional function to run when image data is found, supplies the result (data URL or false) as first parameter.
2017-08-03 23:49:39 +00:00
## `save`
2016-03-24 12:52:33 +00:00
this.save = function( opts )
Serializes the current drawing into SVG XML text and returns it to the ‘ saved’ handler. This function also includes the XML prolog. Clients of the SvgCanvas bind their save function to the ‘ saved’ event.
#### Returns
Nothing
2017-08-03 23:49:39 +00:00
## `rasterExport`
2016-03-24 12:52:33 +00:00
this.rasterExport = function()
Generates a PNG Data URL based on the current image, then calls “exported” with an object including the string and any issues found
2017-08-03 23:49:39 +00:00
## `getSvgString`
2016-03-24 12:52:33 +00:00
this.getSvgString = function()
Returns the current drawing as raw SVG XML text.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The current drawing as raw SVG XML text.
2017-08-03 23:49:39 +00:00
## `setSvgString`
2016-03-24 12:52:33 +00:00
this.setSvgString = function( xmlString )
This function sets the current drawing as the input SVG XML.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `xmlString` The SVG as XML text.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
This function returns false if the set was unsuccessful, true otherwise.
2017-08-03 23:49:39 +00:00
## `importSvgString`
2016-03-24 12:52:33 +00:00
this.importSvgString = function( xmlString )
This function imports the input SVG XML into the current layer in the drawing
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `xmlString` The SVG as XML text.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
This function returns false if the import was unsuccessful, true otherwise.
- Linting (HTML): Use double-quotes for attributes, remove redundant `type=text/css`,
indent/lbs, consistent non-use of HTML namespace, consistent indents, consistent charset
casing
- Linting (Markdown): Add `.remarkrc`, use proper hierarchical headings, use consistent
heading format, trailing spaces
- `composer.json`: consistent property spacing
- License: Add `.txt` extension, update copyright date, and reflect type (MIT) in file name
- Credits: Add self
- npm: Add `package.json` (version 3.0.0-alpha.1 for npm release only; just reserving name)
2018-05-13 01:58:13 +00:00
>TODO:
2016-03-24 12:52:33 +00:00
* properly handle if namespace is introduced by imported content (must add to svgcontent and update all prefixes in the imported node)
* properly handle recalculating dimensions, recalculateDimensions() doesn’ t handle arbitrary transform lists, but makes some assumptions about how the transform list was obtained
* import should happen in top-left of current zoomed viewport
* create a new layer for the imported SVG
2017-08-03 23:49:39 +00:00
# Layers
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `identifyLayers`
2016-03-24 12:52:33 +00:00
var identifyLayers = function()
Updates layer system
2017-08-03 23:49:39 +00:00
## `createLayer`
2016-03-24 12:52:33 +00:00
this.createLayer = function( name )
Creates a new top-level layer in the drawing with the given name, sets the current layer to it, and then clears the selection This function then calls the ‘ changed’ handler. This is an undoable action.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `name` The given name
2017-08-03 23:49:39 +00:00
## `deleteCurrentLayer`
2016-03-24 12:52:33 +00:00
this.deleteCurrentLayer = function()
Deletes the current layer from the drawing and then clears the selection. This function then calls the ‘ changed’ handler. This is an undoable action.
2017-08-03 23:49:39 +00:00
## `getNumLayers`
2016-03-24 12:52:33 +00:00
this.getNumLayers = function()
Returns the number of layers in the current drawing.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The number of layers in the current drawing.
2017-08-03 23:49:39 +00:00
## `getLayer`
2016-03-24 12:52:33 +00:00
this.getLayer = function( i )
Returns the name of the ith layer. If the index is out of range, an empty string is returned.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `i` the zero-based index of the layer you are querying.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The name of the ith layer
2017-08-03 23:49:39 +00:00
## `getCurrentLayer`
2016-03-24 12:52:33 +00:00
this.getCurrentLayer = function()
Returns the name of the currently selected layer. If an error occurs, an empty string is returned.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The name of the currently active layer.
2017-08-03 23:49:39 +00:00
## `setCurrentLayer`
2016-03-24 12:52:33 +00:00
this.setCurrentLayer = function( name )
Sets the current layer. If the name is not a valid layer name, then this function returns false. Otherwise it returns true. This is not an undo-able action.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `name` the name of the layer you want to switch to.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
`true` if the current layer was switched, otherwise `false`
2017-08-03 23:49:39 +00:00
## `renameCurrentLayer`
2016-03-24 12:52:33 +00:00
this.renameCurrentLayer = function( newname )
Renames the current layer. If the layer name is not valid (i.e. unique), then this function does nothing and returns `false` , otherwise it returns `true` . This is an undo-able action.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `newname` the new name you want to give the current layer. This name must be unique among all layer names.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
`true` if the rename succeeded, `false` otherwise.
2017-08-03 23:49:39 +00:00
## `setCurrentLayerPosition`
2016-03-24 12:52:33 +00:00
this.setCurrentLayerPosition = function( newpos )
Changes the position of the current layer to the new value. If the new index is not valid, this function does nothing and returns false, otherwise it returns true. This is an undo-able action.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `newpos` The zero-based index of the new position of the layer. This should be between
`0` and (number of layers `1` )
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
`true` if the current layer position was changed, `false` otherwise.
2017-08-03 23:49:39 +00:00
## `getLayerVisibility`
2016-03-24 12:52:33 +00:00
this.getLayerVisibility = function( layername )
Returns whether the layer is visible. If the layer name is not valid, then this function returns false.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `layername` the name of the layer which you want to query.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The visibility state of the layer, or false if the layer name was invalid.
2017-08-03 23:49:39 +00:00
## `setLayerVisibility`
2016-03-24 12:52:33 +00:00
this.setLayerVisibility = function( layername, bVisible )
Sets the visibility of the layer. If the layer name is not valid, this function return false, otherwise it returns true. This is an undo-able action.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `layername` the name of the layer to change the visibility
* `bVisible` true/false, whether the layer should be visible
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
`true` if the layer’ s visibility was set, `false` otherwise
2017-08-03 23:49:39 +00:00
## `moveSelectedToLayer`
2016-03-24 12:52:33 +00:00
this.moveSelectedToLayer = function( layername )
Moves the selected elements to layername. If the name is not a valid layer name, then false is returned. Otherwise it returns true. This is an undo-able action.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `layername` the name of the layer you want to which you want to move the selected elements
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
`true` if the selected elements were moved to the layer, `false` otherwise.
2017-08-03 23:49:39 +00:00
## `getLayerOpacity`
2016-03-24 12:52:33 +00:00
this.getLayerOpacity = function( layername )
Returns the opacity of the given layer. If the input name is not a layer, null is returned.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `layername` name of the layer on which to get the opacity
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The opacity value of the given layer. This will be a value between `0.0` and `1.0` , or null if layername is not a valid layer
2017-08-03 23:49:39 +00:00
## `setLayerOpacity`
2016-03-24 12:52:33 +00:00
this.setLayerOpacity = function( layername, opacity )
Sets the opacity of the given layer. If the input name is not a layer, nothing happens. This is not an undo-able action.
>NOTE: this function exists solely to apply a highlighting/de-emphasis effect to a layer, when it is possible for a user to affect the opacity of a layer, we will need to allow this function to produce an undo-able action. If opacity is not a value between 0.0 and 1.0, then nothing happens.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `layername` name of the layer on which to set the opacity
* `opacity` a float value in the range 0.0-1.0
2017-08-03 23:49:39 +00:00
# Document functions
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `clear`
2016-03-24 12:52:33 +00:00
this.clear = function()
Clears the current document. This is not an undoable action.
2017-08-03 23:49:39 +00:00
## `linkControlPoints`
2016-03-24 12:52:33 +00:00
Alias function
2017-08-03 23:49:39 +00:00
## `getContentElem`
2016-03-24 12:52:33 +00:00
this.getContentElem = function()
Returns the content DOM element
2017-08-03 23:49:39 +00:00
## `getRootElem`
2016-03-24 12:52:33 +00:00
this.getRootElem = function()
Returns the root DOM element
2017-08-03 23:49:39 +00:00
## `getSelectedElems`
2016-03-24 12:52:33 +00:00
this.getSelectedElems = function()
Returns the array with selected DOM elements
2017-08-03 23:49:39 +00:00
## `getResolution`
2016-03-24 12:52:33 +00:00
var getResolution = this.getResolution = function()
Returns the current dimensions and zoom level in an object
2017-08-03 23:49:39 +00:00
## `getZoom`
2016-03-24 12:52:33 +00:00
this.getZoom = function()
Returns the current zoom level
2017-08-03 23:49:39 +00:00
## `getVersion`
2016-03-24 12:52:33 +00:00
this.getVersion = function()
Returns a string which describes the revision number of SvgCanvas.
2017-08-03 23:49:39 +00:00
## `setUiStrings`
2016-03-24 12:52:33 +00:00
this.setUiStrings = function(strs)
Update interface strings with given values
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `strs` Object with strings (see uiStrings for examples)
2017-08-03 23:49:39 +00:00
## `setConfig`
2016-03-24 12:52:33 +00:00
this.setConfig = function( opts )
Update configuration options with given values
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `opts` Object with options (see curConfig for examples)
2017-08-03 23:49:39 +00:00
## `getDocumentTitle`
2016-03-24 12:52:33 +00:00
this.getDocumentTitle = function()
Returns the current document title or an empty string if not found
2017-08-03 23:49:39 +00:00
## `setDocumentTitle`
2016-03-24 12:52:33 +00:00
this.setDocumentTitle = function( newtitle )
Adds/updates a title element for the document with the given name. This is an undoable action
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `newtitle` String with the new title
2017-08-03 23:49:39 +00:00
## `getEditorNS`
2016-03-24 12:52:33 +00:00
this.getEditorNS = function( add )
Returns the editor’ s namespace URL, optionally adds it to root element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `add` Boolean to indicate whether or not to add the namespace value
2017-08-03 23:49:39 +00:00
## `setResolution`
2016-03-24 12:52:33 +00:00
this.setResolution = function( x, y )
Changes the document’ s dimensions to the given size
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `x` Number with the width of the new dimensions in user units. Can also be the string “fit” to indicate “fit to content”
* `y` Number with the height of the new dimensions in user units.
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Boolean to indicate if resolution change was succesful. It will fail on “fit to content” option with no content to fit to.
2017-08-03 23:49:39 +00:00
## `getOffset`
2016-03-24 12:52:33 +00:00
this.getOffset = function()
Returns an object with `x` , `y` values indicating the svgcontent element’ s position in the editor’ s canvas.
2017-08-03 23:49:39 +00:00
## `setBBoxZoom`
2016-03-24 12:52:33 +00:00
this.setBBoxZoom = function( val, editor_w, editor_h )
Sets the zoom level on the canvas-side based on the given value
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` Bounding box object to zoom to or string indicating zoom option
* `editor_w` Integer with the editor’ s workarea box’ s width
* `editor_h` Integer with the editor’ s workarea box’ s height
2017-08-03 23:49:39 +00:00
## `setZoom`
2016-03-24 12:52:33 +00:00
this.setZoom = function( zoomlevel )
Sets the zoom to the given level
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `zoomlevel` Float indicating the zoom level to change to
2017-08-03 23:49:39 +00:00
## `getMode`
2016-03-24 12:52:33 +00:00
this.getMode = function()
Returns the current editor mode string
2017-08-03 23:49:39 +00:00
## `setMode`
2016-03-24 12:52:33 +00:00
this.setMode = function( name )
Sets the editor’ s mode to the given string
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `name` String with the new mode to change to
2017-08-03 23:49:39 +00:00
# Element Styling
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `getColor`
2016-03-24 12:52:33 +00:00
this.getColor = function( type )
Returns the current fill/stroke option
2017-08-03 23:49:39 +00:00
## `setColor`
2016-03-24 12:52:33 +00:00
this.setColor = function( type, val, preventUndo )
Change the current stroke/fill color/gradient value
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `type` String indicating fill or stroke
* `val` The value to set the stroke attribute to
* `preventUndo` Boolean indicating whether or not this should be and undoable option
2017-08-03 23:49:39 +00:00
## `findDefs`
2016-03-24 12:52:33 +00:00
var findDefs = function()
Return the document’ s `<defs>` element, create it first if necessary
2017-08-03 23:49:39 +00:00
## `setGradient`
2016-03-24 12:52:33 +00:00
var setGradient = this.setGradient = function( type )
Apply the current gradient to selected element’ s fill or stroke
Parameters `type` - String indicating “fill” or “stroke” to apply to an element
2017-08-03 23:49:39 +00:00
## `findDuplicateGradient`
2016-03-24 12:52:33 +00:00
var findDuplicateGradient = function( grad )
Check if exact gradient already exists
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `grad` The gradient DOM element to compare to others
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
The existing gradient if found, null if not
2017-08-03 23:49:39 +00:00
## `setPaint`
2016-03-24 12:52:33 +00:00
this.setPaint = function( type, paint )
Set a color/gradient to a fill/stroke
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `type` String with “fill” or “stroke”
* `paint` The jGraduate paint object to apply
2017-08-03 23:49:39 +00:00
## `getStrokeWidth`
2016-03-24 12:52:33 +00:00
this.getStrokeWidth = function()
Returns the current stroke-width value
2017-08-03 23:49:39 +00:00
## `setStrokeWidth`
2016-03-24 12:52:33 +00:00
this.setStrokeWidth = function( val )
Sets the stroke width for the current selected elements When attempting to set a line’ s width to 0, this changes it to 1 instead
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` A Float indicating the new stroke width value
2017-08-03 23:49:39 +00:00
## `setStrokeAttr`
2016-03-24 12:52:33 +00:00
this.setStrokeAttr = function( attr, val )
Set the given stroke-related attribute the given value for selected elements
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attr` String with the attribute name
* `val` String or number with the attribute value
2017-08-03 23:49:39 +00:00
## `getOpacity`
2016-03-24 12:52:33 +00:00
this.getOpacity = function()
Returns the current opacity
2017-08-03 23:49:39 +00:00
## `setOpacity`
2016-03-24 12:52:33 +00:00
this.setOpacity = function( val )
Sets the given opacity to the current selected elements
2017-08-03 23:49:39 +00:00
## `getOpacity`
2016-03-24 12:52:33 +00:00
Returns the current fill opacity
2017-08-03 23:49:39 +00:00
## `getStrokeOpacity`
2016-03-24 12:52:33 +00:00
this.getStrokeOpacity = function()
Returns the current stroke opacity
2017-08-03 23:49:39 +00:00
## `setPaintOpacity`
2016-03-24 12:52:33 +00:00
this.setPaintOpacity = function( type, val, preventUndo )
Sets the current fill/stroke opacity
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `type` String with “fill” or “stroke”
* `val` Float with the new opacity value
* `preventUndo` Boolean indicating whether or not this should be an undoable action
2017-08-03 23:49:39 +00:00
## `getBlur`
2016-03-24 12:52:33 +00:00
this.getBlur = function( elem )
Gets the stdDeviation blur value of the given element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` The element to check the blur value for
2017-08-03 23:49:39 +00:00
## `setBlurNoUndo`
2016-03-24 12:52:33 +00:00
canvas.setBlurNoUndo = function( val )
Sets the stdDeviation blur value on the selected element without being undoable
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` The new stdDeviation value
2017-08-03 23:49:39 +00:00
## `setBlurOffsets`
2016-03-24 12:52:33 +00:00
canvas.setBlurOffsets = function( filter, stdDev )
Sets the `x` , `y` , with, height values of the filter element in order to make the blur not be clipped. Removes them if not neeeded
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `filter` The filter DOM element to update
* `stdDev` The standard deviation value on which to base the offset size
2017-08-03 23:49:39 +00:00
## `setBlur`
2016-03-24 12:52:33 +00:00
canvas.setBlur = function( val, complete )
Adds/updates the blur filter to the selected element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` Float with the new stdDeviation blur value
* `complete` Boolean indicating whether or not the action should be completed (to add to the undo manager)
2017-08-03 23:49:39 +00:00
## `getBold`
2016-03-24 12:52:33 +00:00
this.getBold = function()
Check whether selected element is bold or not
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Boolean indicating whether or not element is bold
2017-08-03 23:49:39 +00:00
## `setBold`
2016-03-24 12:52:33 +00:00
this.setBold = function( b )
Make the selected element bold or normal
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `b` Boolean indicating bold `true` or normal `false`
2017-08-03 23:49:39 +00:00
## `getItalic`
2016-03-24 12:52:33 +00:00
this.getItalic = function()
Check whether selected element is italic or not
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Boolean indicating whether or not element is italic
2017-08-03 23:49:39 +00:00
## `setItalic`
2016-03-24 12:52:33 +00:00
this.setItalic = function( i )
Make the selected element italic or normal
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `b` Boolean indicating italic (true) or normal (false)
2017-08-03 23:49:39 +00:00
## `getFontFamily`
2016-03-24 12:52:33 +00:00
this.getFontFamily = function()
Returns the current font family
2017-08-03 23:49:39 +00:00
## `setFontFamily`
2016-03-24 12:52:33 +00:00
this.setFontFamily = function( val )
Set the new font family
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` String with the new font family
2017-08-03 23:49:39 +00:00
## `getFontSize`
2016-03-24 12:52:33 +00:00
this.getFontSize = function()
Returns the current font size
2017-08-03 23:49:39 +00:00
## `setFontSize`
2016-03-24 12:52:33 +00:00
this.setFontSize = function( val )
Applies the given font size to the selected element
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` Float with the new font size
2017-08-03 23:49:39 +00:00
## `getText`
2016-03-24 12:52:33 +00:00
this.getText = function()
Returns the current text `textContent` of the selected element
2017-08-03 23:49:39 +00:00
## `setTextContent`
2016-03-24 12:52:33 +00:00
this.setTextContent = function( val )
Updates the text element with the given string
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` String with the new text
2017-08-03 23:49:39 +00:00
## `setImageURL`
2016-03-24 12:52:33 +00:00
this.setImageURL = function( val )
Sets the new image URL for the selected image element. Updates its size if a new URL is given
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` String with the image URL/path
2017-08-03 23:49:39 +00:00
## `setRectRadius`
2016-03-24 12:52:33 +00:00
this.setRectRadius = function( val )
Sets the `rx` & `ry` values to the selected rect element to change its corner radius
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `val` The new radius
2017-08-03 23:49:39 +00:00
# Element manipulation
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `setSegType`
2016-03-24 12:52:33 +00:00
this.setSegType = function( new_type )
Sets the new segment type to the selected segment(s).
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `new_type` Integer with the new segment type See http://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathSeg for list
2017-08-03 23:49:39 +00:00
## `convertToPath`
2016-03-24 12:52:33 +00:00
this.convertToPath = function( elem, getBBox )
Convert selected element to a path, or get the BBox of an element-as-path
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `elem` The DOM element to be converted
* `getBBox` Boolean on whether or not to only return the path’ s BBox
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
If the getBBox flag is true, the resulting path’ s bounding box object. Otherwise the resulting path element is returned.
2017-08-03 23:49:39 +00:00
## `changeSelectedAttributeNoUndo`
2016-03-24 12:52:33 +00:00
var changeSelectedAttributeNoUndo = function( attr, newValue, elems )
This function makes the changes to the elements. It does not add the change to the history stack.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attr` String with the attribute name
* `newValue` String or number with the new attribute value
* `elems` The DOM elements to apply the change to
2017-08-03 23:49:39 +00:00
## `changeSelectedAttribute`
2016-03-24 12:52:33 +00:00
var changeSelectedAttribute = this.changeSelectedAttribute = function( attr, val, elems )
Change the given/selected element and add the original value to the history stack If you want to change all selectedElements, ignore the elems argument. If you want to change only a subset of selectedElements, then send the subset to this function in the elems argument.
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `attr` String with the attribute name
* `newValue` String or number with the new attribute value
* `elems` The DOM elements to apply the change to
2017-08-03 23:49:39 +00:00
## `deleteSelectedElements`
2016-03-24 12:52:33 +00:00
this.deleteSelectedElements = function()
Removes all selected elements from the DOM and adds the change to the history stack
2017-08-03 23:49:39 +00:00
## `groupSelectedElements`
2016-03-24 12:52:33 +00:00
this.groupSelectedElements = function()
Wraps all the selected elements in a group (g) element
2017-08-03 23:49:39 +00:00
## `ungroupSelectedElement`
2016-03-24 12:52:33 +00:00
this.ungroupSelectedElement = function()
Unwraps all the elements in a selected group (g) element. This requires significant recalculations to apply group’ s transforms, etc to its children
2017-08-03 23:49:39 +00:00
## `moveToTopSelectedElement`
2016-03-24 12:52:33 +00:00
this.moveToTopSelectedElement = function()
Repositions the selected element to the bottom in the DOM to appear on top of other elements
2017-08-03 23:49:39 +00:00
## `moveToBottomSelectedElement`
2016-03-24 12:52:33 +00:00
this.moveToBottomSelectedElement = function()
Repositions the selected element to the top in the DOM to appear under other elements
2017-08-03 23:49:39 +00:00
## `moveSelectedElements`
2016-03-24 12:52:33 +00:00
this.moveSelectedElements = function( dx, dy, undoable )
Moves selected elements on the X/Y axis
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `dx` Float with the distance to move on the x-axis
* `dy` Float with the distance to move on the y-axis
* `undoable` Boolean indicating whether or not the action should be undoable
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Batch command for the move
2017-08-03 23:49:39 +00:00
## `cloneSelectedElements`
2016-03-24 12:52:33 +00:00
this.cloneSelectedElements = function()
Create deep DOM copies (clones) of all selected elements and move them slightly from their originals
2017-08-03 23:49:39 +00:00
## `alignSelectedElements`
2016-03-24 12:52:33 +00:00
this.alignSelectedElements = function( type, relative_to )
Aligns selected elements
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `type` String with single character indicating the alignment type
* `relative_to` String that must be one of the following: “selected”, “largest”, “smallest”, “page”
2017-08-03 23:49:39 +00:00
# Additional editor tools
2016-03-24 12:52:33 +00:00
2017-08-03 23:49:39 +00:00
## `updateCanvas`
2016-03-24 12:52:33 +00:00
this.updateCanvas = function( w, h )
Updates the editor canvas width/height/position after a zoom has occurred
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `w` Float with the new width
* `h` Float with the new height
2017-08-03 23:49:39 +00:00
#### Returns
2016-03-24 12:52:33 +00:00
Object with the following values:
* `x` - The canvas’ new x coordinate
* `y` - The canvas’ new y coordinate
* `old_x` - The canvas’ old x coordinate
* `old_y` - The canvas’ old y coordinate
* `d_x` - The x position difference
* `d_y` - The y position difference
2017-08-03 23:49:39 +00:00
## `setBackground`
2016-03-24 12:52:33 +00:00
this.setBackground = function( color, url )
Set the background of the editor (NOT the actual document)
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `color` String with fill color to apply
* `url` URL or path to image to use
2017-08-03 23:49:39 +00:00
## `cycleElement`
2016-03-24 12:52:33 +00:00
this.cycleElement = function( next )
Select the next/previous element within the current layer
2017-08-03 23:49:39 +00:00
#### Parameters
2016-03-24 12:52:33 +00:00
* `next` Boolean where true = next and false = previous element