Preliminary SVG-edit Support

WYSIWYG SVG editing.

Still no support for mixed
SVG/MathML content, yet.
This commit is contained in:
Jacques Distler 2010-02-05 21:36:35 -06:00
parent 954bcb52c2
commit c3ed5b461b
224 changed files with 32910 additions and 21 deletions

View file

@ -71,6 +71,69 @@ function addS5button(page_name) {
}
}
function setupSVGedit(path){
var f = $('MarkupHelp');
var selected;
var before;
var after;
// create a control button
if (f) {
var SVGeditButton = new Element('input', {id:'SVGeditButton', type:'button', value: 'Create an SVG graphic'});
f.insert({top: SVGeditButton});
SVGeditButton.disabled = true;
Event.observe(SVGeditButton, 'click', function(){
if (selected) {
var editor = window.open(path +'?source=data:image/svg+xml;base64,' + window.btoa(selected), 'Spoons!');
} else {
var editor = window.open(path, 'Spoons!');
}
});
}
var t = $('content');
var callback = function(){
// This is triggered by 'onmouseup' events
var sel = window.getSelection();
var a = sel.anchorOffset;
var f = sel.focusOffset;
// A bit of ugliness, because Gecko-based browsers
// don't support getSelection in textareas
if (t.selectionStart ) {
var begin = t.selectionStart;
var end = t.selectionEnd;
} else {
if( a < f) {
begin = a;
end = f;
} else {
begin = f;
end = a;
}
}
// finally, slice up the textarea content into before, selected, & after pieces
before = t.value.slice(0, begin);
selected = t.value.slice(begin, end);
after = t.value.slice(end, t.value.length-1);
if (selected && selected != '') {
if ( selected.match(/^<svg(.|\n)*<\/svg>$/) ) {
SVGeditButton.disabled = false;
SVGeditButton.value = 'Edit existing SVG graphic';
} else {
SVGeditButton.disabled = true;
}
} else {
SVGeditButton.disabled = false;
SVGeditButton.value = 'Create SVG graphic';
}
}
Event.observe(t, 'mouseup', callback );
var my_loc = window.location.protocol + '//' + window.location.host;
Event.observe(window, "message", function(event){
if(event.origin !== my_loc) { return;}
t.value = before + event.data + after;
});
}
function updateSize(elt, w, h) {
// adjust to the size of the user's browser area.
// w and h are the original, unadjusted, width and height per row/column