git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2666 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-02-02 00:34:04 +00:00
parent adbec3e33e
commit a5083f0394
1 changed files with 60 additions and 58 deletions

View File

@ -1,3 +1,5 @@
/*globals $, svgEditor, svgedit, svgCanvas, DOMParser*/
/*jslint vars: true, eqeq: true, es5: true, todo: true */
/*
* ext-imagelib.js
*
@ -7,7 +9,7 @@
*
*/
svgEditor.addExtension("imagelib", function() {
svgEditor.addExtension("imagelib", function() {'use strict';
var uiStrings = svgEditor.uiStrings;
@ -59,6 +61,7 @@ svgEditor.addExtension("imagelib", function() {
var cur_meta;
var tranfer_stopped = false;
var pending = {};
var preview, submit;
window.addEventListener("message", function(evt) {
// Receive postMessage data
@ -77,7 +80,7 @@ svgEditor.addExtension("imagelib", function() {
catch (e) {}
var char1 = response.charAt(0);
var id;
var svg_str;
var img_str;
@ -88,21 +91,20 @@ svgEditor.addExtension("imagelib", function() {
if (char1 == '|') {
var secondpos = response.indexOf('|', 1);
var id = response.substr(1, secondpos-1);
id = response.substr(1, secondpos-1);
response = response.substr(secondpos+1);
char1 = response.charAt(0);
}
// Hide possible transfer dialog box
$('#dialog_box').hide();
var entry, cur_meta;
switch (char1) {
case '{':
// Metadata
tranfer_stopped = false;
var cur_meta = JSON.parse(response);
cur_meta = JSON.parse(response);
pending[cur_meta.id] = cur_meta;
@ -118,7 +120,7 @@ svgEditor.addExtension("imagelib", function() {
$('#dialog_box').hide();
});
} else {
var entry = $('<div>' + message + '</div>').data('id', cur_meta.id);
entry = $('<div>' + message + '</div>').data('id', cur_meta.id);
preview.append(entry);
cur_meta.entry = entry;
}
@ -175,14 +177,15 @@ svgEditor.addExtension("imagelib", function() {
case 'm':
// Import multiple
multi_arr.push([(svg_str ? 'svg' : 'img'), response]);
var cur_meta = pending[id];
var title;
cur_meta = pending[id];
if (svg_str) {
if (cur_meta && cur_meta.name) {
var title = cur_meta.name;
title = cur_meta.name;
} else {
// Try to find a title
var xml = new DOMParser().parseFromString(response, 'text/xml').documentElement;
var title = $(xml).children('title').first().text() || '(SVG #' + response.length + ')';
title = $(xml).children('title').first().text() || '(SVG #' + response.length + ')';
}
if (cur_meta) {
preview.children().each(function() {
@ -201,12 +204,12 @@ svgEditor.addExtension("imagelib", function() {
}
} else {
if (cur_meta && cur_meta.preview_url) {
var title = cur_meta.name || '';
title = cur_meta.name || '';
}
if (cur_meta && cur_meta.preview_url) {
var entry = '<img src="' + cur_meta.preview_url + '">' + title;
entry = '<img src="' + cur_meta.preview_url + '">' + title;
} else {
var entry = '<img src="' + response + '">';
entry = '<img src="' + response + '">';
}
if (cur_meta) {
@ -225,9 +228,9 @@ svgEditor.addExtension("imagelib", function() {
break;
case 'o':
// Open
if(!svg_str) break;
if (!svg_str) {break;}
svgEditor.openPrep(function(ok) {
if(!ok) return;
if (!ok) {return;}
svgCanvas.clear();
svgCanvas.setSvgString(response);
// updateCanvas();
@ -237,8 +240,6 @@ svgEditor.addExtension("imagelib", function() {
}
}, true);
var preview, submit;
function toggleMulti(show) {
$('#lib_framewrap, #imglib_opts').css({right: (show ? 200 : 10)});
@ -338,6 +339,7 @@ svgEditor.addExtension("imagelib", function() {
case 'm':
// Import multiple
toggleMulti(true);
break;
}
}).css({
'margin-top': 10
@ -453,6 +455,6 @@ svgEditor.addExtension("imagelib", function() {
}\
').appendTo('head');
}
}
};
});