123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
-
- (function () {'use strict';
- var cbid = 0;
- function getCallbackSetter (d) {
- return function () {
- var t = this,
- args = [].slice.call(arguments),
- cbid = t.send(d, args, function(){});
- return function(newcallback){
- t.callbacks[cbid] = newcallback;
- };
- };
- }
- function addCallback (t, data) {
- var result = data.result || data.error,
- cbid = data.id;
- if (t.callbacks[cbid]) {
- if (data.result) {
- t.callbacks[cbid](result);
- } else {
- t.callbacks[cbid](result, 'error');
- }
- }
- }
- function messageListener (e) {
-
-
- if (typeof e.data !== 'string') {
- return;
- }
- var allowedOrigins = this.allowedOrigins,
- data = e.data && JSON.parse(e.data);
- if (!data || typeof data !== 'object' || data.namespace !== 'svg-edit' ||
- e.source !== this.frame.contentWindow ||
- (allowedOrigins.indexOf('*') === -1 && allowedOrigins.indexOf(e.origin) === -1)
- ) {
- return;
- }
- addCallback(this, data);
- }
- function getMessageListener (t) {
- return function (e) {
- messageListener.call(t, e);
- };
- }
- function EmbeddedSVGEdit (frame, allowedOrigins) {
- if (!(this instanceof EmbeddedSVGEdit)) {
- return new EmbeddedSVGEdit(frame);
- }
- this.allowedOrigins = allowedOrigins || [];
-
- this.frame = frame;
- this.callbacks = {};
-
-
-
-
-
-
-
-
-
-
-
- var i,
- functions = [
- 'clearSvgContentElement', 'setIdPrefix', 'getCurrentDrawing', 'addSvgElementFromJson', 'getTransformList', 'matrixMultiply', 'hasMatrixTransform', 'transformListToTransform', 'convertToNum', 'findDefs', 'getUrlFromAttr', 'getHref', 'setHref', 'getBBox', 'getRotationAngle', 'getElem', 'getRefElem', 'assignAttributes', 'cleanupElement', 'remapElement', 'recalculateDimensions', 'sanitizeSvg', 'runExtensions', 'addExtension', 'round', 'getIntersectionList', 'getStrokedBBox', 'getVisibleElements', 'getVisibleElementsAndBBoxes', 'groupSvgElem', 'getId', 'getNextId', 'call', 'bind', 'prepareSvg', 'setRotationAngle', 'recalculateAllSelectedDimensions', 'clearSelection', 'addToSelection', 'selectOnly', 'removeFromSelection', 'selectAllInCurrentLayer', 'getMouseTarget', 'removeUnusedDefElems', 'svgCanvasToString', 'svgToString', 'embedImage', 'setGoodImage', 'open', 'save', 'rasterExport', 'exportPDF', 'getSvgString', 'randomizeIds', 'uniquifyElems', 'setUseData', 'convertGradients', 'convertToGroup', 'setSvgString', 'importSvgString', 'identifyLayers', 'createLayer', 'cloneLayer', 'deleteCurrentLayer', 'setCurrentLayer', 'renameCurrentLayer', 'setCurrentLayerPosition', 'setLayerVisibility', 'moveSelectedToLayer', 'mergeLayer', 'mergeAllLayers', 'leaveContext', 'setContext', 'clear', 'linkControlPoints', 'getContentElem', 'getRootElem', 'getSelectedElems', 'getResolution', 'getZoom', 'getVersion', 'setUiStrings', 'setConfig', 'getTitle', 'setGroupTitle', 'getDocumentTitle', 'setDocumentTitle', 'getEditorNS', 'setResolution', 'getOffset', 'setBBoxZoom', 'setZoom', 'getMode', 'setMode', 'getColor', 'setColor', 'setGradient', 'setPaint', 'setStrokePaint', 'setFillPaint', 'getStrokeWidth', 'setStrokeWidth', 'setStrokeAttr', 'getStyle', 'getOpacity', 'setOpacity', 'getFillOpacity', 'getStrokeOpacity', 'setPaintOpacity', 'getPaintOpacity', 'getBlur', 'setBlurNoUndo', 'setBlurOffsets', 'setBlur', 'getBold', 'setBold', 'getItalic', 'setItalic', 'getFontFamily', 'setFontFamily', 'setFontColor', 'getFontColor', 'getFontSize', 'setFontSize', 'getText', 'setTextContent', 'setImageURL', 'setLinkURL', 'setRectRadius', 'makeHyperlink', 'removeHyperlink', 'setSegType', 'convertToPath', 'changeSelectedAttribute', 'deleteSelectedElements', 'cutSelectedElements', 'copySelectedElements', 'pasteElements', 'groupSelectedElements', 'pushGroupProperties', 'ungroupSelectedElement', 'moveToTopSelectedElement', 'moveToBottomSelectedElement', 'moveUpDownSelected', 'moveSelectedElements', 'cloneSelectedElements', 'alignSelectedElements', 'updateCanvas', 'setBackground', 'cycleElement', 'getPrivateMethods', 'zoomChanged', 'ready'
- ];
-
- for (i = 0; i < functions.length; i++) {
- this[functions[i]] = getCallbackSetter(functions[i]);
- }
-
-
- window.addEventListener('message', getMessageListener(this), false);
- }
- EmbeddedSVGEdit.prototype.send = function (name, args, callback){
- var t = this;
- cbid++;
- this.callbacks[cbid] = callback;
- setTimeout((function (cbid) {
- return function () {
-
-
- if (window.location.origin === t.frame.contentWindow.location.origin) {
-
-
-
-
-
-
- var message = {id: cbid},
- svgCanvas = t.frame.contentWindow.svgCanvas;
- try {
- message.result = svgCanvas[name].apply(svgCanvas, args);
- }
- catch (err) {
- message.error = err.message;
- }
- addCallback(t, message);
- }
- else {
- t.frame.contentWindow.postMessage(JSON.stringify({namespace: 'svgCanvas', id: cbid, name: name, args: args}), '*');
- }
- };
- }(cbid)), 0);
- return cbid;
- };
- window.embedded_svg_edit = EmbeddedSVGEdit;
- window.EmbeddedSVGEdit = EmbeddedSVGEdit;
- }());
|