JSLint extensions

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2695 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-02-12 09:38:38 +00:00
parent d97e21b604
commit d6cc464ba5
17 changed files with 767 additions and 664 deletions

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgCanvas, $*/
/*jslint vars: true, eqeq: true*/
/*
* ext-arrows.js
*
@ -12,7 +14,7 @@ svgEditor.addExtension('Arrows', function(S) {
addElem = S.addSvgElementFromJson,
nonce = S.nonce,
randomize_ids = S.randomize_ids,
selElems,
selElems, pathdata,
lang_list = {
'en':[
{'id': 'arrow_none', 'textContent': 'No arrow' }
@ -21,22 +23,9 @@ svgEditor.addExtension('Arrows', function(S) {
{'id': 'arrow_none', 'textContent': 'Sans flèche' }
]
},
arrowprefix,
prefix = 'se_arrow_';
svgCanvas.bind('setnonce', setArrowNonce);
svgCanvas.bind('unsetnonce', unsetArrowNonce);
if (randomize_ids) {
var arrowprefix = prefix + nonce + '_';
} else {
var arrowprefix = prefix;
}
var pathdata = {
fw: {d: 'm0,0l10,5l-10,5l5,-5l-5,-5z', refx: 8, id: arrowprefix + 'fw'},
bk: {d: 'm10,0l-10,5l10,5l-5,-5l5,-5z', refx: 2, id: arrowprefix + 'bk'}
};
function setArrowNonce(window, n) {
randomize_ids = true;
arrowprefix = prefix + n + '_';
@ -51,9 +40,24 @@ svgEditor.addExtension('Arrows', function(S) {
pathdata.bk.id = arrowprefix + 'bk';
}
svgCanvas.bind('setnonce', setArrowNonce);
svgCanvas.bind('unsetnonce', unsetArrowNonce);
if (randomize_ids) {
arrowprefix = prefix + nonce + '_';
} else {
arrowprefix = prefix;
}
pathdata = {
fw: {d: 'm0,0l10,5l-10,5l5,-5l-5,-5z', refx: 8, id: arrowprefix + 'fw'},
bk: {d: 'm10,0l-10,5l10,5l-5,-5l5,-5z', refx: 2, id: arrowprefix + 'bk'}
};
function getLinked(elem, attr) {
var str = elem.getAttribute(attr);
if(!str) return null;
if(!str) {return null;}
var m = str.match(/\(\#(.*)\)/);
if(!m || m.length !== 2) {
return null;
@ -78,7 +82,7 @@ svgEditor.addExtension('Arrows', function(S) {
val = 'start';
} else if (mid) {
val = 'mid';
if(mid.indexOf('bk') != -1) {
if (mid.indexOf('bk') !== -1) {
val = 'mid_bk';
}
}
@ -173,12 +177,12 @@ svgEditor.addExtension('Arrows', function(S) {
$.each(mtypes, function(i, type) {
var marker = getLinked(elem, 'marker-'+type);
if(!marker) return;
if(!marker) {return;}
var cur_color = $(marker).children().attr('fill');
var cur_d = $(marker).children().attr('d');
var new_marker = null;
if(cur_color === color) return;
if(cur_color === color) {return;}
var all_markers = $(defs).find('marker');
// Different color, check if already made
@ -208,10 +212,11 @@ svgEditor.addExtension('Arrows', function(S) {
var elem = this;
$.each(mtypes, function(j, mtype) {
if($(elem).attr('marker-' + mtype) === 'url(#' + marker.id + ')') {
return remove = false;
remove = false;
return remove;
}
});
if(!remove) return false;
if(!remove) {return false;}
});
// Not found, so can safely remove
@ -259,7 +264,7 @@ svgEditor.addExtension('Arrows', function(S) {
var marker_elems = ['line', 'path', 'polyline', 'polygon'];
while(i--) {
var elem = selElems[i];
if(elem && $.inArray(elem.tagName, marker_elems) != -1) {
if(elem && $.inArray(elem.tagName, marker_elems) !== -1) {
if(opts.selectedElement && !opts.multiselected) {
showPanel(true);
} else {

View File

@ -1,3 +1,5 @@
/*globals svgEditor, $*/
/*jslint vars: true, eqeq: true*/
/*
* ext-closepath.js
*
@ -9,7 +11,7 @@
// This extension adds a simple button to the contextual panel for paths
// The button toggles whether the path is open or closed
svgEditor.addExtension('ClosePath', function() {
svgEditor.addExtension('ClosePath', function() {'use strict';
var selElems,
updateButton = function(path) {
var seglist = path.pathSegList,
@ -23,7 +25,7 @@ svgEditor.addExtension('ClosePath', function() {
$('#closepath_panel').toggle(on);
if (on) {
var path = selElems[0];
if (path) updateButton(path);
if (path) {updateButton(path);}
}
},
toggleClosed = function() {

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgCanvas, $*/
/*jslint vars: true, continue: true, eqeq: true, todo: true*/
/*
* ext-connector.js
*
@ -25,8 +27,7 @@ svgEditor.addExtension("Connector", function(S) {
conn_sel = ".se_connector",
se_ns,
// connect_str = "-SE_CONNECT-",
selElems = [];
selElems = [],
elData = $.data;
var lang_list = {
@ -38,6 +39,38 @@ svgEditor.addExtension("Connector", function(S) {
]
};
function getBBintersect(x, y, bb, offset) {
if(offset) {
offset -= 0;
bb = $.extend({}, bb);
bb.width += offset;
bb.height += offset;
bb.x -= offset/2;
bb.y -= offset/2;
}
var mid_x = bb.x + bb.width/2;
var mid_y = bb.y + bb.height/2;
var len_x = x - mid_x;
var len_y = y - mid_y;
var slope = Math.abs(len_y/len_x);
var ratio;
if(slope < bb.height/bb.width) {
ratio = (bb.width/2) / Math.abs(len_x);
} else {
ratio = (bb.height/2) / Math.abs(len_y);
}
return {
x: mid_x + len_x * ratio,
y: mid_y + len_y * ratio
};
}
function getOffset(side, line) {
var give_offset = !!line.getAttribute('marker-' + side);
// var give_offset = $(line).data(side+'_off');
@ -57,19 +90,19 @@ svgEditor.addExtension("Connector", function(S) {
}
function setPoint(elem, pos, x, y, setMid) {
var pts = elem.points;
var i, pts = elem.points;
var pt = svgroot.createSVGPoint();
pt.x = x;
pt.y = y;
if(pos === 'end') pos = pts.numberOfItems-1;
if (pos === 'end') {pos = pts.numberOfItems - 1;}
// TODO: Test for this on init, then use alt only if needed
try {
pts.replaceItem(pt, pos);
} catch(err) {
// Should only occur in FF which formats points attr as "n,n n,n", so just split
var pt_arr = elem.getAttribute("points").split(" ");
for(var i=0; i< pt_arr.length; i++) {
if(i == pos) {
for (i = 0; i < pt_arr.length; i++) {
if (i === pos) {
pt_arr[i] = x + ',' + y;
}
}
@ -120,26 +153,29 @@ svgEditor.addExtension("Connector", function(S) {
}
function findConnectors(elems) {
if(!elems) elems = selElems;
var i;
if (!elems) {elems = selElems;}
var connectors = $(svgcontent).find(conn_sel);
connections = [];
// Loop through connectors to see if one is connected to the element
connectors.each(function() {
var start = elData(this, "c_start");
var end = elData(this, "c_end");
var parts = [getElem(start), getElem(end)];
for(var i=0; i<2; i++) {
var c_elem = parts[i];
var add_this = false;
// The connected element might be part of a selected group
$(c_elem).parents().each(function() {
var add_this;
function add () {
if ($.inArray(this, elems) !== -1) {
// Pretend this element is selected
add_this = true;
}
});
}
var start = elData(this, "c_start");
var end = elData(this, "c_end");
var parts = [getElem(start), getElem(end)];
for (i = 0; i < 2; i++) {
var c_elem = parts[i];
add_this = false;
// The connected element might be part of a selected group
$(c_elem).parents().each(add);
if(!c_elem || !c_elem.parentNode) {
$(this).remove();
@ -163,10 +199,11 @@ svgEditor.addExtension("Connector", function(S) {
// Updates connector lines based on selected elements
// Is not used on mousemove, as it runs getStrokedBBox every time,
// which isn't necessary there.
var i, j;
findConnectors(elems);
if (connections.length) {
// Update line with element
var i = connections.length;
i = connections.length;
while (i--) {
var conn = connections[i];
var line = conn.connector;
@ -198,51 +235,18 @@ svgEditor.addExtension("Connector", function(S) {
setPoint(line, conn.is_start ? 'end' : 0, pt2.x, pt2.y, true);
// Update points attribute manually for webkit
if(navigator.userAgent.indexOf('AppleWebKit') != -1) {
if (navigator.userAgent.indexOf('AppleWebKit') !== -1) {
var pts = line.points;
var len = pts.numberOfItems;
var pt_arr = Array(len);
for(var j=0; j< len; j++) {
var pt = pts.getItem(j);
var pt_arr = [];
for (j = 0; j < len; j++) {
pt = pts.getItem(j);
pt_arr[j] = pt.x + ',' + pt.y;
}
line.setAttribute("points",pt_arr.join(" "));
}
line.setAttribute('points', pt_arr.join(' '));
}
}
}
function getBBintersect(x, y, bb, offset) {
if(offset) {
offset -= 0;
bb = $.extend({}, bb);
bb.width += offset;
bb.height += offset;
bb.x -= offset/2;
bb.y -= offset/2;
}
var mid_x = bb.x + bb.width/2;
var mid_y = bb.y + bb.height/2;
var len_x = x - mid_x;
var len_y = y - mid_y;
var slope = Math.abs(len_y/len_x);
var ratio;
if(slope < bb.height/bb.width) {
ratio = (bb.width/2) / Math.abs(len_x);
} else {
ratio = (bb.height/2) / Math.abs(len_y);
}
return {
x: mid_x + len_x * ratio,
y: mid_y + len_y * ratio
}
}
// Do once
@ -252,7 +256,7 @@ svgEditor.addExtension("Connector", function(S) {
svgCanvas.groupSelectedElements = function() {
svgCanvas.removeFromSelection($(conn_sel).toArray());
return gse.apply(this, arguments);
}
};
var mse = svgCanvas.moveSelectedElements;
@ -261,7 +265,7 @@ svgEditor.addExtension("Connector", function(S) {
var cmd = mse.apply(this, arguments);
updateConnectors();
return cmd;
}
};
se_ns = svgCanvas.getEditorNS();
}());
@ -323,19 +327,19 @@ svgEditor.addExtension("Connector", function(S) {
},
mouseDown: function(opts) {
var e = opts.event;
start_x = opts.start_x,
start_x = opts.start_x;
start_y = opts.start_y;
var mode = svgCanvas.getMode();
if (mode == "connector") {
if(started) return;
if (started) {return;}
var mouse_target = e.target;
var parents = $(mouse_target).parents();
if($.inArray(svgcontent, parents) != -1) {
if($.inArray(svgcontent, parents) !== -1) {
// Connectable element
// If child of foreignObject, use parent
@ -365,7 +369,8 @@ svgEditor.addExtension("Connector", function(S) {
return {
started: true
};
} else if(mode == "select") {
}
if (mode == "select") {
findConnectors();
}
},
@ -421,7 +426,7 @@ svgEditor.addExtension("Connector", function(S) {
if(svgCanvas.getMode() == "connector") {
var fo = $(mouse_target).closest("foreignObject");
if(fo.length) mouse_target = fo[0];
if (fo.length) {mouse_target = fo[0];}
var parents = $(mouse_target).parents();
@ -432,8 +437,9 @@ svgEditor.addExtension("Connector", function(S) {
keep: true,
element: null,
started: started
};
}
} else if($.inArray(svgcontent, parents) === -1) {
if ($.inArray(svgcontent, parents) === -1) {
// Not a valid target element, so remove line
$(cur_line).remove();
started = false;
@ -441,8 +447,8 @@ svgEditor.addExtension("Connector", function(S) {
keep: false,
element: null,
started: started
};
}
} else {
// Valid end element
end_elem = mouse_target;
@ -452,7 +458,7 @@ svgEditor.addExtension("Connector", function(S) {
// Don't create connector if one already exists
var dupe = $(svgcontent).find(conn_sel).filter(function() {
var conn = this.getAttributeNS(se_ns, "connector");
if(conn == conn_str || conn == alt_str) return true;
if (conn == conn_str || conn == alt_str) {return true;}
});
if(dupe.length) {
$(cur_line).remove();
@ -460,7 +466,7 @@ svgEditor.addExtension("Connector", function(S) {
keep: false,
element: null,
started: false
}
};
}
var bb = svgCanvas.getStrokedBBox([end_elem]);
@ -483,13 +489,12 @@ svgEditor.addExtension("Connector", function(S) {
keep: true,
element: cur_line,
started: started
}
}
};
}
},
selectedChanged: function(opts) {
// TODO: Find better way to skip operations if no connectors are in use
if(!$(svgcontent).find(conn_sel).length) return;
if(!$(svgcontent).find(conn_sel).length) {return;}
if(svgCanvas.getMode() == 'connector') {
svgCanvas.setMode('select');
@ -518,19 +523,20 @@ svgEditor.addExtension("Connector", function(S) {
},
elementChanged: function(opts) {
var elem = opts.elems[0];
if (elem && elem.tagName == 'svg' && elem.id == "svgcontent") {
if (elem && elem.tagName === 'svg' && elem.id === 'svgcontent') {
// Update svgcontent (can change on import)
svgcontent = elem;
init();
}
// Has marker, so change offset
var start;
if (elem && (
elem.getAttribute("marker-start") ||
elem.getAttribute("marker-mid") ||
elem.getAttribute("marker-end")
)) {
var start = elem.getAttribute("marker-start");
start = elem.getAttribute("marker-start");
var mid = elem.getAttribute("marker-mid");
var end = elem.getAttribute("marker-end");
cur_line = elem;
@ -538,13 +544,13 @@ svgEditor.addExtension("Connector", function(S) {
.data("start_off", !!start)
.data("end_off", !!end);
if(elem.tagName == "line" && mid) {
if (elem.tagName === 'line' && mid) {
// Convert to polyline to accept mid-arrow
var x1 = elem.getAttribute('x1')-0;
var x2 = elem.getAttribute('x2')-0;
var y1 = elem.getAttribute('y1')-0;
var y2 = elem.getAttribute('y2')-0;
var x1 = Number(elem.getAttribute('x1'));
var x2 = Number(elem.getAttribute('x2'));
var y1 = Number(elem.getAttribute('y1'));
var y2 = Number(elem.getAttribute('y2'));
var id = elem.id;
var mid_pt = (' '+((x1+x2)/2)+','+((y1+y2)/2) + ' ');
@ -568,7 +574,7 @@ svgEditor.addExtension("Connector", function(S) {
}
// Update line if it's a connector
if (elem.getAttribute('class') == conn_sel.substr(1)) {
var start = getElem(elData(elem, 'c_start'));
start = getElem(elData(elem, 'c_start'));
updateConnectors([start]);
} else {
updateConnectors();
@ -577,7 +583,7 @@ svgEditor.addExtension("Connector", function(S) {
toolButtonStateUpdate: function(opts) {
if (opts.nostroke) {
if ($('#mode_connect').hasClass('tool_button_current')) {
clickSelect();
svgEditor.clickSelect();
}
}
$('#mode_connect')

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgedit, $*/
/*jslint vars: true, eqeq: true*/
/*
* ext-eyedropper.js
*
@ -13,32 +15,33 @@
// 3) svg_editor.js
// 4) svgcanvas.js
svgEditor.addExtension("eyedropper", function(S) {
var NS = svgedit.NS,
svgcontent = S.svgcontent,
svgdoc = S.svgroot.parentNode.ownerDocument,
svgEditor.addExtension("eyedropper", function(S) {'use strict';
var // NS = svgedit.NS,
// svgcontent = S.svgcontent,
// svgdoc = S.svgroot.parentNode.ownerDocument,
svgCanvas = svgEditor.canvas,
ChangeElementCommand = svgedit.history.ChangeElementCommand,
addToHistory = function(cmd) { svgCanvas.undoMgr.addCommandToHistory(cmd); },
currentStyle = {fillPaint: "red", fillOpacity: 1.0,
currentStyle = {
fillPaint: "red", fillOpacity: 1.0,
strokePaint: "black", strokeOpacity: 1.0,
strokeWidth: 5, strokeDashArray: null,
opacity: 1.0,
strokeLinecap: 'butt',
strokeLinejoin: 'miter',
strokeLinejoin: 'miter'
};
function getStyle(opts) {
// if we are in eyedropper mode, we don't want to disable the eye-dropper tool
var mode = svgCanvas.getMode();
if (mode == "eyedropper") return;
if (mode == "eyedropper") {return;}
var elem = null;
var tool = $('#tool_eyedropper');
// enable-eye-dropper if one element is selected
if (!opts.multiselected && opts.elems[0] &&
$.inArray(opts.elems[0].nodeName, ['svg', 'g', 'use']) == -1)
{
$.inArray(opts.elems[0].nodeName, ['svg', 'g', 'use']) === -1
) {
elem = opts.elems[0];
tool.removeClass('disabled');
// grab the current style
@ -83,7 +86,7 @@ svgEditor.addExtension("eyedropper", function(S) {
if (mode == "eyedropper") {
var e = opts.event;
var target = e.target;
if ($.inArray(target.nodeName, ['svg', 'g', 'use']) == -1) {
if ($.inArray(target.nodeName, ['svg', 'g', 'use']) === -1) {
var changes = {};
var change = function(elem, attrname, newvalue) {
@ -91,19 +94,19 @@ svgEditor.addExtension("eyedropper", function(S) {
elem.setAttribute(attrname, newvalue);
};
if (currentStyle.fillPaint) change(target, "fill", currentStyle.fillPaint);
if (currentStyle.fillOpacity) change(target, "fill-opacity", currentStyle.fillOpacity);
if (currentStyle.strokePaint) change(target, "stroke", currentStyle.strokePaint);
if (currentStyle.strokeOpacity) change(target, "stroke-opacity", currentStyle.strokeOpacity);
if (currentStyle.strokeWidth) change(target, "stroke-width", currentStyle.strokeWidth);
if (currentStyle.strokeDashArray) change(target, "stroke-dasharray", currentStyle.strokeDashArray);
if (currentStyle.opacity) change(target, "opacity", currentStyle.opacity);
if (currentStyle.strokeLinecap) change(target, "stroke-linecap", currentStyle.strokeLinecap);
if (currentStyle.strokeLinejoin) change(target, "stroke-linejoin", currentStyle.strokeLinejoin);
if (currentStyle.fillPaint) {change(target, "fill", currentStyle.fillPaint);}
if (currentStyle.fillOpacity) {change(target, "fill-opacity", currentStyle.fillOpacity);}
if (currentStyle.strokePaint) {change(target, "stroke", currentStyle.strokePaint);}
if (currentStyle.strokeOpacity) {change(target, "stroke-opacity", currentStyle.strokeOpacity);}
if (currentStyle.strokeWidth) {change(target, "stroke-width", currentStyle.strokeWidth);}
if (currentStyle.strokeDashArray) {change(target, "stroke-dasharray", currentStyle.strokeDashArray);}
if (currentStyle.opacity) {change(target, "opacity", currentStyle.opacity);}
if (currentStyle.strokeLinecap) {change(target, "stroke-linecap", currentStyle.strokeLinecap);}
if (currentStyle.strokeLinejoin) {change(target, "stroke-linejoin", currentStyle.strokeLinejoin);}
addToHistory(new ChangeElementCommand(target, changes));
}
}
},
}
};
});

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgedit, svgCanvas, $*/
/*jslint vars: true, eqeq: true, todo: true*/
/*
* ext-foreignobject.js
*
@ -10,6 +12,7 @@
svgEditor.addExtension("foreignObject", function(S) {
var NS = svgedit.NS,
Utils = svgedit.utilities,
svgcontent = S.svgcontent,
addElem = S.addSvgElementFromJson,
selElems,
@ -67,7 +70,7 @@ svgEditor.addExtension("foreignObject", function(S) {
function showForeignEditor() {
var elt = selElems[0];
if (!elt || editingforeign) return;
if (!elt || editingforeign) {return;}
editingforeign = true;
toggleSourceButtons(true);
elt.removeAttribute('fill');
@ -93,7 +96,7 @@ svgEditor.addExtension("foreignObject", function(S) {
title: "Foreign Object Tool",
events: {
'click': function() {
svgCanvas.setMode('foreign')
svgCanvas.setMode('foreign');
}
}
},{
@ -155,7 +158,7 @@ svgEditor.addExtension("foreignObject", function(S) {
editingforeign = false;
$('#svg_source_textarea').blur();
toggleSourceButtons(false);
}
};
// TODO: Needs to be done after orig icon loads
setTimeout(function() {
@ -164,11 +167,11 @@ svgEditor.addExtension("foreignObject", function(S) {
.hide().attr('id', 'foreign_save').unbind()
.appendTo("#tool_source_back").click(function() {
if (!editingforeign) return;
if (!editingforeign) {return;}
if (!setForeignString($('#svg_source_textarea').val())) {
$.confirm("Errors found. Revert to original?", function(ok) {
if(!ok) return false;
if(!ok) {return false;}
endChanges();
});
} else {
@ -218,20 +221,20 @@ svgEditor.addExtension("foreignObject", function(S) {
newFO.appendChild(m);
return {
started: true
}
};
}
},
mouseUp: function(opts) {
var e = opts.event;
if(svgCanvas.getMode() == "foreign" && started) {
var attrs = $(newFO).attr(["width", "height"]);
keep = (attrs.width != 0 || attrs.height != 0);
var keep = (attrs.width != 0 || attrs.height != 0);
svgCanvas.addToSelection([newFO], true);
return {
keep: keep,
element: newFO
}
};
}
@ -244,7 +247,7 @@ svgEditor.addExtension("foreignObject", function(S) {
while(i--) {
var elem = selElems[i];
if(elem && elem.tagName == "foreignObject") {
if(elem && elem.tagName === 'foreignObject') {
if(opts.selectedElement && !opts.multiselected) {
$('#foreign_font_size').val(elem.getAttribute("font-size"));
$('#foreign_width').val(elem.getAttribute("width"));

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgedit, svgCanvas, $*/
/*jslint vars: true*/
/*
* ext-grid.js
*
@ -12,7 +14,7 @@
// 1) units.js
// 2) everything else
svgEditor.addExtension('view_grid', function() {
svgEditor.addExtension('view_grid', function() { 'use strict';
var NS = svgedit.NS,
svgdoc = document.getElementById('svgcanvas').ownerDocument,
@ -73,13 +75,14 @@ svgEditor.addExtension('view_grid', function() {
$('#canvasGrid').append(gridBox);
function updateGrid(zoom) {
var i;
// TODO: Try this with <line> elements, then compare performance difference
var unit = units[svgEditor.curConfig.baseUnit]; // 1 = 1px
var u_multi = unit * zoom;
// Calculate the main number interval
var raw_m = 100 / u_multi;
var multi = 1;
for(var i = 0; i < intervals.length; i++) {
for (i = 0; i < intervals.length; i++) {
var num = intervals[i];
multi = num;
if (raw_m <= num) {
@ -97,7 +100,7 @@ svgEditor.addExtension('view_grid', function() {
ctx.globalAlpha = 0.2;
ctx.strokeStyle = svgEditor.curConfig.gridColor;
for (var i = 1; i < 10; i++) {
for (i = 1; i < 10; i++) {
var sub_d = Math.round(part * i) + 0.5;
// var line_num = (i % 2)?12:10;
var line_num = 0;
@ -129,7 +132,7 @@ svgEditor.addExtension('view_grid', function() {
svgicons: svgEditor.curConfig.extPath + 'grid-icon.xml',
zoomChanged: function(zoom) {
if(showGrid) updateGrid(zoom);
if (showGrid) {updateGrid(zoom);}
},
buttons: [{

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgCanvas, $*/
/*jslint vars: true, eqeq: true*/
/*
* ext-helloworld.js
*
@ -13,7 +15,7 @@
user the point on the canvas that was clicked on.
*/
svgEditor.addExtension("Hello World", function() {
svgEditor.addExtension("Hello World", function() {'use strict';
return {
name: "Hello World",

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgCanvas, $*/
/*jslint vars: true, eqeq: true, todo: true */
/*
* ext-markers.js
*
@ -31,7 +33,7 @@
*/
svgEditor.addExtension("Markers", function(S) {
var svgcontent = S.svgcontent,
var // svgcontent = S.svgcontent,
addElem = S.addSvgElementFromJson,
selElems;
@ -69,8 +71,8 @@ svgEditor.addExtension("Markers", function(S) {
triangle:
{element:'path', attr:{d:'M10,80 L50,20 L80,80 Z'}},
mcircle:
{element:'circle', attr:{r:30, cx:50, cy:50}},
}
{element:'circle', attr:{r:30, cx:50, cy:50}}
};
var lang_list = {
@ -95,7 +97,7 @@ svgEditor.addExtension("Markers", function(S) {
{id: "box_o", title: "Open Box" },
{id: "star_o", title: "Open Star" },
{id: "triangle_o", title: "Open Triangle" },
{id: "mcircle_o", title: "Open Circle" },
{id: "mcircle_o", title: "Open Circle" }
]
};
@ -110,7 +112,7 @@ svgEditor.addExtension("Markers", function(S) {
// returns the marker element that is linked to the graphic element
function getLinked(elem, attr) {
var str = elem.getAttribute(attr);
if(!str) return null;
if(!str) {return null;}
var m = str.match(/\(\#(.*)\)/);
if(!m || m.length !== 2) {
return null;
@ -118,6 +120,13 @@ svgEditor.addExtension("Markers", function(S) {
return S.getElem(m[1]);
}
function setIcon(pos,id) {
if (id.substr(0,1) !== '\\') {id = '\\textmarker';}
var ci = '#'+id_prefix+pos+'_'+id.substr(1);
svgEditor.setIcon('#cur_' + pos +'_marker_list', $(ci).children());
$(ci).addClass('current').siblings().removeClass('current');
}
// toggles context tool panel off/on
//sets the controls with the selected element's settings
function showPanel(on) {
@ -134,21 +143,21 @@ svgEditor.addExtension("Markers", function(S) {
if (!m) {
val = '\\nomarker';
ci = val;
txtbox.hide() // hide text box
txtbox.hide(); // hide text box
} else {
if (!m.attributes.se_type) return; // not created by this extension
if (!m.attributes.se_type) {return;} // not created by this extension
val = '\\' + m.attributes.se_type.textContent;
ci = val;
if (val=='\\textmarker') {
if (val === '\\textmarker') {
val=m.lastChild.textContent;
//txtbox.show(); // show text box
} else {
txtbox.hide() // hide text box
txtbox.hide(); // hide text box
}
}
txtbox.val(val);
setIcon(pos,ci);
})
});
}
}
@ -159,9 +168,9 @@ svgEditor.addExtension("Markers", function(S) {
var marker = S.getElem(id);
if (marker) return;
if (marker) {return;}
if (val=='' || val=='\\nomarker') return;
if (val == '' || val == '\\nomarker') {return;}
var el = selElems[0];
var color = el.getAttribute('stroke');
@ -174,10 +183,11 @@ svgEditor.addExtension("Markers", function(S) {
var markerWidth = 5;
var markerHeight = 5;
var strokeWidth = 10;
if (val.substr(0,1)=='\\') se_type=val.substr(1);
else se_type='textmarker';
var se_type;
if (val.substr(0,1) === '\\') {se_type = val.substr(1);}
else {se_type = 'textmarker';}
if (!marker_types[se_type]) return; // an unknown type!
if (!marker_types[se_type]) {return;} // an unknown type!
// create a generic marker
marker = addElem({
@ -194,7 +204,7 @@ svgEditor.addExtension("Markers", function(S) {
if (se_type != 'textmarker') {
var mel = addElem(marker_types[se_type]);
var fillcolor = color;
if (se_type.substr(-2)=='_o') fillcolor='none';
if (se_type.substr(-2) === '_o') {fillcolor = 'none';}
mel.setAttribute('fill', fillcolor);
mel.setAttribute('stroke', color);
mel.setAttribute('stroke-width', strokeWidth);
@ -248,42 +258,17 @@ svgEditor.addExtension("Markers", function(S) {
return marker;
}
function setMarker() {
var poslist={'start_marker':'start','mid_marker':'mid','end_marker':'end'};
var pos = poslist[this.id];
var marker_name = 'marker-'+pos;
var val = this.value;
var el = selElems[0];
var marker = getLinked(el, marker_name);
if (marker) $(marker).remove();
el.removeAttribute(marker_name);
if (val=='') val='\\nomarker';
if (val=='\\nomarker') {
setIcon(pos,val);
S.call("changed", selElems);
return;
}
// Set marker on element
var id = marker_prefix + pos + '_' + el.id;
addMarker(id, val);
svgCanvas.changeSelectedAttribute(marker_name, "url(#" + id + ")");
if (el.tagName == "line" && pos=='mid') el=convertline(el);
S.call("changed", selElems);
setIcon(pos,val);
}
function convertline(elem) {
// this routine came from the connectors extension
// it is needed because midpoint markers don't work with line elements
if (!(elem.tagName == "line")) return elem;
if (!(elem.tagName === 'line')) {return elem;}
// Convert to polyline to accept mid-arrow
var x1 = elem.getAttribute('x1')-0;
var x2 = elem.getAttribute('x2')-0;
var y1 = elem.getAttribute('y1')-0;
var y2 = elem.getAttribute('y2')-0;
var x1 = Number(elem.getAttribute('x1'));
var x2 = Number(elem.getAttribute('x2'));
var y1 = Number(elem.getAttribute('y1'));
var y2 = Number(elem.getAttribute('y2'));
var id = elem.id;
var mid_pt = (' '+((x1+x2)/2)+','+((y1+y2)/2) + ' ');
@ -300,7 +285,7 @@ svgEditor.addExtension("Markers", function(S) {
$.each(mtypes, function(i, pos) { // get any existing marker definitions
var nam = 'marker-'+pos;
var m = elem.getAttribute(nam);
if (m) pline.setAttribute(nam,elem.getAttribute(nam));
if (m) {pline.setAttribute(nam,elem.getAttribute(nam));}
});
var batchCmd = new S.BatchCommand();
@ -315,6 +300,30 @@ svgEditor.addExtension("Markers", function(S) {
return pline;
}
function setMarker() {
var poslist={'start_marker':'start','mid_marker':'mid','end_marker':'end'};
var pos = poslist[this.id];
var marker_name = 'marker-'+pos;
var val = this.value;
var el = selElems[0];
var marker = getLinked(el, marker_name);
if (marker) {$(marker).remove();}
el.removeAttribute(marker_name);
if (val == '') {val = '\\nomarker';}
if (val == '\\nomarker') {
setIcon(pos,val);
S.call("changed", selElems);
return;
}
// Set marker on element
var id = marker_prefix + pos + '_' + el.id;
addMarker(id, val);
svgCanvas.changeSelectedAttribute(marker_name, "url(#" + id + ")");
if (el.tagName === 'line' && pos == 'mid') {el = convertline(el);}
S.call("changed", selElems);
setIcon(pos,val);
}
// called when the main system modifies an object
// this routine changes the associated markers to be the same color
function colorChanged(elem) {
@ -322,14 +331,14 @@ svgEditor.addExtension("Markers", function(S) {
$.each(mtypes, function(i, pos) {
var marker = getLinked(elem, 'marker-'+pos);
if (!marker) return;
if (!marker.attributes.se_type) return; //not created by this extension
if (!marker) {return;}
if (!marker.attributes.se_type) {return;} // not created by this extension
var ch = marker.lastElementChild;
if (!ch) return;
var curfill = ch.getAttribute("fill");
var curstroke = ch.getAttribute("stroke")
if (curfill && curfill!='none') ch.setAttribute("fill",color);
if (curstroke && curstroke!='none') ch.setAttribute("stroke",color);
if (!ch) {return;}
var curfill = ch.getAttribute('fill');
var curstroke = ch.getAttribute('stroke');
if (curfill && curfill != 'none') {ch.setAttribute('fill', color);}
if (curstroke && curstroke != 'none') {ch.setAttribute('stroke', color);}
});
}
@ -340,7 +349,7 @@ svgEditor.addExtension("Markers", function(S) {
var id = marker_prefix + pos + '_' + el.id;
var marker_name = 'marker-'+pos;
var marker = getLinked(el, marker_name);
if (!marker || !marker.attributes.se_type) return; //not created by this extension
if (!marker || !marker.attributes.se_type) {return;} // not created by this extension
var url = el.getAttribute(marker_name);
if (url) {
var len = el.id.length;
@ -349,7 +358,7 @@ svgEditor.addExtension("Markers", function(S) {
var val = $('#'+pos + '_marker').attr('value');
addMarker(id, val);
svgCanvas.changeSelectedAttribute(marker_name, "url(#" + id + ")");
if (el.tagName == "line" && pos=='mid') el=convertline(el);
if (el.tagName === 'line' && pos == 'mid') {el = convertline(el);}
S.call("changed", selElems);
}
}
@ -360,18 +369,20 @@ svgEditor.addExtension("Markers", function(S) {
function triggerTextEntry(pos, val) {
$('#'+pos+'_marker').val(val);
$('#'+pos+'_marker').change();
var txtbox = $('#'+pos+'_marker');
//if (val.substr(0,1)=='\\') txtbox.hide();
//else txtbox.show();
// var txtbox = $('#'+pos+'_marker');
// if (val.substr(0,1)=='\\') {txtbox.hide();}
// else {txtbox.show();}
}
function setIcon(pos,id) {
if (id.substr(0,1)!='\\') id='\\textmarker'
var ci = '#'+id_prefix+pos+'_'+id.substr(1);
svgEditor.setIcon('#cur_' + pos +'_marker_list', $(ci).children());
$(ci).addClass('current').siblings().removeClass('current');
function showTextPrompt(pos) {
var def = $('#'+pos+'_marker').val();
if (def.substr(0,1) === '\\') {def = '';}
$.prompt('Enter text for ' + pos + ' marker', def , function(txt) {
if (txt) {triggerTextEntry(pos, txt);}
});
}
/*
function setMarkerSet(obj) {
var parts = this.id.split('_');
var set = parts[2];
@ -393,20 +404,14 @@ svgEditor.addExtension("Markers", function(S) {
break;
}
}
function showTextPrompt(pos) {
var def = $('#'+pos+'_marker').val();
if (def.substr(0,1)=='\\') def='';
$.prompt('Enter text for ' + pos + ' marker', def , function(txt) { if (txt) triggerTextEntry(pos,txt); });
}
*/
// callback function for a toolbar button click
function setArrowFromButton(obj) {
var parts = this.id.split('_');
var pos = parts[1];
var val = parts[2];
if (parts[3]) val+='_'+parts[3];
if (parts[3]) { val += '_' + parts[3];}
if (val != 'textmarker') {
triggerTextEntry(pos, '\\'+val);
@ -416,9 +421,11 @@ svgEditor.addExtension("Markers", function(S) {
}
function getTitle(lang,id) {
var list = lang_list[lang];
for (var i in list) {
if (list[i].id==id) return list[i].title;
var i, list = lang_list[lang];
for (i in list) {
if (list.hasOwnProperty(i) && list[i].id == id) {
return list[i].title;
}
}
return id;
}
@ -428,7 +435,7 @@ svgEditor.addExtension("Markers", function(S) {
// TODO: need to incorporate language specific titles
function buildButtonList() {
var buttons=[];
var i=0;
// var i = 0;
/*
buttons.push({
id:id_prefix + 'markers_off',
@ -543,7 +550,7 @@ svgEditor.addExtension("Markers", function(S) {
while(i--) {
var elem = selElems[i];
if(elem && $.inArray(elem.tagName, marker_elems) != -1) {
if(elem && $.inArray(elem.tagName, marker_elems) !== -1) {
if(opts.selectedElement && !opts.multiselected) {
showPanel(true);
} else {
@ -566,7 +573,7 @@ svgEditor.addExtension("Markers", function(S) {
colorChanged(elem);
updateReferences(elem);
}
changing_flag = false;
// changing_flag = false; // Not apparently in use
}
};
});

View File

@ -1,3 +1,5 @@
/*globals MathJax, svgEditor, svgCanvas, $*/
/*jslint es5: true, todo: true, vars: true*/
/*
* ext-mathjax.js
*
@ -7,11 +9,11 @@
*
*/
svgEditor.addExtension("mathjax", function() {
svgEditor.addExtension("mathjax", function() {'use strict';
// Configuration of the MathJax extention.
// This will be added to the head tag before MathJax is loaded.
var mathjaxConfiguration = '<script type="text/x-mathjax-config">\
var /*mathjaxConfiguration = '<script type="text/x-mathjax-config">\
MathJax.Hub.Config({\
extensions: ["tex2jax.js"],\
jax: ["input/TeX","output/SVG"],\
@ -32,8 +34,8 @@ svgEditor.addExtension("mathjax", function() {
"SVG": {\
}\
});\
</script>',
mathjaxSrc = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
</script>',*/
// mathjaxSrc = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
mathjaxSrcSecure = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG.js',
math,
locationX,
@ -76,13 +78,13 @@ svgEditor.addExtension("mathjax", function() {
var mathjaxMath = $('.MathJax_SVG');
var svg = $(mathjaxMath.html());
svg.find('use').each(function() {
var x, y, transform;
var x, y, id, transform;
// TODO: find a less pragmatic and more elegant solution to this.
if ($(this).attr('href')) {
var id = $(this).attr('href').slice(1); // Works in Chrome.
id = $(this).attr('href').slice(1); // Works in Chrome.
} else {
var id = $(this).attr('xlink:href').slice(1); // Works in Firefox.
id = $(this).attr('xlink:href').slice(1); // Works in Firefox.
}
var glymph = $('#' + id).clone().removeAttr('id');

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgedit, $ */
/*jslint es5: true, vars: true*/
/*
* ext-overview_window.js
*
@ -8,7 +10,7 @@
*/
var overviewWindowGlobals = {};
svgEditor.addExtension("overview_window", function() {
svgEditor.addExtension("overview_window", function() { 'use strict';
//define and insert the base html element
var propsWindowHtml= "\
<div id=\"overview_window_content_pane\" style=\" width:100%; word-wrap:break-word; display:inline-block; margin-top:20px;\">\
@ -47,7 +49,7 @@ svgEditor.addExtension("overview_window", function() {
};
$("#workarea").scroll(function(){
if(!(overviewWindowGlobals.viewBoxDragging)){
updateViewBox()
updateViewBox();
}
});
$("#workarea").resize(updateViewBox);
@ -111,8 +113,8 @@ svgEditor.addExtension("overview_window", function() {
var viewBoxWidth =parseFloat($("#overview_window_view_box").css("min-width" ));
var viewBoxHeight=parseFloat($("#overview_window_view_box").css("min-height"));
var viewBoxX=mouseX-.5*viewBoxWidth;
var viewBoxY=mouseY-.5*viewBoxHeight;
var viewBoxX=mouseX - 0.5 * viewBoxWidth;
var viewBoxY=mouseY- 0.5 * viewBoxHeight;
//deal with constraints
if(viewBoxX<0){
viewBoxX=0;

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgCanvas*/
/*jslint eqeq: true*/
/*
* ext-panning.js
*
@ -11,7 +13,7 @@
This is a very basic SVG-Edit extension to let tablet/mobile devices panning without problem
*/
svgEditor.addExtension('ext-panning', function() {
svgEditor.addExtension('ext-panning', function() {'use strict';
return {
name: 'Extension Panning',
svgicons: svgEditor.curConfig.extPath + 'ext-panning.xml',

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgCanvas, svgedit, $*/
/*jslint vars: true, eqeq: true, todo: true */
/*
* ext-polygon.js
*
@ -6,23 +8,29 @@
* All rights reserved
*
*/
svgEditor.addExtension("polygon", function(S){
svgEditor.addExtension("polygon", function(S) {'use strict';
var NS = svgedit.NS,
svgcontent = S.svgcontent,
addElem = S.addSvgElementFromJson,
var // NS = svgedit.NS,
// svgcontent = S.svgcontent,
// addElem = S.addSvgElementFromJson,
selElems,
editingitex = false, svgdoc = S.svgroot.parentNode.ownerDocument, started, newFO, edg = 0, newFOG, newFOGParent, newDef, newImageName, newMaskID, undoCommand = "Not image", modeChangeG;
editingitex = false,
// svgdoc = S.svgroot.parentNode.ownerDocument,
// newFOG, newFOGParent, newDef, newImageName, newMaskID, modeChangeG,
// edg = 0,
// undoCommand = "Not image";
started, newFO;
var ccZoom;
var wEl, hEl;
var wOffset, hOffset;
var ccRBG, ccRgbEl;
var ccOpacity;
var brushW, brushH, shape;
var ccDebug = document.getElementById('debugpanel');
// var ccZoom;
// var wEl, hEl;
// var wOffset, hOffset;
// var ccRBG;
var ccRgbEl;
// var ccOpacity;
// var brushW, brushH;
var shape;
// var ccDebug = document.getElementById('debugpanel');
/* var properlySourceSizeTextArea = function(){
// TODO: remove magic numbers here and get values from CSS
@ -38,10 +46,12 @@ svgEditor.addExtension("polygon", function(S){
$('#polygon_panel').toggle(on);
}
/*
function toggleSourceButtons(on){
$('#tool_source_save, #tool_source_cancel').toggle(!on);
$('#polygon_save, #polygon_cancel').toggle(on);
}
*/
function setAttr(attr, val){
svgCanvas.changeSelectedAttribute(attr, val);
@ -50,14 +60,57 @@ svgEditor.addExtension("polygon", function(S){
function cot(n){
return 1 / Math.tan(n);
};
}
function sec(n){
return 1 / Math.cos(n);
};
}
/**
* Obtained from http://code.google.com/p/passenger-top/source/browse/instiki/public/svg-edit/editor/extensions/ext-itex.js?r=3
* This function sets the content of of the currently-selected foreignObject element,
* based on the itex contained in string.
* @param {string} tex The itex text.
* @returns This function returns false if the set was unsuccessful, true otherwise.
*/
/*
function setItexString(tex) {
var mathns = 'http://www.w3.org/1998/Math/MathML',
xmlnsns = 'http://www.w3.org/2000/xmlns/',
ajaxEndpoint = '../../itex';
var elt = selElems[0];
try {
var math = svgdoc.createElementNS(mathns, 'math');
math.setAttributeNS(xmlnsns, 'xmlns', mathns);
math.setAttribute('display', 'inline');
var semantics = document.createElementNS(mathns, 'semantics');
var annotation = document.createElementNS(mathns, 'annotation');
annotation.setAttribute('encoding', 'application/x-tex');
annotation.textContent = tex;
var mrow = document.createElementNS(mathns, 'mrow');
semantics.appendChild(mrow);
semantics.appendChild(annotation);
math.appendChild(semantics);
// make an AJAX request to the server, to get the MathML
$.post(ajaxEndpoint, {'tex': tex, 'display': 'inline'}, function(data){
var children = data.documentElement.childNodes;
while (children.length > 0) {
mrow.appendChild(svgdoc.adoptNode(children[0], true));
}
S.sanitizeSvg(math);
S.call("changed", [elt]);
});
elt.replaceChild(math, elt.firstChild);
S.call("changed", [elt]);
svgCanvas.clearSelection();
} catch(e) {
console.log(e);
return false;
}
return true;
}
*/
return {
name: "polygon",
svgicons: svgEditor.curConfig.extPath + "polygon-icons.svg",
@ -95,20 +148,22 @@ svgEditor.addExtension("polygon", function(S){
$('#polygon_panel').hide();
var endChanges = function(){
}
};
// TODO: Needs to be done after orig icon loads
setTimeout(function(){
// Create source save/cancel buttons
var save = $('#tool_source_save').clone().hide().attr('id', 'polygon_save').unbind().appendTo("#tool_source_back").click(function(){
if (!editingitex)
if (!editingitex) {
return;
}
// Todo: Uncomment the setItexString() function above and handle ajaxEndpoint?
if (!setItexString($('#svg_source_textarea').val())) {
$.confirm("Errors found. Revert to original?", function(ok){
if (!ok)
if (!ok) {
return false;
}
endChanges();
});
}
@ -125,13 +180,13 @@ svgEditor.addExtension("polygon", function(S){
}, 3000);
},
mouseDown: function(opts){
var e = opts.event;
rgb = svgCanvas.getColor("fill");
// var e = opts.event;
var rgb = svgCanvas.getColor("fill");
ccRgbEl = rgb.substring(1, rgb.length);
var sRgb = svgCanvas.getColor("stroke");
// ccSRgbEl = sRgb.substring(1, rgb.length);
sRgb = svgCanvas.getColor("stroke");
ccSRgbEl = sRgb.substring(1, rgb.length);
sRgb = svgCanvas.getColor("stroke");
sWidth = svgCanvas.getStrokeWidth();
var sWidth = svgCanvas.getStrokeWidth();
if (svgCanvas.getMode() == "polygon") {
started = true;
@ -154,27 +209,31 @@ svgEditor.addExtension("polygon", function(S){
return {
started: true
}
};
}
},
mouseMove: function(opts){
if (!started)
if (!started) {
return;
}
if (svgCanvas.getMode() == "polygon") {
var e = opts.event;
// var e = opts.event;
var x = opts.mouse_x;
var y = opts.mouse_y;
var c = $(newFO).attr(["cx", "cy", "sides", "orient", "fill", "strokecolor", "strokeWidth"]);
var cx = c.cx, cy = c.cy, fill = c.fill, strokecolor = c.strokecolor, strokewidth = c.strokeWidth, sides = c.sides, orient = c.orient, edg = (Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy))) / 1.5;
var cx = c.cx, cy = c.cy, fill = c.fill, strokecolor = c.strokecolor, strokewidth = c.strokeWidth, sides = c.sides,
// orient = c.orient,
edg = (Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy))) / 1.5;
newFO.setAttributeNS(null, "edge", edg);
var inradius = (edg / 2) * cot(Math.PI / sides);
var circumradius = inradius * sec(Math.PI / sides);
var points = '';
for (var s = 0; sides >= s; s++) {
var s;
for (s = 0; sides >= s; s++) {
var angle = 2.0 * Math.PI * s / sides;
var x = (circumradius * Math.cos(angle)) + cx;
var y = (circumradius * Math.sin(angle)) + cy;
x = (circumradius * Math.cos(angle)) + cx;
y = (circumradius * Math.sin(angle)) + cy;
points += x + ',' + y + ' ';
}
@ -190,7 +249,7 @@ svgEditor.addExtension("polygon", function(S){
//DrawPoly(cx, cy, sides, edg, orient);
return {
started: true
}
};
}
},
@ -198,12 +257,12 @@ svgEditor.addExtension("polygon", function(S){
mouseUp: function(opts){
if (svgCanvas.getMode() == "polygon") {
var attrs = $(newFO).attr("edge");
keep = (attrs.edge != 0);
var keep = (attrs.edge != 0);
// svgCanvas.addToSelection([newFO], true);
return {
keep: keep,
element: newFO
}
};
}
},
@ -215,7 +274,7 @@ svgEditor.addExtension("polygon", function(S){
while (i--) {
var elem = selElems[i];
if (elem && elem.getAttributeNS(null, 'shape') == "regularPoly") {
if (elem && elem.getAttributeNS(null, 'shape') === 'regularPoly') {
if (opts.selectedElement && !opts.multiselected) {
$('#polySides').val(elem.getAttribute("sides"));
@ -231,7 +290,7 @@ svgEditor.addExtension("polygon", function(S){
}
},
elementChanged: function(opts){
var elem = opts.elems[0];
// var elem = opts.elems[0];
}
};
});

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgedit, svgCanvas, canvg, $, top*/
/*jslint vars: true*/
/*
* ext-server_moinsave.js
*
@ -11,7 +13,7 @@
*/
svgEditor.addExtension("server_opensave", {
callback: function() {
callback: function() {'use strict';
var save_svg_action = '/+modify';
@ -33,7 +35,7 @@ svgEditor.addExtension("server_opensave", {
$.getScript('canvg/canvg.js', function() {
canvg(c, svg, {renderCallback: function() {
var datauri = c.toDataURL('image/png');
var uiStrings = svgEditor.uiStrings;
// var uiStrings = svgEditor.uiStrings;
var png_data = svgedit.utilities.encode64(datauri);
var form = $('<form>').attr({
method: 'post',
@ -45,10 +47,11 @@ svgEditor.addExtension("server_opensave", {
.append('<input type="hidden" name="contenttype" value="application/x-svgdraw">')
.appendTo('body')
.submit().remove();
}})});
}});
});
alert("Saved! Return to Item View!");
top.window.location = '/'+name;
},
}
});
}

View File

@ -1,4 +1,5 @@
/*globals svgEditor, svgCanvas, canvg, $*/
/*globals svgEditor, svgedit, svgCanvas, canvg, $*/
/*jslint eqeq: true*/
/*
* ext-server_opensave.js
*
@ -70,7 +71,7 @@ svgEditor.addExtension("server_opensave", {
canvg(c, data.svg, {renderCallback: function() {
var pre, filename, suffix,
datauri = quality ? c.toDataURL(mimeType, quality) : c.toDataURL(mimeType),
uiStrings = svgEditor.uiStrings,
// uiStrings = svgEditor.uiStrings,
note = '';
// Check if there are issues

View File

@ -1,3 +1,5 @@
/*globals svgEditor, $, DOMParser*/
/*jslint es5: true, vars: true, eqeq: true*/
/*
* ext-shapes.js
*
@ -8,7 +10,7 @@
*
*/
svgEditor.addExtension('shapes', function() {
svgEditor.addExtension('shapes', function() {'use strict';
var current_d, cur_shape_id;
var canv = svgEditor.canvas;
var cur_shape;
@ -79,28 +81,6 @@ svgEditor.addExtension('shapes', function() {
$('#shape_buttons').empty().append(cur_lib.buttons);
}
function loadLibrary(cat_id) {
var lib = library[cat_id];
if (!lib) {
$('#shape_buttons').html('Loading...');
$.getJSON(svgEditor.curConfig.extPath + 'shapelib/' + cat_id + '.json', function(result) {
cur_lib = library[cat_id] = {
data: result.data,
size: result.size,
fill: result.fill
};
makeButtons(cat_id, result);
loadIcons();
});
return;
}
cur_lib = lib;
if (!lib.buttons.length) makeButtons(cat_id, lib);
loadIcons();
}
function makeButtons(cat, shapes) {
var size = cur_lib.size || 300;
var fill = cur_lib.fill || false;
@ -120,8 +100,8 @@ svgEditor.addExtension('shapes', function() {
var data = shapes.data;
cur_lib.buttons = [];
for (var id in data) {
var id;
for (id in data) {
var path_d = data[id];
var icon = svg_elem.clone();
icon.find('path').attr('d', path_d);
@ -135,6 +115,28 @@ svgEditor.addExtension('shapes', function() {
}
}
function loadLibrary(cat_id) {
var lib = library[cat_id];
if (!lib) {
$('#shape_buttons').html('Loading...');
$.getJSON(svgEditor.curConfig.extPath + 'shapelib/' + cat_id + '.json', function(result) {
cur_lib = library[cat_id] = {
data: result.data,
size: result.size,
fill: result.fill
};
makeButtons(cat_id, result);
loadIcons();
});
return;
}
cur_lib = lib;
if (!lib.buttons.length) {makeButtons(cat_id, lib);}
loadIcons();
}
return {
svgicons: svgEditor.curConfig.extPath + 'ext-shapes.xml',
buttons: [{
@ -189,7 +191,7 @@ svgEditor.addExtension('shapes', function() {
$('#shape_buttons').mouseup(function(evt) {
var btn = $(evt.target).closest('div.tool_button');
if (!btn.length) return;
if (!btn.length) {return;}
var copy = btn.children().clone();
shower.children(':not(.flyout_arrow_horiz)').remove();
@ -239,10 +241,12 @@ svgEditor.addExtension('shapes', function() {
},
mouseDown: function(opts) {
var mode = canv.getMode();
if (mode !== mode_id) return;
if (mode !== mode_id) {return;}
var x = start_x = opts.start_x;
var y = start_y = opts.start_y;
start_x = opts.start_x;
var x = start_x;
start_y = opts.start_y;
var y = start_y;
var cur_style = canv.getStyle();
startClientPos.x = opts.event.clientX;
@ -279,7 +283,7 @@ svgEditor.addExtension('shapes', function() {
},
mouseMove: function(opts) {
var mode = canv.getMode();
if (mode !== mode_id) return;
if (mode !== mode_id) {return;}
var zoom = canv.getZoom();
var evt = opts.event;
@ -311,7 +315,7 @@ svgEditor.addExtension('shapes', function() {
if (x < start_x) {
tx = lastBBox.width;
}
if (y < start_y) ty = lastBBox.height;
if (y < start_y) {ty = lastBBox.height;}
// update the transform list with translate,scale,translate
var translateOrigin = svgroot.createSVGTransform(),
@ -338,7 +342,7 @@ svgEditor.addExtension('shapes', function() {
},
mouseUp: function(opts) {
var mode = canv.getMode();
if (mode !== mode_id) return;
if (mode !== mode_id) {return;}
var keepObject = (opts.event.clientX != startClientPos.x && opts.event.clientY != startClientPos.y);

View File

@ -1,3 +1,5 @@
/*globals svgEditor, svgedit, svgCanvas, $*/
/*jslint vars: true, eqeq: true*/
/*
* ext-star.js
*
@ -7,31 +9,19 @@
*
*/
svgEditor.addExtension('star', function(S){
svgEditor.addExtension('star', function(S){'use strict';
var NS = svgedit.NS,
svgcontent = S.svgcontent,
var // NS = svgedit.NS,
// svgcontent = S.svgcontent,
selElems,
editingitex = false,
svgdoc = S.svgroot.parentNode.ownerDocument,
// editingitex = false,
// svgdoc = S.svgroot.parentNode.ownerDocument,
started,
newFO,
edg = 0,
newFOG,
newFOGParent,
newDef,
newImageName,
newMaskID,
undoCommand = 'Not image',
modeChangeG,
ccZoom,
wEl,
hEl,
wOffset,
hOffset,
ccRgbEl,
brushW,
brushH,
// edg = 0,
// newFOG, newFOGParent, newDef, newImageName, newMaskID,
// undoCommand = 'Not image',
// modeChangeG, ccZoom, wEl, hEl, wOffset, hOffset, ccRgbEl, brushW, brushH,
shape;
function showPanel(on){
@ -43,15 +33,18 @@ svgEditor.addExtension('star', function(S){
$('#star_panel').toggle(on);
}
/*
function toggleSourceButtons(on){
$('#star_save, #star_cancel').toggle(on);
}
*/
function setAttr(attr, val){
svgCanvas.changeSelectedAttribute(attr, val);
S.call('changed', selElems);
}
/*
function cot(n){
return 1 / Math.tan(n);
}
@ -59,6 +52,7 @@ svgEditor.addExtension('star', function(S){
function sec(n){
return 1 / Math.cos(n);
}
*/
return {
name: 'star',
@ -113,13 +107,13 @@ svgEditor.addExtension('star', function(S){
}],
callback: function(){
$('#star_panel').hide();
var endChanges = function(){};
// var endChanges = function(){};
},
mouseDown: function(opts){
var rgb = svgCanvas.getColor('fill');
var ccRgbEl = rgb.substring(1, rgb.length);
// var ccRgbEl = rgb.substring(1, rgb.length);
var sRgb = svgCanvas.getColor('stroke');
var ccSRgbEl = sRgb.substring(1, rgb.length);
// var ccSRgbEl = sRgb.substring(1, rgb.length);
var sWidth = svgCanvas.getStrokeWidth();
if (svgCanvas.getMode() == 'star') {
@ -148,8 +142,9 @@ svgEditor.addExtension('star', function(S){
}
},
mouseMove: function(opts){
if (!started)
if (!started) {
return;
}
if (svgCanvas.getMode() == 'star') {
var x = opts.mouse_x;
var y = opts.mouse_y;
@ -160,7 +155,8 @@ svgEditor.addExtension('star', function(S){
newFO.setAttributeNS(null, 'r2', inradius);
var polyPoints = '';
for (var s = 0; point >= s; s++) {
var s;
for (s = 0; point >= s; s++) {
var angle = 2.0 * Math.PI * (s / point);
if ('point' == orient) {
angle -= (Math.PI / 2);
@ -218,7 +214,7 @@ svgEditor.addExtension('star', function(S){
while (i--) {
var elem = selElems[i];
if (elem && elem.getAttributeNS(null, 'shape') == 'star') {
if (elem && elem.getAttributeNS(null, 'shape') === 'star') {
if (opts.selectedElement && !opts.multiselected) {
// $('#starRadiusMulitplier').val(elem.getAttribute('r2'));
$('#starNumPoints').val(elem.getAttribute('point'));
@ -234,7 +230,7 @@ svgEditor.addExtension('star', function(S){
}
},
elementChanged: function(opts){
var elem = opts.elems[0];
// var elem = opts.elems[0];
}
};
});

View File

@ -12,50 +12,53 @@
<a href="../../images/logo.png">logo.png</a>
<script>
$('a').click(function() {
/*globals $*/
/*jslint vars: true*/
$('a').click(function() {'use strict';
var meta_str;
var href = this.href;
var target = window.parent;
// Convert Non-SVG images to data URL first
// (this could also have been done server-side by the library)
if (this.href.indexOf('.svg') === -1) {
var meta_str = JSON.stringify({
meta_str = JSON.stringify({
name: $(this).text(),
id: href
});
target.postMessage(meta_str, "*");
target.postMessage(meta_str, '*');
var img = new Image();
img.onload = function() {
var canvas = document.createElement("canvas");
var canvas = document.createElement('canvas');
canvas.width = this.width;
canvas.height = this.height;
// load the raster image into the canvas
canvas.getContext("2d").drawImage(this,0,0);
canvas.getContext('2d').drawImage(this, 0, 0);
// retrieve the data: URL
var dataurl;
try {
var dataurl = canvas.toDataURL();
dataurl = canvas.toDataURL();
} catch(err) {
// This fails in Firefox with file:// URLs :(
alert("Data URL conversion failed: " + err);
var dataurl = "";
}
target.postMessage('|' + href + '|' + dataurl, "*");
dataurl = "";
}
target.postMessage('|' + href + '|' + dataurl, '*');
};
img.src = href;
} else {
// Send metadata (also indicates file is about to be sent)
var meta_str = JSON.stringify({
meta_str = JSON.stringify({
name: $(this).text(),
id: href
});
target.postMessage(meta_str, "*");
target.postMessage(meta_str, '*');
// Do ajax request for image's href value
$.get(href, function(data) {
data = '|' + href + '|' + data;
// This is where the magic happens!
target.postMessage(data, "*");
target.postMessage(data, '*');
}, 'html'); // 'html' is necessary to keep returned data as a string
}