master
Mark MacKay 2019-11-10 23:26:06 -06:00
parent 26bf1fb7f0
commit de8eb4c695
6 changed files with 757 additions and 883 deletions

View File

@ -1,28 +1,32 @@
function touchHandler(event)
{
(function() {
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
function touchHandler(event) {
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
switch(event.type) {
case "touchstart": type="mousedown"; break;
case "touchmove": type="mousemove"; break;
case "touchend": type="mouseup"; break;
default: return;
}
//initMouseEvent(type, canBubble, cancelable, view, clickCount,
// screenX, screenY, clientX, clientY, ctrlKey,
// altKey, shiftKey, metaKey, button, relatedTarget);
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
simulatedEvent.initMouseEvent(
type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
false, false, false, 0/*left*/, null
);
if(touches.length < 2) {
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
//event.preventDefault();
}
}
})();

File diff suppressed because it is too large Load Diff

View File

@ -13,10 +13,10 @@
.toggleClass('prompt',(type=='prompt'));
btn_holder.empty();
var ok = $('<input type="button" value="' + uiStrings.common.ok + '">').appendTo(btn_holder);
var ok = $('<input type="button" value="OK">').appendTo(btn_holder);
if(type != 'alert') {
$('<input type="button" value="' + uiStrings.common.cancel + '">')
$('<input type="button" value="Cancel">')
.appendTo(btn_holder)
.on("click touchstart", function() { box.hide();callback(false)});
}

View File

@ -7,7 +7,7 @@
* Copyright(c) 2010 Pavol Rusnak
* Copyright(c) 2010 Jeff Schiller
* Copyright(c) 2010 Narendra Sisodiya
* Copyright(c) 2012 Mark MacKay
* Copyright(c) 2012 Mark MacKay
*
*/
@ -17,16 +17,12 @@
// 3) svgcanvas.js
(function() {
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
if(!window.methodDraw) window.methodDraw = function($) {
var svgCanvas;
var Editor = {};
var is_ready = false;
curConfig = {
var curConfig = {
canvas_expansion: 1,
dimensions: [580,400],
initFill: {color: 'fff', opacity: 1},
@ -47,48 +43,7 @@
show_outside_canvas: false,
no_save_warning: true,
initFont: 'Helvetica, Arial, sans-serif'
},
uiStrings = Editor.uiStrings = {
common: {
"ok":"OK",
"cancel":"Cancel",
"key_up":"Up",
"key_down":"Down",
"key_backspace":"Backspace",
"key_del":"Del"
},
// This is needed if the locale is English, since the locale strings are not read in that instance.
layers: {
"layer":"Layer"
},
notification: {
"invalidAttrValGiven":"Invalid value given",
"noContentToFitTo":"No content to fit to",
"dupeLayerName":"There is already a layer named that!",
"enterUniqueLayerName":"Please enter a unique layer name",
"enterNewLayerName":"Please enter the new layer name",
"layerHasThatName":"Layer already has that name",
"QmoveElemsToLayer":"Move selected elements to layer \"%s\"?",
"QwantToClear":"<strong>Do you want to clear the drawing?</strong>\nThis will also erase your undo history",
"QwantToOpen":"Do you want to open a new file?\nThis will also erase your undo history",
"QerrorsRevertToSource":"There were parsing errors in your SVG source.\nRevert back to original SVG source?",
"QignoreSourceChanges":"Ignore changes made to SVG source?",
"featNotSupported":"Feature not supported",
"enterNewImgURL":"Enter the new image URL",
"defsFailOnSave": "NOTE: Due to a bug in your browser, this image may appear wrong (missing gradients or elements). It will however appear correct once actually saved.",
"loadingImage":"Loading image, please wait...",
"saveFromBrowser": "Select \"Save As...\" in your browser to save this image as a %s file.",
"noteTheseIssues": "Also note the following issues: ",
"unsavedChanges": "There are unsaved changes.",
"enterNewLinkURL": "Enter the new hyperlink URL",
"errorLoadingSVG": "Error: Unable to load SVG data",
"URLloadFail": "Unable to load from URL",
"retrieving": 'Retrieving "%s" ...'
}
};
var curPrefs = {}; //$.extend({}, defaultPrefs);
var customHandlers = {};
Editor.curConfig = curConfig;
@ -348,10 +303,10 @@
.toggleClass('prompt',(type=='prompt'));
btn_holder.empty();
var ok = $('<input type="button" value="' + uiStrings.common.ok + '">').appendTo(btn_holder);
var ok = $('<input type="button" value="OK">').appendTo(btn_holder);
if(type != 'alert') {
$('<input type="button" value="' + uiStrings.common.cancel + '">')
$('<input type="button" value="Cancel">')
.appendTo(btn_holder)
.on("click touchstart", function() { box.hide();callback(false)});
}
@ -433,47 +388,7 @@
var cur_context = '';
var saveHandler = function(window,svg) {
Editor.show_save_warning = false;
// by default, we add the XML prolog back, systems integrating SVG-edit (wikis, CMSs)
// can just provide their own custom save handler and might not want the XML prolog
svg = '<?xml version="1.0"?>\n' + svg;
// Opens the SVG in new window, with warning about Mozilla bug #308590 when applicable
var ua = navigator.userAgent;
// Chrome 5 (and 6?) don't allow saving, show source instead ( http://code.google.com/p/chromium/issues/detail?id=46735 )
// IE9 doesn't allow standalone Data URLs ( https://connect.microsoft.com/IE/feedback/details/542600/data-uri-images-fail-when-loaded-by-themselves )
if(~ua.indexOf('MSIE')) {
showSourceEditor(0,true);
return;
}
var win = window.open("data:image/svg+xml;base64," + Utils.encode64(svg));
// Alert will only appear the first time saved OR the first time the bug is encountered
var done = $.pref('save_notice_done');
if(done !== "all") {
var note = uiStrings.notification.saveFromBrowser.replace('%s', 'SVG');
// Check if FF and has <defs/>
if(ua.indexOf('Gecko/') !== -1) {
if(svg.indexOf('<defs') !== -1) {
note += "\n\n" + uiStrings.notification.defsFailOnSave;
$.pref('save_notice_done', 'all');
done = "all";
} else {
$.pref('save_notice_done', 'part');
}
} else {
$.pref('save_notice_done', 'all');
}
if(done !== 'part') {
win.alert(note);
}
}
};
var exportHandler = function(window, data) {
@ -491,12 +406,11 @@
exportWindow.location.href = datauri;
var done = $.pref('export_notice_done');
if(done !== "all") {
var note = uiStrings.notification.saveFromBrowser.replace('%s', 'PNG');
var note ="Select \"Save As...\" in your browser to save this image as a PNG file.";
// Check if there's issues
if(issues.length) {
var pre = "\n \u2022 ";
note += ("\n\n" + uiStrings.notification.noteTheseIssues + pre + issues.join(pre));
note += ("\n\n" + "Also note the following issues: " + pre + issues.join(pre));
}
// Note that this will also prevent the notice even though new issues may appear later.
@ -1592,7 +1506,6 @@
svgCanvas.bind("selected", selectedChanged);
svgCanvas.bind("transition", elementTransition);
svgCanvas.bind("changed", elementChanged);
svgCanvas.bind("saved", saveHandler);
svgCanvas.bind("exported", exportHandler);
svgCanvas.bind("zoomed", zoomChanged);
svgCanvas.bind("contextset", contextChanged);
@ -1705,7 +1618,7 @@
var val = el.value * multiplier;
var valid = svgedit.units.isValidUnit(attr, val, selectedElement);
if(!valid) {
$.alert(uiStrings.notification.invalidAttrValGiven);
$.alert("Invalid value given");
el.value = selectedElement.getAttribute(attr);
return false;
}
@ -2232,7 +2145,7 @@
var makeHyperlink = function() {
if (selectedElement != null || multiselected) {
$.prompt(uiStrings.notification.enterNewLinkURL, "http://", function(url) {
$.prompt("Enter the new hyperlink URL", "http://", function(url) {
if(url) svgCanvas.makeHyperlink(url);
});
}
@ -2303,12 +2216,14 @@
var clickClear = function(){
var dims = curConfig.dimensions;
$.confirm(uiStrings.notification.QwantToClear, function(ok) {
$.confirm("<strong>Do you want to clear the drawing?</strong>\nThis will also erase your undo history", function(ok) {
if(!ok) return;
setSelectMode();
svgCanvas.deleteSelectedElements();
svgCanvas.clear();
svgCanvas.setResolution(dims[0], dims[1]);
updateCanvas(true);
createBackground();
zoomImage();
updateContextPanel();
prepPaints();
@ -2329,8 +2244,7 @@
var clickExport = function() {
// Open placeholder window (prevents popup)
if(!customHandlers.pngsave) {
var str = uiStrings.notification.loadingImage;
exportWindow = window.open("data:text/html;charset=utf-8,<title>" + str + "<\/title><h1>" + str + "<\/h1>");
exportWindow = window.open("data:text/html;charset=utf-8,<title>Loading image, please wait...<\/title><h1>" + str + "<\/h1>");
}
if(window.canvg) {
@ -2529,7 +2443,7 @@
}
if (!svgCanvas.setSvgString($('#svg_source_textarea').val())) {
$.confirm(uiStrings.notification.QerrorsRevertToSource, function(ok) {
$.confirm("There were parsing errors in your SVG source.\nRevert back to original SVG source?", function(ok) {
if(!ok) return false;
saveChanges();
});
@ -2689,7 +2603,7 @@
if (editingsource) {
if (orig_source !== $('#svg_source_textarea').val()) {
$.confirm(uiStrings.notification.QignoreSourceChanges, function(ok) {
$.confirm("Ignore changes made to SVG source?", function(ok) {
if(ok) hideSourceEditor();
});
} else {
@ -2774,7 +2688,7 @@
function promptImgURL() {
var curhref = svgCanvas.getHref(selectedElement);
curhref = curhref.indexOf("data:") === 0?"":curhref;
$.prompt(uiStrings.notification.enterNewImgURL, curhref, function(url) {
$.prompt("Enter the new image URL", curhref, function(url) {
if(url) setImageURL(url);
});
}
@ -2985,7 +2899,7 @@
$('#image_save_opts [value=embed]').attr('disabled','disabled');
$('#image_save_opts input').val(['ref']);
curPrefs.img_save = 'ref';
$('#image_opt_embed').css('color','#666').attr('title',uiStrings.notification.featNotSupported);
$('#image_opt_embed').css('color','#666').attr('title', "Feature not supported");
}
});
},1000);
@ -3102,7 +3016,7 @@
var h = height.val()
if(w != "fit" && !svgedit.units.isValidUnit('width', w)) {
$.alert(uiStrings.notification.invalidAttrValGiven);
$.alert("Invalid value given");
width.parent().addClass('error');
return false;
}
@ -3110,13 +3024,13 @@
width.parent().removeClass('error');
if(h != "fit" && !svgedit.units.isValidUnit('height', h)) {
$.alert(uiStrings.notification.invalidAttrValGiven);
$.alert("Invalid value given");
height.parent().addClass('error');
return false;
}
height.parent().removeClass('error');
if(!svgCanvas.setResolution(w, h)) {
$.alert(uiStrings.notification.noContentToFitTo);
$.alert("No content to fit to");
var dims = svgCanvas.getResolution()
width.val(dims.w)
height.val(dims.h)
@ -3385,7 +3299,7 @@
mod = mod_bits[0] + '+';
key = mod_bits[1];
}
key_str += (i?'/':'') + mod + (uiStrings['key_'+key] || key);
key_str += (i?'/':'') + mod + (key);
});
if(menu) {
this.lastChild.textContent = t +' ['+key_str+']';
@ -3540,7 +3454,7 @@
// show_save_warning is set to "false" when the page is saved.
if(!curConfig.no_save_warning && Editor.show_save_warning) {
// Browser already asks question about closing the page
return uiStrings.notification.unsavedChanges;
return "There are unsaved changes.";
}
};
@ -3549,7 +3463,7 @@
if(undoMgr.getUndoStackSize() === 0) {
func(true);
} else {
$.confirm(uiStrings.notification.QwantToOpen, func);
$.confirm("Do you want to open a new file?\nThis will also erase your undo history", func);
}
}
@ -4017,7 +3931,7 @@
if(success) {
callback(true);
} else {
$.alert(uiStrings.notification.errorLoadingSVG, function() {
$.alert("Error: Unable to load SVG data", function() {
callback(false);
});
}
@ -4062,7 +3976,7 @@
if(xhr.status != 404 && xhr.responseText) {
loadSvgString(xhr.responseText, cb);
} else {
$.alert(uiStrings.notification.URLloadFail + ": \n"+err+'', cb);
$.alert("Unable to load from URL" + ": \n"+err+'', cb);
}
}
});

View File

@ -23,11 +23,6 @@ if (!svgedit.path) {
var svgns = "http://www.w3.org/2000/svg";
var uiStrings = {
"pathNodeTooltip": "Drag node to move it. Double-click node to change segment type",
"pathCtrlPtTooltip": "Drag control point to adjust curve properties"
};
var segData = {
2: ['x','y'],
4: ['x','y'],
@ -137,7 +132,7 @@ svgedit.path.addPointGrip = function(index, x, y) {
'stroke-width': 1,
'cursor': 'move',
'style': 'pointer-events:all',
'xlink:title': uiStrings.pathNodeTooltip
'xlink:title': "Drag node to move it. Double-click node to change segment type"
});
pointGrip = pointGripContainer.appendChild(pointGrip);
@ -182,7 +177,7 @@ svgedit.path.addCtrlGrip = function(id) {
'stroke-width': '3',
'cursor': 'move',
'style': 'pointer-events:all',
'xlink:title': uiStrings.pathCtrlPtTooltip
'xlink:title': "Drag control point to adjust curve properties"
});
svgedit.path.getGripContainer().appendChild(pointGrip);
return pointGrip;

View File

@ -135,20 +135,11 @@ var canvas = this;
var svgdoc = container.ownerDocument;
// This is a container for the document being edited, not the document itself.
var svgroot = svgdoc.importNode(svgedit.utilities.text2xml(
'<svg id="svgroot" xmlns="' + svgns + '" xlinkns="' + xlinkns + '" ' +
'width="' + dimensions[0] + '" height="' + dimensions[1] + '" x="' + dimensions[0] + '" y="' + dimensions[1] + '" overflow="visible">' +
'<defs>' +
'<filter id="canvashadow" filterUnits="objectBoundingBox">' +
'<feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>'+
'<feOffset in="blur" dx="5" dy="5" result="offsetBlur"/>'+
'<feMerge>'+
'<feMergeNode in="offsetBlur"/>'+
'<feMergeNode in="SourceGraphic"/>'+
'</feMerge>'+
'</filter>'+
'</defs>'+
'</svg>').documentElement, true);
var svgroot = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgroot.setAttribute("width", dimensions[0]);
svgroot.setAttribute("height", dimensions[1]);
svgroot.id = "svgroot";
svgroot.setAttribute("xlinkns", xlinkns);
container.appendChild(svgroot);
// The actual element that represents the final output SVG element
@ -425,15 +416,6 @@ svgedit.utilities.snapToGrid = function(value){
return value;
};
var snapToGrid = svgedit.utilities.snapToGrid;
// Interface strings, usually for title elements
var uiStrings = {
"exportNoBlur": "Blurred elements will appear as un-blurred",
"exportNoforeignObject": "foreignObject elements will not appear",
"exportNoDashArray": "Strokes will appear filled",
"exportNoText": "Text may not appear as expected"
};
var visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use';
var ref_attrs = ["clip-path", "fill", "filter", "marker-end", "marker-mid", "marker-start", "mask", "stroke"];
@ -5578,14 +5560,9 @@ this.save = function(opts) {
// no need for doctype, see http://jwatt.org/svg/authoring/#doctype-declaration
var str = this.svgCanvasToString();
if (svgedit.browser.supportsBlobs()) {
var blob = new Blob([ str ], {type: "image/svg+xml;charset=utf-8"});
var dropAutoBOM = true;
saveAs(blob, "method-draw-image.svg", dropAutoBOM);
}
else {
call("saved", str);
}
};
// Function: rasterExport
@ -5600,15 +5577,15 @@ this.rasterExport = function() {
// Selector and notice
var issue_list = {
'feGaussianBlur': uiStrings.exportNoBlur,
'foreignObject': uiStrings.exportNoforeignObject,
'[stroke-dasharray]': uiStrings.exportNoDashArray
'feGaussianBlur': "Blurred elements will appear as un-blurred",
'foreignObject': "foreignObject elements will not appear",
'[stroke-dasharray]': "Strokes will appear filled"
};
var content = $(svgcontent);
// Add font/text check if Canvas Text API is not implemented
if(!("font" in $('<canvas>')[0].getContext('2d'))) {
issue_list['text'] = uiStrings.exportNoText;
issue_list['text'] = "Text may not appear as expected";
}
$.each(issue_list, function(sel, descr) {
@ -6750,15 +6727,6 @@ this.getVersion = function() {
return "svgcanvas.js ($Rev: 2082 $)";
};
// Function: setUiStrings
// Update interface strings with given values
//
// Parameters:
// strs - Object with strings (see uiStrings for examples)
this.setUiStrings = function(strs) {
$.extend(uiStrings, strs.notification);
}
// Function: setConfig
// Update configuration options with given values
//
@ -8759,7 +8727,7 @@ this.cloneSelectedElements = function(x,y, drag) {
if (drag) {
//removed the dragged transform until that moment
tlist = getTransformList(clone)
tlist.removeItem(drag)
tlist.removeItem(0)
recalculateDimensions(clone)
parent.insertBefore(clone, elem);
}