/* * ext-imagelib.js * * Licensed under the Apache License, Version 2 * * Copyright(c) 2010 Alexis Deveria * */ svgEditor.addExtension("imagelib", function() { var uiStrings = svgEditor.uiStrings; var img_libs = [{ name: 'Demo library (local)', url: 'extensions/imagelib/index.html', description: 'Demonstration library for SVG-edit on this server' }, { name: 'IAN Symbol Libraries', url: 'http://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php', description: 'Free library of illustrations' } ]; var xlinkns = "http://www.w3.org/1999/xlink"; function closeBrowser() { $('#imgbrowse_holder').hide(); } function importImage(url) { var newImage = svgCanvas.addSvgElementFromJson({ "element": "image", "attr": { "x": 0, "y": 0, "width": 0, "height": 0, "id": svgCanvas.getNextId(), "style": "pointer-events:inherit" } }); svgCanvas.clearSelection(); svgCanvas.addToSelection([newImage]); svgCanvas.setImageURL(url); } var mode = 's'; var multi_arr = []; var cur_meta; var tranfer_stopped = false; var pending = {}; window.addEventListener("message", function(evt) { // Receive postMessage data var response = evt.data; if(!response) { // Do nothing return; } var char1 = response.charAt(0); var svg_str; var img_str; if(char1 != "{" && tranfer_stopped) { tranfer_stopped = false; return; } if(char1 == '|') { var secondpos = response.indexOf('|', 1); var id = response.substr(1, secondpos-1); response = response.substr(secondpos+1); char1 = response.charAt(0); } // Hide possible transfer dialog box $('#dialog_box').hide(); switch (char1) { case '{': // Metadata tranfer_stopped = false; var cur_meta = JSON.parse(response); pending[cur_meta.id] = cur_meta; var name = (cur_meta.name || 'file'); var message = uiStrings.notification.retrieving.replace('%s', name); if(mode != 'm') { $.process_cancel(message, function() { tranfer_stopped = true; // Should a message be sent back to the frame? $('#dialog_box').hide(); }); } else { var entry = $('