2013-10-13 23:59:32 +00:00
<!DOCTYPE html>
< html xmlns = "http://www.w3.org/1999/xhtml" >
2010-09-20 18:55:10 +00:00
< head >
2013-10-13 23:59:32 +00:00
< meta charset = "utf-8" / >
2014-01-31 08:57:22 +00:00
< title > Embed API< / title >
2013-10-13 23:59:32 +00:00
< script src = "jquery.js" > < / script >
2014-01-31 08:57:22 +00:00
< script src = "embedapi.js" > < / script >
< script >
2013-10-13 23:59:32 +00:00
/*globals $, EmbeddedSVGEdit*/
2014-04-09 22:47:39 +00:00
var initEmbed;
2013-10-13 23:59:32 +00:00
$(function () {'use strict';
2014-01-31 08:57:22 +00:00
2013-10-13 23:59:32 +00:00
var svgCanvas = null;
2010-09-20 18:55:10 +00:00
2014-02-22 04:08:24 +00:00
initEmbed = function () {
2014-01-31 08:57:22 +00:00
var doc, mainButton,
2013-10-13 23:59:32 +00:00
frame = document.getElementById('svgedit');
2014-01-31 08:57:22 +00:00
svgCanvas = new EmbeddedSVGEdit(frame);
// Hide main button, as we will be controlling new, load, save, etc. from the host document
doc = frame.contentDocument || frame.contentWindow.document;
mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none';
2014-02-22 04:08:24 +00:00
};
2013-02-19 16:30:56 +00:00
2014-01-31 08:57:22 +00:00
function handleSvgData(data, error) {
if (error) {
alert('error ' + error);
} else {
alert('Congratulations. Your SVG string is back in the host page, do with it what you will\n\n' + data);
}
}
2010-09-20 18:55:10 +00:00
2014-01-31 08:57:22 +00:00
function loadSvg() {
2014-02-22 04:08:24 +00:00
var svgexample = '< svg width = "640" height = "480" xmlns:xlink = "http://www.w3.org/1999/xlink" xmlns = "http://www.w3.org/2000/svg" > < g > < title > Layer 1< \/title>< rect stroke-width = "5" stroke = "#000000" fill = "#FF0000" id = "svg_1" height = "35" width = "51" y = "35" x = "32" / > < ellipse ry = "15" rx = "24" stroke-width = "5" stroke = "#000000" fill = "#0000ff" id = "svg_2" cy = "60" cx = "66" / > < \/g>< \/svg>';
2014-01-31 08:57:22 +00:00
svgCanvas.setSvgString(svgexample);
}
2010-09-20 18:55:10 +00:00
2014-01-31 08:57:22 +00:00
function saveSvg() {
svgCanvas.getSvgString()(handleSvgData);
}
2014-04-09 22:47:39 +00:00
function exportSvg() {
var str = document.getElementById('svgedit').contentWindow.svgEditor.uiStrings.notification.loadingImage;
var exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('< title > ' + str + '< / title > < h1 > ' + str + '< / h1 > '),
'svg-edit-exportWindow'
);
svgCanvas.rasterExport('PNG', null, exportWindow.name);
}
2013-10-13 23:59:32 +00:00
// Add event handlers
$('#load').click(loadSvg);
$('#save').click(saveSvg);
2014-04-09 22:47:39 +00:00
$('#export').click(exportSvg);
$('body').append(
$('< iframe src = "svg-editor.html?extensions=ext-xdomain-messaging.js' +
window.location.href.replace(/\?(.*)$/, '& $1') + // Append arguments to this file onto the iframe
'" width="900px" height="600px" id="svgedit" onload="initEmbed();">< / iframe > '
)
);
});
2014-01-31 08:57:22 +00:00
< / script >
2013-10-13 23:59:32 +00:00
< / head >
< body >
2014-01-31 08:57:22 +00:00
< button id = "load" > Load example< / button >
< button id = "save" > Save data< / button >
2014-04-09 22:47:39 +00:00
< button id = "export" > Export data< / button >
2014-01-31 08:57:22 +00:00
< br / >
2010-09-20 18:55:10 +00:00
< / body >
< / html >