Added extension that adds Image library option to main menu, includes minimal local and external libraries
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1630 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
5a66cd4f9f
commit
d627c01d1e
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* ext-imagelib.js
|
||||
*
|
||||
* Licensed under the Apache License, Version 2
|
||||
*
|
||||
* Copyright(c) 2010 Alexis Deveria
|
||||
*
|
||||
*/
|
||||
|
||||
svgEditor.addExtension("imagelib", function() {
|
||||
|
||||
var img_libs = [{
|
||||
name: 'Demo library (local)',
|
||||
url: 'extensions/imagelib/index.html',
|
||||
description: 'Demonstration library for SVG-edit on this server'
|
||||
},
|
||||
{
|
||||
name: 'Demo library (external)',
|
||||
url: 'http://a.deveria.com/tests/clip-art/',
|
||||
description: 'Demonstration library for SVG-edit on another domain'
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
function closeBrowser() {
|
||||
$('#imgbrowse_holder').hide();
|
||||
}
|
||||
|
||||
window.addEventListener("message", function(evt) {
|
||||
// Receive postMessage data
|
||||
var response = evt.data;
|
||||
|
||||
if(!response) {
|
||||
$.alert('No data was given', closeBrowser);
|
||||
return;
|
||||
}
|
||||
|
||||
var char1 = response.charAt(0);
|
||||
|
||||
switch (char1) {
|
||||
case '<':
|
||||
svgEditor.loadFromString(response);
|
||||
break;
|
||||
case 'd':
|
||||
if(response.indexOf('data:') === 0) {
|
||||
svgEditor.loadFromDataURI(response);
|
||||
break;
|
||||
}
|
||||
// Else fall through
|
||||
default:
|
||||
$.alert('Unexpected data was returned', closeBrowser);
|
||||
return;
|
||||
}
|
||||
|
||||
closeBrowser();
|
||||
|
||||
}, true);
|
||||
|
||||
|
||||
function showBrowser() {
|
||||
var browser = $('#imgbrowse');
|
||||
if(!browser.length) {
|
||||
$('<div id=imgbrowse_holder><div id=imgbrowse>\
|
||||
</div></div>').insertAfter('#svg_docprops');
|
||||
browser = $('#imgbrowse');
|
||||
|
||||
var all_libs = 'Select an image library';
|
||||
|
||||
var lib_opts = $('<ul id=imglib_opts>').appendTo(browser);
|
||||
var frame = $('<iframe/>').prependTo(browser).hide().wrap('<div>');
|
||||
|
||||
var header = $('<h1>').prependTo(browser).text(all_libs);
|
||||
|
||||
var cancel = $('<input type=button value=Cancel>').appendTo(browser).click(function() {
|
||||
$('#imgbrowse_holder').hide();
|
||||
}).css({
|
||||
position: 'absolute',
|
||||
top: 5,
|
||||
right: 5
|
||||
});
|
||||
|
||||
var back = $('<input type=button value="Show libraries">').appendTo(browser).click(function() {
|
||||
frame.hide();
|
||||
lib_opts.show();
|
||||
header.text(all_libs);
|
||||
}).css({
|
||||
position: 'absolute',
|
||||
top: 5,
|
||||
left: 5
|
||||
});
|
||||
|
||||
$.each(img_libs, function(i, opts) {
|
||||
$('<li>').appendTo(lib_opts).text(opts.name).click(function() {
|
||||
frame.attr('src', opts.url).show();
|
||||
header.text(name);
|
||||
lib_opts.hide();
|
||||
}).append('<span>' + opts.description + '</span>');
|
||||
});
|
||||
|
||||
} else {
|
||||
$('#imgbrowse_holder').show();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
svgicons: "extensions/ext-imagelib.xml",
|
||||
buttons: [{
|
||||
id: "tool_imagelib",
|
||||
type: "app_menu", // _flyout
|
||||
position: 4,
|
||||
title: "Image library",
|
||||
events: {
|
||||
"mouseup": showBrowser
|
||||
}
|
||||
}],
|
||||
callback: function() {
|
||||
|
||||
$('<style>').text('\
|
||||
#imgbrowse_holder {\
|
||||
position: absolute;\
|
||||
top: 0;\
|
||||
left: 0;\
|
||||
width: 100%;\
|
||||
height: 100%;\
|
||||
background-color: rgba(0, 0, 0, .5);\
|
||||
z-index: 4;\
|
||||
}\
|
||||
\
|
||||
#imgbrowse {\
|
||||
position: absolute;\
|
||||
top: 25px;\
|
||||
left: 25px;\
|
||||
right: 25px;\
|
||||
bottom: 25px;\
|
||||
min-width: 300px;\
|
||||
min-height: 200px;\
|
||||
background: #B0B0B0;\
|
||||
border: 1px outset #777;\
|
||||
}\
|
||||
#imgbrowse h1 {\
|
||||
font-size: 20px;\
|
||||
margin: .4em;\
|
||||
text-align: center;\
|
||||
}\
|
||||
#imgbrowse > div,\
|
||||
#imgbrowse > ul {\
|
||||
position: absolute;\
|
||||
top: 36px;\
|
||||
left: 10px;\
|
||||
right: 10px;\
|
||||
bottom: 10px;\
|
||||
border: 1px solid #666;\
|
||||
background: white;\
|
||||
margin: 0;\
|
||||
padding: 0;\
|
||||
overflow: auto;\
|
||||
}\
|
||||
#imgbrowse li {\
|
||||
list-style: none;\
|
||||
padding: .5em;\
|
||||
background: #E8E8E8;\
|
||||
border-bottom: 1px solid #B0B0B0;\
|
||||
line-height: 1.2em;\
|
||||
font-style: sans-serif;\
|
||||
}\
|
||||
#imgbrowse li > span {\
|
||||
color: #666;\
|
||||
font-size: 15px;\
|
||||
display: block;\
|
||||
}\
|
||||
#imgbrowse li:hover {\
|
||||
background: #FFC;\
|
||||
cursor: pointer;\
|
||||
}\
|
||||
#imgbrowse iframe {\
|
||||
width: 100%;\
|
||||
height: 100%;\
|
||||
border: 0;\
|
||||
}\
|
||||
').appendTo('head');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<g id="tool_imagelib">
|
||||
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">
|
||||
<path fill="#c0c0c0" stroke-linejoin="round" stroke-width="14" stroke="#202020" fill-rule="nonzero" d="m70,194.72501l0,0c0,-10.30901 35.8172,-18.666 80,-18.666c44.18298,0 80,8.35699 80,18.666l0,74.66699c0,10.30899 -35.81702,18.66699 -80,18.66699c-44.1828,0 -80,-8.358 -80,-18.66699l0,-74.66699z"/>
|
||||
<path fill="#c0c0c0" stroke-linejoin="round" stroke-width="14" stroke="#202020" fill-rule="nonzero" d="m70,114.608l0,0c0,-10.309 35.8172,-18.6668 80,-18.6668c44.18298,0 80,8.3578 80,18.6668l0,74.66699c0,10.30901 -35.81702,18.666 -80,18.666c-44.1828,0 -80,-8.35699 -80,-18.666l0,-74.66699z"/>
|
||||
<path fill="#c0c0c0" stroke-linejoin="round" stroke-width="14" stroke="#202020" fill-rule="nonzero" d="m70,33.6667l0,0c0,-10.3094 35.8172,-18.6667 80,-18.6667c44.18298,0 80,8.3573 80,18.6667l0,74.6663c0,10.31 -35.81702,18.667 -80,18.667c-44.1828,0 -80,-8.357 -80,-18.667l0,-74.6663z"/>
|
||||
<path id="svg_1" fill="#c0c0c0" stroke-linejoin="round" stroke-width="14" stroke="#202020" fill-rule="nonzero" d="m230,32.33334c0,10.30931 -35.81726,18.66666 -80,18.66666c-44.1828,0 -80,-8.35735 -80,-18.66666"/>
|
||||
</svg>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
|
@ -45,7 +45,7 @@
|
|||
imgPath: 'images/',
|
||||
langPath: 'locale/',
|
||||
extPath: 'extensions/',
|
||||
extensions: ['ext-markers.js','ext-connector.js', 'ext-eyedropper.js', 'ext-shapes.js'],
|
||||
extensions: ['ext-markers.js','ext-connector.js', 'ext-eyedropper.js', 'ext-shapes.js', 'ext-imagelib.js'],
|
||||
initTool: 'select',
|
||||
wireframe: false
|
||||
},
|
||||
|
@ -909,7 +909,11 @@
|
|||
} else {
|
||||
fallback_obj[id] = btn.icon;
|
||||
var svgicon = btn.svgicon?btn.svgicon:btn.id;
|
||||
placement_obj['#' + id] = svgicon;
|
||||
if(btn.type == 'app_menu') {
|
||||
placement_obj['#' + id + ' > div'] = svgicon;
|
||||
} else {
|
||||
placement_obj['#' + id] = svgicon;
|
||||
}
|
||||
}
|
||||
|
||||
var cls, parent;
|
||||
|
@ -928,9 +932,13 @@
|
|||
if(!$(parent).length)
|
||||
$('<div>', {id: btn.panel}).appendTo("#tools_top");
|
||||
break;
|
||||
case 'app_menu':
|
||||
cls = '';
|
||||
parent = '#main_menu ul';
|
||||
break;
|
||||
}
|
||||
|
||||
var button = $(btn.list?'<li/>':'<div/>')
|
||||
var button = $((btn.list || btn.type == 'app_menu')?'<li/>':'<div/>')
|
||||
.attr("id", id)
|
||||
.attr("title", btn.title)
|
||||
.addClass(cls);
|
||||
|
@ -940,7 +948,7 @@
|
|||
} else {
|
||||
button.appendTo(parent);
|
||||
}
|
||||
|
||||
|
||||
if(btn.type =='mode_flyout') {
|
||||
// Add to flyout menu / make flyout menu
|
||||
// var opts = btn.includeWith;
|
||||
|
@ -992,6 +1000,8 @@
|
|||
// flyout_holder.append(button);
|
||||
// cur_h.reverse();
|
||||
// }
|
||||
} else if(btn.type == 'app_menu') {
|
||||
button.append('<div>').append(btn.title);
|
||||
}
|
||||
|
||||
} else if(btn.list) {
|
||||
|
@ -3629,46 +3639,48 @@
|
|||
// var lang = ('lang' in curPrefs) ? curPrefs.lang : null;
|
||||
Editor.putLocale(null, good_langs);
|
||||
|
||||
try{
|
||||
json_encode = function(obj){
|
||||
//simple partial JSON encoder implementation
|
||||
if(window.JSON && JSON.stringify) return JSON.stringify(obj);
|
||||
var enc = arguments.callee; //for purposes of recursion
|
||||
if(typeof obj == "boolean" || typeof obj == "number"){
|
||||
return obj+'' //should work...
|
||||
}else if(typeof obj == "string"){
|
||||
//a large portion of this is stolen from Douglas Crockford's json2.js
|
||||
return '"'+
|
||||
obj.replace(
|
||||
/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
|
||||
, function (a) {
|
||||
return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
})
|
||||
+'"'; //note that this isn't quite as purtyful as the usualness
|
||||
}else if(obj.length){ //simple hackish test for arrayish-ness
|
||||
for(var i = 0; i < obj.length; i++){
|
||||
obj[i] = enc(obj[i]); //encode every sub-thingy on top
|
||||
}
|
||||
return "["+obj.join(",")+"]";
|
||||
}else{
|
||||
var pairs = []; //pairs will be stored here
|
||||
for(var k in obj){ //loop through thingys
|
||||
pairs.push(enc(k)+":"+enc(obj[k])); //key: value
|
||||
}
|
||||
return "{"+pairs.join(",")+"}" //wrap in the braces
|
||||
}
|
||||
}
|
||||
window.addEventListener("message", function(e){
|
||||
var cbid = parseInt(e.data.substr(0, e.data.indexOf(";")));
|
||||
try{
|
||||
e.source.postMessage("SVGe"+cbid+";"+json_encode(eval(e.data)), e.origin);
|
||||
}catch(err){
|
||||
e.source.postMessage("SVGe"+cbid+";error:"+err.message, e.origin);
|
||||
}
|
||||
}, false)
|
||||
}catch(err){
|
||||
window.embed_error = err;
|
||||
}
|
||||
// Not sure what this was being used for...commented out until known.
|
||||
// The "message" event listener was interfering with image lib responder
|
||||
// try{
|
||||
// json_encode = function(obj){
|
||||
// //simple partial JSON encoder implementation
|
||||
// if(window.JSON && JSON.stringify) return JSON.stringify(obj);
|
||||
// var enc = arguments.callee; //for purposes of recursion
|
||||
// if(typeof obj == "boolean" || typeof obj == "number"){
|
||||
// return obj+'' //should work...
|
||||
// }else if(typeof obj == "string"){
|
||||
// //a large portion of this is stolen from Douglas Crockford's json2.js
|
||||
// return '"'+
|
||||
// obj.replace(
|
||||
// /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g
|
||||
// , function (a) {
|
||||
// return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
// })
|
||||
// +'"'; //note that this isn't quite as purtyful as the usualness
|
||||
// }else if(obj.length){ //simple hackish test for arrayish-ness
|
||||
// for(var i = 0; i < obj.length; i++){
|
||||
// obj[i] = enc(obj[i]); //encode every sub-thingy on top
|
||||
// }
|
||||
// return "["+obj.join(",")+"]";
|
||||
// }else{
|
||||
// var pairs = []; //pairs will be stored here
|
||||
// for(var k in obj){ //loop through thingys
|
||||
// pairs.push(enc(k)+":"+enc(obj[k])); //key: value
|
||||
// }
|
||||
// return "{"+pairs.join(",")+"}" //wrap in the braces
|
||||
// }
|
||||
// }
|
||||
// window.addEventListener("message", function(e){
|
||||
// var cbid = parseInt(e.data.substr(0, e.data.indexOf(";")));
|
||||
// try{
|
||||
// e.source.postMessage("SVGe"+cbid+";"+json_encode(eval(e.data)), e.origin);
|
||||
// }catch(err){
|
||||
// e.source.postMessage("SVGe"+cbid+";error:"+err.message, e.origin);
|
||||
// }
|
||||
// }, false)
|
||||
// }catch(err){
|
||||
// window.embed_error = err;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -394,6 +394,10 @@ var Utils = this.Utils = function() {
|
|||
// Cross-browser compatible method of converting a string to an XML tree
|
||||
// found this function here: http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f
|
||||
"text2xml": function(sXML) {
|
||||
if(sXML.indexOf('<svg:svg') !== -1) {
|
||||
sXML = sXML.replace(/<(\/?)svg:/g, '<$1').replace('xmlns:svg', 'xmlns');
|
||||
}
|
||||
|
||||
var out;
|
||||
try{
|
||||
var dXML = ($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser();
|
||||
|
|
Loading…
Reference in New Issue