Minor: Spacing
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2825 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
f854c00f4c
commit
582e71cb1b
|
@ -7,7 +7,7 @@
|
|||
<script src="embedapi.js"></script>
|
||||
<script>
|
||||
/*globals $, EmbeddedSVGEdit*/
|
||||
var initEmbed;
|
||||
var initEmbed;
|
||||
$(function () {'use strict';
|
||||
|
||||
var svgCanvas = null;
|
||||
|
@ -38,33 +38,33 @@
|
|||
function saveSvg() {
|
||||
svgCanvas.getSvgString()(handleSvgData);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Add event handlers
|
||||
$('#load').click(loadSvg);
|
||||
$('#save').click(saveSvg);
|
||||
$('#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>'
|
||||
)
|
||||
);
|
||||
});
|
||||
$('#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>'
|
||||
)
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<button id="load">Load example</button>
|
||||
<button id="save">Save data</button>
|
||||
<button id="export">Export data</button>
|
||||
<button id="export">Export data</button>
|
||||
<br/>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -10,9 +10,9 @@ svgCanvas.setSvgString('string')
|
|||
- Or if a callback is needed:
|
||||
svgCanvas.setSvgString('string')(function(data, error){
|
||||
if (error){
|
||||
// There was an error
|
||||
// There was an error
|
||||
} else{
|
||||
// Handle data
|
||||
// Handle data
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -41,13 +41,13 @@ var cbid = 0;
|
|||
|
||||
function getCallbackSetter (d) {
|
||||
return function () {
|
||||
var t = this, // New callback
|
||||
args = [].slice.call(arguments),
|
||||
cbid = t.send(d, args, function(){}); // The callback (currently it's nothing, but will be set later)
|
||||
var t = this, // New callback
|
||||
args = [].slice.call(arguments),
|
||||
cbid = t.send(d, args, function(){}); // The callback (currently it's nothing, but will be set later)
|
||||
|
||||
return function(newcallback){
|
||||
t.callbacks[cbid] = newcallback; // Set callback
|
||||
};
|
||||
return function(newcallback){
|
||||
t.callbacks[cbid] = newcallback; // Set callback
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -60,11 +60,11 @@ 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');
|
||||
}
|
||||
if (data.result) {
|
||||
t.callbacks[cbid](result);
|
||||
} else {
|
||||
t.callbacks[cbid](result, 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,15 +72,15 @@ function messageListener (e) {
|
|||
// We accept and post strings as opposed to objects for the sake of IE9 support; this
|
||||
// will most likely be changed in the future
|
||||
if (typeof e.data !== 'string') {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
var allowedOrigins = this.allowedOrigins,
|
||||
data = e.data && JSON.parse(e.data);
|
||||
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)
|
||||
e.source !== this.frame.contentWindow ||
|
||||
(allowedOrigins.indexOf('*') === -1 && allowedOrigins.indexOf(e.origin) === -1)
|
||||
) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
addCallback(this, data);
|
||||
}
|
||||
|
@ -94,12 +94,12 @@ function getMessageListener (t) {
|
|||
/**
|
||||
* @param {HTMLIFrameElement} frame
|
||||
* @param {array} [allowedOrigins=[]] 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
|
||||
* 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
|
||||
*/
|
||||
function EmbeddedSVGEdit (frame, allowedOrigins) {
|
||||
if (!(this instanceof EmbeddedSVGEdit)) { // Allow invocation without 'new' keyword
|
||||
return new EmbeddedSVGEdit(frame);
|
||||
return new EmbeddedSVGEdit(frame);
|
||||
}
|
||||
this.allowedOrigins = allowedOrigins || [];
|
||||
// Initialize communication
|
||||
|
@ -125,7 +125,7 @@ function EmbeddedSVGEdit (frame, allowedOrigins) {
|
|||
|
||||
// TODO: rewrite the following, it's pretty scary.
|
||||
for (i = 0; i < functions.length; i++) {
|
||||
this[functions[i]] = getCallbackSetter(functions[i]);
|
||||
this[functions[i]] = getCallbackSetter(functions[i]);
|
||||
}
|
||||
|
||||
// Older IE may need a polyfill for addEventListener, but so it would for SVG
|
||||
|
|
|
@ -990,18 +990,18 @@ PubSub implementation
|
|||
// @TODO: Add different output options
|
||||
};
|
||||
|
||||
switch (unit) {
|
||||
case 'pt': k = 1; break;
|
||||
case 'mm': k = 72 / 25.4; break;
|
||||
case 'cm': k = 72 / 2.54; break;
|
||||
case 'in': k = 72; break;
|
||||
case 'px': k = 96 / 72; break;
|
||||
case 'pc': k = 12; break;
|
||||
case 'em': k = 12; break;
|
||||
case 'ex': k = 6; break;
|
||||
default:
|
||||
throw ('Invalid unit: ' + unit);
|
||||
}
|
||||
switch (unit) {
|
||||
case 'pt': k = 1; break;
|
||||
case 'mm': k = 72 / 25.4; break;
|
||||
case 'cm': k = 72 / 2.54; break;
|
||||
case 'in': k = 72; break;
|
||||
case 'px': k = 96 / 72; break;
|
||||
case 'pc': k = 12; break;
|
||||
case 'em': k = 12; break;
|
||||
case 'ex': k = 6; break;
|
||||
default:
|
||||
throw ('Invalid unit: ' + unit);
|
||||
}
|
||||
|
||||
// Dimensions are stored as user units and converted to points on output
|
||||
if (pageFormats.hasOwnProperty(format_as_string)) {
|
||||
|
|
|
@ -206,7 +206,7 @@ TODOS
|
|||
return function (win, data) {
|
||||
if (window.canvg) {
|
||||
callCanvg(win, data);
|
||||
} else { // Might not be set up yet
|
||||
} else { // Might not be set up yet
|
||||
$.getScript('canvg/rgbcolor.js', function() {
|
||||
$.getScript('canvg/canvg.js', function() {
|
||||
callCanvg(win, data);
|
||||
|
|
Loading…
Reference in New Issue