Added list of arrows to select for arrows extension

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1337 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Alexis Deveria 2010-02-03 20:00:01 +00:00
parent e20d3dc39f
commit 68dd9def3a
1 changed files with 68 additions and 29 deletions

View File

@ -16,12 +16,10 @@ $(function() {
var lang_list = { var lang_list = {
"en":[ "en":[
{"id": "arrow_none", "textContent": "No arrow" }, {"id": "arrow_none", "textContent": "No arrow" }
{"id": "arrow_arrow", "textContent": "Arrow" }
], ],
"fr":[ "fr":[
{"id": "arrow_none", "textContent": "Sans flèche" }, {"id": "arrow_none", "textContent": "Sans flèche" }
{"id": "arrow_arrow", "textContent": "Flèche" }
] ]
}; };
@ -35,18 +33,34 @@ $(function() {
} }
} }
function addArrow() { function resetMarker() {
var defs = S.findDefs(); var el = selElems[0];
var m_id = "se_arrow"; el.removeAttribute("marker-start");
var marker = getElem(m_id); el.removeAttribute("marker-mid");
el.removeAttribute("marker-end");
}
function addMarker(id, type) {
// TODO: Make marker (or use?) per arrow type, since refX can be different
var marker = getElem(id);
var pathdata = {
se_arrow_fw: {d:"m0,0l10,5l-10,5l5,-5l-5,-5z", refx:10},
se_arrow_bk: {d:"m10,0l-10,5l10,5l-5,-5l5,-5z", refx:0}
}
var data = pathdata[id];
if(type == "mid") {
data.refx = 5;
}
if(!marker) { if(!marker) {
marker = addElem({ marker = addElem({
"element": "marker", "element": "marker",
"attr": { "attr": {
"viewBox": "0 0 10 10", "viewBox": "0 0 10 10",
"id": m_id, "id": id,
"refX": 10,
"refY": 5, "refY": 5,
"markerUnits": "strokeWidth", "markerUnits": "strokeWidth",
"markerWidth": 5, "markerWidth": 5,
@ -57,39 +71,64 @@ $(function() {
var arrow = addElem({ var arrow = addElem({
"element": "path", "element": "path",
"attr": { "attr": {
"d": "m0,0l10,5l-10,5l5,-5l-5,-5z", "d": data.d,
"fill": "#000" "fill": "#000"
} }
}); });
marker.appendChild(arrow); marker.appendChild(arrow);
defs.appendChild(marker); S.findDefs().appendChild(marker);
} }
selElems[0].setAttribute("marker-end", "url(#" + m_id + ")"); marker.setAttribute('refX', data.refx);
} }
function remArrow() { function setArrow(type) {
selElems[0].removeAttribute("marker-end"); resetMarker();
if(type == "none") {
return;
} }
var fw_id = "se_arrow_fw";
var bk_id = "se_arrow_bk";
// Set marker on element
var id = fw_id;
if(type == "mid_bk") {
type = "mid";
id = bk_id;
} else if(type == "both") {
addMarker(bk_id, type);
selElems[0].setAttribute("marker-start", "url(#" + bk_id + ")");
type = "end";
id = fw_id;
} else if (type == "start") {
id = bk_id;
}
addMarker(id, type);
selElems[0].setAttribute("marker-"+type, "url(#" + id + ")");
}
// Init code // Init code
(function() { (function() {
var conn_tools = $('<div id="arrow_panel">\ var conn_tools = $('<div id="arrow_panel">\
<label><select id="arrow_list">\ <label><select id="arrow_list">\
<option id="arrow_none" value="none">No arrow</option>\ <option value="none">No arrow</option>\
<option id="arrow_arrow" value="arrow">Arrow</option>\ <option value="end">----&gt;</option>\
<option value="start">&lt;----</option>\
<option value="both">&lt;---&gt;</option>\
<option value="mid">--&gt;--</option>\
<option value="mid_bk">--&lt;--</option>\
</select></label></div>"').hide().appendTo("#tools_top"); </select></label></div>"').hide().appendTo("#tools_top");
$('#arrow_list').change(function() { $('#arrow_list').change(function() {
switch ( this.value ) { setArrow(this.value);
case "arrow":
addArrow();
break;
case "none":
remArrow();
break;
}
}); });
}()); }());