- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
/* globals jQuery */
|
2010-02-08 21:26:54 +00:00
|
|
|
/*
|
|
|
|
* ext-arrows.js
|
|
|
|
*
|
2012-09-16 18:53:27 +00:00
|
|
|
* Licensed under the MIT License
|
2010-02-08 21:26:54 +00:00
|
|
|
*
|
|
|
|
* Copyright(c) 2010 Alexis Deveria
|
|
|
|
*
|
|
|
|
*/
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
import svgEditor from '../svg-editor.js';
|
2018-05-16 00:53:27 +00:00
|
|
|
svgEditor.addExtension('Arrows', function (S) {
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
const svgCanvas = svgEditor.canvas;
|
2018-05-18 03:25:45 +00:00
|
|
|
const $ = jQuery;
|
|
|
|
const // {svgcontent} = S,
|
2018-05-18 04:54:31 +00:00
|
|
|
addElem = S.addSvgElementFromJson,
|
2018-05-18 03:25:45 +00:00
|
|
|
{nonce} = S,
|
2018-05-18 04:54:31 +00:00
|
|
|
langList = {
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
en: [
|
|
|
|
{id: 'arrow_none', textContent: 'No arrow'}
|
2018-05-18 04:54:31 +00:00
|
|
|
],
|
- Breaking change: Rename config file to `svgedit-config-iife.js` (or for the module version, `svgedit-config-es.js`);
also expect one directory higher; incorporates #207 (@iuyiuy)
- Breaking change: Separate `extIconsPath` from `extPath` (not copying over icons)
- Breaking change: Don't reference `custom.css` in HTML; can instead be referenced in JavaScript through
the config file (provided in `svgedit-config-sample-iife.js`/`svgedit-config-sample-es.js` as `svgedit-custom.css` for
better namespacing); incorporates #207 (@iuyiuy)
- Breaking change: Remove minified jgraduate/spinbtn files (minified within Rollup routine)
- Fix: Zoom when scrolled; incorporates #169 (@AndrolGenhald), adapting for conventions; also allow avoidance when shift key pressed
- Fix: Update Atom feed reference in HTML
- Fixes related to recent commits: Some path and method name fixes needed, function order, missing methods, variable scope declaration, no need for DOMContentLoaded listeners in modules, switch back to non-default export, avoid trimming nullish, deal with mock tests, fix `math.matrixMultiply`, use jquery-svg where needed for array/SVG attributes; add babel-polyfill and defer script to imagelib; other misc. fixes
- Enhancement: Move config-sample.js out of `editor` directory
- Enhancement: For `callback`-style extensions, also provide config object; add following
to that object: buildCanvgCallback, canvg, decode64, encode64, executeAfterLoads, getTypeMap, isChrome, ieIE, NS, text2xml
- Enhancement: Complete ES6 modules work (extensions, locales, tests), along with Babel;
make Node build routine for converting modular source to non-modular,
use `loadStylesheets` for modular stylehsheet defining (but parallel loading);
- Enhancement: Add `stylesheets` config for modular but parallel stylesheet loading with `@default` option for simple inclusion/exclusion of defaults (if not going with default).
- Refactoring: Clean up `svg-editor.html`: consistent indents; avoid extra lbs, avoid long lines
- Refactoring: Avoid embedded API adding inline JavaScript listener
- Refactoring: Move layers and context code to `draw.js`
- Refactoring: Move `pathActions` from `svgcanvas.js` (though preserve aliases to these methods on `canvas`) and `convertPath` from `svgutils.js` to `path.js`
- Refactoring: Move `getStrokedBBox` from `svgcanvas.js` (while keeping an alias) to `svgutils.js` (as `getStrokedBBoxDefaultVisible` to avoid conflict with existing)
- Docs: Remove "dependencies" comments in code except where summarizing role of jQuery or a non-obvious dependency
- Refactoring/Linting: Enfore `no-extra-semi` and `quote-props` rules
- Refactoring: Further avoidance of quotes on properties (as possible)
- Refactoring: Use `class` in place of functions where intended as classes
- Refactoring: Consistency and granularity in extensions imports
- Testing: Update QUnit to 2.6.1 (node_modules) and Sinon to 5.0.8 (and add sinon-test at 2.1.3) and enforce eslint-plugin-qunit linting rules; update custom extensions
- Testing: Add node-static for automating (and accessing out-of-directory contents)
- Testing: Avoid HTML attributes for styling
- Testing: Add npm `test` script
- Testing: Comment out unused jQuery SVG test
- Testing: Add test1 and svgutils_performance_test to all tests page
- Testing: Due apparently to Path having not been a formal class, the test was calling it without `new`; refactored now with sufficient mock data to take into account it is a class
- npm: Update devDeps
- npm: Add html modules and config build to test script
2018-05-22 10:03:16 +00:00
|
|
|
fr: [
|
|
|
|
{id: 'arrow_none', textContent: 'Sans flèche'}
|
2018-05-18 04:54:31 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
prefix = 'se_arrow_';
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let selElems, arrowprefix, randomizeIds = S.randomize_ids;
|
|
|
|
|
2018-05-18 04:54:31 +00:00
|
|
|
function setArrowNonce (window, n) {
|
|
|
|
randomizeIds = true;
|
|
|
|
arrowprefix = prefix + n + '_';
|
|
|
|
pathdata.fw.id = arrowprefix + 'fw';
|
|
|
|
pathdata.bk.id = arrowprefix + 'bk';
|
|
|
|
}
|
|
|
|
|
|
|
|
function unsetArrowNonce (window) {
|
|
|
|
randomizeIds = false;
|
|
|
|
arrowprefix = prefix;
|
|
|
|
pathdata.fw.id = arrowprefix + 'fw';
|
|
|
|
pathdata.bk.id = arrowprefix + 'bk';
|
|
|
|
}
|
|
|
|
|
|
|
|
svgCanvas.bind('setnonce', setArrowNonce);
|
|
|
|
svgCanvas.bind('unsetnonce', unsetArrowNonce);
|
|
|
|
|
|
|
|
if (randomizeIds) {
|
|
|
|
arrowprefix = prefix + nonce + '_';
|
|
|
|
} else {
|
|
|
|
arrowprefix = prefix;
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const pathdata = {
|
2018-05-18 04:54:31 +00:00
|
|
|
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) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const str = elem.getAttribute(attr);
|
2018-05-18 04:54:31 +00:00
|
|
|
if (!str) { return null; }
|
2018-05-18 03:25:45 +00:00
|
|
|
const m = str.match(/\(#(.*)\)/);
|
2018-05-18 04:54:31 +00:00
|
|
|
if (!m || m.length !== 2) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return S.getElem(m[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPanel (on) {
|
|
|
|
$('#arrow_panel').toggle(on);
|
|
|
|
if (on) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const el = selElems[0];
|
|
|
|
const end = el.getAttribute('marker-end');
|
|
|
|
const start = el.getAttribute('marker-start');
|
|
|
|
const mid = el.getAttribute('marker-mid');
|
|
|
|
let val;
|
2018-05-18 04:54:31 +00:00
|
|
|
if (end && start) {
|
|
|
|
val = 'both';
|
|
|
|
} else if (end) {
|
|
|
|
val = 'end';
|
|
|
|
} else if (start) {
|
|
|
|
val = 'start';
|
|
|
|
} else if (mid) {
|
|
|
|
val = 'mid';
|
2018-05-18 03:25:45 +00:00
|
|
|
if (mid.includes('bk')) {
|
2018-05-18 04:54:31 +00:00
|
|
|
val = 'mid_bk';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!start && !mid && !end) {
|
|
|
|
val = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#arrow_list').val(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetMarker () {
|
2018-05-18 03:25:45 +00:00
|
|
|
const el = selElems[0];
|
2018-05-18 04:54:31 +00:00
|
|
|
el.removeAttribute('marker-start');
|
|
|
|
el.removeAttribute('marker-mid');
|
|
|
|
el.removeAttribute('marker-end');
|
|
|
|
}
|
|
|
|
|
|
|
|
function addMarker (dir, type, id) {
|
|
|
|
// TODO: Make marker (or use?) per arrow type, since refX can be different
|
|
|
|
id = id || arrowprefix + dir;
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const data = pathdata[dir];
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
if (type === 'mid') {
|
|
|
|
data.refx = 5;
|
|
|
|
}
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let marker = S.getElem(id);
|
2018-05-18 04:54:31 +00:00
|
|
|
if (!marker) {
|
|
|
|
marker = addElem({
|
2018-05-18 03:25:45 +00:00
|
|
|
element: 'marker',
|
|
|
|
attr: {
|
|
|
|
viewBox: '0 0 10 10',
|
|
|
|
id,
|
|
|
|
refY: 5,
|
|
|
|
markerUnits: 'strokeWidth',
|
|
|
|
markerWidth: 5,
|
|
|
|
markerHeight: 5,
|
|
|
|
orient: 'auto',
|
|
|
|
style: 'pointer-events:none' // Currently needed for Opera
|
2018-05-18 04:54:31 +00:00
|
|
|
}
|
|
|
|
});
|
2018-05-18 03:25:45 +00:00
|
|
|
const arrow = addElem({
|
|
|
|
element: 'path',
|
|
|
|
attr: {
|
|
|
|
d: data.d,
|
|
|
|
fill: '#000000'
|
2018-05-18 04:54:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
marker.appendChild(arrow);
|
|
|
|
S.findDefs().appendChild(marker);
|
|
|
|
}
|
|
|
|
|
|
|
|
marker.setAttribute('refX', data.refx);
|
|
|
|
|
|
|
|
return marker;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setArrow () {
|
|
|
|
resetMarker();
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
let type = this.value;
|
2018-05-18 04:54:31 +00:00
|
|
|
if (type === 'none') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set marker on element
|
2018-05-18 03:25:45 +00:00
|
|
|
let dir = 'fw';
|
2018-05-18 04:54:31 +00:00
|
|
|
if (type === 'mid_bk') {
|
|
|
|
type = 'mid';
|
|
|
|
dir = 'bk';
|
|
|
|
} else if (type === 'both') {
|
|
|
|
addMarker('bk', type);
|
|
|
|
svgCanvas.changeSelectedAttribute('marker-start', 'url(#' + pathdata.bk.id + ')');
|
|
|
|
type = 'end';
|
|
|
|
dir = 'fw';
|
|
|
|
} else if (type === 'start') {
|
|
|
|
dir = 'bk';
|
|
|
|
}
|
|
|
|
|
|
|
|
addMarker(dir, type);
|
|
|
|
svgCanvas.changeSelectedAttribute('marker-' + type, 'url(#' + pathdata[dir].id + ')');
|
|
|
|
S.call('changed', selElems);
|
|
|
|
}
|
|
|
|
|
|
|
|
function colorChanged (elem) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const color = elem.getAttribute('stroke');
|
|
|
|
const mtypes = ['start', 'mid', 'end'];
|
|
|
|
const defs = S.findDefs();
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
$.each(mtypes, function (i, type) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const marker = getLinked(elem, 'marker-' + type);
|
2018-05-18 04:54:31 +00:00
|
|
|
if (!marker) { return; }
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const curColor = $(marker).children().attr('fill');
|
|
|
|
const curD = $(marker).children().attr('d');
|
2018-05-18 04:54:31 +00:00
|
|
|
if (curColor === color) { return; }
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const allMarkers = $(defs).find('marker');
|
|
|
|
let newMarker = null;
|
2018-05-18 04:54:31 +00:00
|
|
|
// Different color, check if already made
|
|
|
|
allMarkers.each(function () {
|
2018-05-18 03:25:45 +00:00
|
|
|
const attrs = $(this).children().attr(['fill', 'd']);
|
2018-05-18 04:54:31 +00:00
|
|
|
if (attrs.fill === color && attrs.d === curD) {
|
|
|
|
// Found another marker with this color and this path
|
|
|
|
newMarker = this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!newMarker) {
|
|
|
|
// Create a new marker with this color
|
2018-05-18 03:25:45 +00:00
|
|
|
const lastId = marker.id;
|
|
|
|
const dir = lastId.includes('_fw') ? 'fw' : 'bk';
|
2018-05-18 04:54:31 +00:00
|
|
|
|
|
|
|
newMarker = addMarker(dir, type, arrowprefix + dir + allMarkers.length);
|
|
|
|
|
|
|
|
$(newMarker).children().attr('fill', color);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(elem).attr('marker-' + type, 'url(#' + newMarker.id + ')');
|
|
|
|
|
|
|
|
// Check if last marker can be removed
|
2018-05-18 03:25:45 +00:00
|
|
|
let remove = true;
|
2018-05-18 04:54:31 +00:00
|
|
|
$(S.svgcontent).find('line, polyline, path, polygon').each(function () {
|
2018-05-18 03:25:45 +00:00
|
|
|
const elem = this;
|
2018-05-18 04:54:31 +00:00
|
|
|
$.each(mtypes, function (j, mtype) {
|
|
|
|
if ($(elem).attr('marker-' + mtype) === 'url(#' + marker.id + ')') {
|
|
|
|
remove = false;
|
|
|
|
return remove;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!remove) { return false; }
|
|
|
|
});
|
|
|
|
|
|
|
|
// Not found, so can safely remove
|
|
|
|
if (remove) {
|
|
|
|
$(marker).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: 'Arrows',
|
|
|
|
context_tools: [{
|
|
|
|
type: 'select',
|
|
|
|
panel: 'arrow_panel',
|
|
|
|
title: 'Select arrow type',
|
|
|
|
id: 'arrow_list',
|
|
|
|
options: {
|
|
|
|
none: 'No arrow',
|
|
|
|
end: '---->',
|
|
|
|
start: '<----',
|
|
|
|
both: '<--->',
|
|
|
|
mid: '-->--',
|
|
|
|
mid_bk: '--<--'
|
|
|
|
},
|
|
|
|
defval: 'none',
|
|
|
|
events: {
|
|
|
|
change: setArrow
|
|
|
|
}
|
|
|
|
}],
|
2018-05-18 03:25:45 +00:00
|
|
|
callback () {
|
2018-05-18 04:54:31 +00:00
|
|
|
$('#arrow_panel').hide();
|
|
|
|
// Set ID so it can be translated in locale file
|
|
|
|
$('#arrow_list option')[0].id = 'connector_no_arrow';
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
addLangData (lang) {
|
2018-05-18 04:54:31 +00:00
|
|
|
return {
|
|
|
|
data: langList[lang]
|
|
|
|
};
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
selectedChanged (opts) {
|
2018-05-18 04:54:31 +00:00
|
|
|
// Use this to update the current selected elements
|
|
|
|
selElems = opts.elems;
|
|
|
|
|
2018-05-18 03:25:45 +00:00
|
|
|
const markerElems = ['line', 'path', 'polyline', 'polygon'];
|
|
|
|
let i = selElems.length;
|
2018-05-18 04:54:31 +00:00
|
|
|
while (i--) {
|
2018-05-18 03:25:45 +00:00
|
|
|
const elem = selElems[i];
|
|
|
|
if (elem && markerElems.includes(elem.tagName)) {
|
2018-05-18 04:54:31 +00:00
|
|
|
if (opts.selectedElement && !opts.multiselected) {
|
|
|
|
showPanel(true);
|
|
|
|
} else {
|
|
|
|
showPanel(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showPanel(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-05-18 03:25:45 +00:00
|
|
|
elementChanged (opts) {
|
|
|
|
const elem = opts.elems[0];
|
2018-05-18 04:54:31 +00:00
|
|
|
if (elem && (
|
|
|
|
elem.getAttribute('marker-start') ||
|
|
|
|
elem.getAttribute('marker-mid') ||
|
|
|
|
elem.getAttribute('marker-end')
|
|
|
|
)) {
|
2018-05-18 03:25:45 +00:00
|
|
|
// const start = elem.getAttribute('marker-start');
|
|
|
|
// const mid = elem.getAttribute('marker-mid');
|
|
|
|
// const end = elem.getAttribute('marker-end');
|
2018-05-18 04:54:31 +00:00
|
|
|
// Has marker, so see if it should match color
|
|
|
|
colorChanged(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2010-02-08 21:26:54 +00:00
|
|
|
});
|