Class: EmbeddedSVGEdit

EmbeddedSVGEdit~EmbeddedSVGEdit(frame, allowedOriginsopt)

Embedded SVG-edit API. General usage:

  • Have an iframe somewhere pointing to a version of svg-edit > r1000.

Constructor

new EmbeddedSVGEdit(frame, allowedOriginsopt)

Parameters:
Name Type Attributes Default Description
frame HTMLIFrameElement
allowedOrigins Array.<string> <optional>
[]

Array of origins from which incoming messages will be allowed when same origin is not used; defaults to none. If supplied, it should probably be the same as svgEditor's allowedOrigins

Source:
Example
// Initialize the magic with:
const svgCanvas = new EmbeddedSVGEdit(window.frames.svgedit);

// Pass functions in this format:
svgCanvas.setSvgString('string');

// Or if a callback is needed:
svgCanvas.setSvgString('string')(function (data, error) {
  if (error) {
     // There was an error
  } else {
     // Handle data
  }
});

// Everything is done with the same API as the real svg-edit,
// and all documentation is unchanged.

// However, this file depends on the postMessage API which
// can only support JSON-serializable arguments and
// return values, so, for example, arguments whose value is
// 'undefined', a function, a non-finite number, or a built-in
// object like Date(), RegExp(), etc. will most likely not behave
// as expected. In such a case one may need to host
// the SVG editor on the same domain and reference the
// JavaScript methods on the frame itself.

// The only other difference is when handling returns:
// the callback notation is used instead.
const blah = new EmbeddedSVGEdit(window.frames.svgedit);
blah.clearSelection('woot', 'blah', 1337, [1, 2, 3, 4, 5, 'moo'], -42, {
     a: 'tree', b: 6, c: 9
})(function () { console.log('GET DATA', args); });

Methods

send(name, args, callback) → {Integer}

Parameters:
Name Type Description
name string
args ArgumentsArray

Signature dependent on function

callback GenericCallback

(This may be better than a promise in case adding an event.)

Source:
Returns:
Type
Integer