refactor to class step 1
This commit is contained in:
@@ -24,7 +24,7 @@ export default {
|
||||
async init (S) {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const
|
||||
addElem = svgCanvas.addSVGElementFromJson,
|
||||
{nonce, $} = S,
|
||||
|
||||
@@ -23,7 +23,7 @@ export default {
|
||||
name: 'connector',
|
||||
async init (S) {
|
||||
const svgEditor = this;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const {getElem} = svgCanvas;
|
||||
const {$, svgroot} = S,
|
||||
addElem = svgCanvas.addSVGElementFromJson,
|
||||
@@ -374,7 +374,7 @@ export default {
|
||||
startX = opts.start_x;
|
||||
startY = opts.start_y;
|
||||
const mode = svgCanvas.getMode();
|
||||
const {curConfig: {initStroke}} = svgEditor;
|
||||
const {curConfig: {initStroke}} = svgEditor.configObj;
|
||||
|
||||
if (mode === 'connector') {
|
||||
if (started) { return undefined; }
|
||||
|
||||
@@ -26,7 +26,7 @@ export default {
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const {$, ChangeElementCommand} = S, // , svgcontent,
|
||||
// svgdoc = S.svgroot.parentNode.ownerDocument,
|
||||
svgCanvas = svgEditor.canvas,
|
||||
{svgCanvas} = svgEditor,
|
||||
addToHistory = function (cmd) { svgCanvas.undoMgr.addCommandToHistory(cmd); },
|
||||
currentStyle = {
|
||||
fillPaint: 'red', fillOpacity: 1.0,
|
||||
|
||||
@@ -24,7 +24,7 @@ export default {
|
||||
async init (S) {
|
||||
const svgEditor = this;
|
||||
const {$, text2xml, NS} = S;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const
|
||||
// {svgcontent} = S,
|
||||
// addElem = svgCanvas.addSVGElementFromJson,
|
||||
|
||||
@@ -24,14 +24,14 @@ export default {
|
||||
async init ({$, NS, getTypeMap}) {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const svgdoc = document.getElementById('svgcanvas').ownerDocument,
|
||||
{assignAttributes} = svgCanvas,
|
||||
hcanvas = document.createElement('canvas'),
|
||||
canvBG = $('#canvasBackground'),
|
||||
units = getTypeMap(), // Assumes prior `init()` call on `units.js` module
|
||||
intervals = [0.01, 0.1, 1, 10, 100, 1000];
|
||||
let showGrid = svgEditor.curConfig.showGrid || false;
|
||||
let showGrid = svgEditor.configObj.curConfig.showGrid || false;
|
||||
|
||||
$(hcanvas).hide().appendTo('body');
|
||||
|
||||
@@ -90,7 +90,7 @@ export default {
|
||||
*/
|
||||
function updateGrid (zoom) {
|
||||
// TODO: Try this with <line> elements, then compare performance difference
|
||||
const unit = units[svgEditor.curConfig.baseUnit]; // 1 = 1px
|
||||
const unit = units[svgEditor.configObj.curConfig.baseUnit]; // 1 = 1px
|
||||
const uMulti = unit * zoom;
|
||||
// Calculate the main number interval
|
||||
const rawM = 100 / uMulti;
|
||||
@@ -109,7 +109,7 @@ export default {
|
||||
const part = bigInt / 10;
|
||||
|
||||
ctx.globalAlpha = 0.2;
|
||||
ctx.strokeStyle = svgEditor.curConfig.gridColor;
|
||||
ctx.strokeStyle = svgEditor.configObj.curConfig.gridColor;
|
||||
for (let i = 1; i < 10; i++) {
|
||||
const subD = Math.round(part * i) + 0.5;
|
||||
// const lineNum = (i % 2)?12:10;
|
||||
@@ -161,7 +161,7 @@ export default {
|
||||
events: {
|
||||
id: 'view_grid',
|
||||
click () {
|
||||
svgEditor.curConfig.showGrid = showGrid = !showGrid;
|
||||
svgEditor.configObj.curConfig.showGrid = showGrid = !showGrid;
|
||||
gridUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export default {
|
||||
async init ({$, importLocale}) {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
return {
|
||||
name: strings.name,
|
||||
events: [{
|
||||
|
||||
@@ -47,7 +47,7 @@ export default {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const {$} = S;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const // {svgcontent} = S,
|
||||
addElem = svgCanvas.addSVGElementFromJson;
|
||||
const mtypes = ['start', 'mid', 'end'];
|
||||
|
||||
@@ -25,7 +25,7 @@ export default {
|
||||
async init ({$}) {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
|
||||
// Configuration of the MathJax extention.
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export default {
|
||||
async init ({importLocale}) {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const buttons = [{
|
||||
id: 'ext-panning',
|
||||
icon: 'panning.png',
|
||||
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
name: 'placemark',
|
||||
async init (S) {
|
||||
const svgEditor = this;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const addElem = svgCanvas.addSVGElementFromJson;
|
||||
const {$} = S; // {svgcontent},
|
||||
let
|
||||
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
name: 'polygon',
|
||||
async init (S) {
|
||||
const svgEditor = this;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const {$} = S, // {svgcontent}
|
||||
// addElem = svgCanvas.addSVGElementFromJson,
|
||||
editingitex = false;
|
||||
|
||||
@@ -26,7 +26,7 @@ export default {
|
||||
async init ({$, encode64, importLocale}) {
|
||||
const svgEditor = this;
|
||||
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
const saveSvgAction = '/+modify';
|
||||
|
||||
// Create upload target (hidden iframe)
|
||||
|
||||
@@ -11,7 +11,7 @@ export default {
|
||||
name: 'shapes',
|
||||
init ({$}) {
|
||||
const svgEditor = this;
|
||||
const canv = svgEditor.canvas;
|
||||
const canv = svgEditor.svgCanvas;
|
||||
const svgroot = canv.getRootElem();
|
||||
let lastBBox = {};
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
name: 'star',
|
||||
async init (S) {
|
||||
const svgEditor = this;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
|
||||
const {$} = S; // {svgcontent},
|
||||
let
|
||||
|
||||
@@ -36,7 +36,7 @@ export default {
|
||||
name: 'storage',
|
||||
init ({$}) {
|
||||
const svgEditor = this;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
|
||||
// We could empty any already-set data for users when they decline storage,
|
||||
// but it would be a risk for users who wanted to store but accidentally
|
||||
@@ -56,7 +56,7 @@ export default {
|
||||
// the "noStorageOnLoad" config setting to true in svgedit-config-*.js.
|
||||
noStorageOnLoad,
|
||||
forceStorage
|
||||
} = svgEditor.curConfig;
|
||||
} = svgEditor.configObj.curConfig;
|
||||
const {storage, updateCanvas} = svgEditor;
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ export default {
|
||||
*/
|
||||
function setSVGContentStorage (val) {
|
||||
if (storage) {
|
||||
const name = 'svgedit-' + svgEditor.curConfig.canvasName;
|
||||
const name = 'svgedit-' + svgEditor.configObj.curConfig.canvasName;
|
||||
if (!val) {
|
||||
storage.removeItem(name);
|
||||
} else {
|
||||
|
||||
@@ -99,7 +99,7 @@ export default {
|
||||
webappfind: {
|
||||
type: saveMessage,
|
||||
pathID,
|
||||
content: svgEditor.canvas.getSvgString()
|
||||
content: svgEditor.svgCanvas.getSvgString()
|
||||
}
|
||||
}, window.location.origin === 'null'
|
||||
// Avoid "null" string error for `file:` protocol (even
|
||||
|
||||
@@ -8,7 +8,7 @@ export default {
|
||||
name: 'xdomain-messaging',
|
||||
init () {
|
||||
const svgEditor = this;
|
||||
const svgCanvas = svgEditor.canvas;
|
||||
const {svgCanvas} = svgEditor;
|
||||
try {
|
||||
window.addEventListener('message', function (e) {
|
||||
// We accept and post strings for the sake of IE9 support
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
// The default is not to allow any origins, including even the same domain or
|
||||
// if run on a `file:///` URL. See `svgedit-config-es.js` for an example of how
|
||||
// to configure
|
||||
const {allowedOrigins} = svgEditor.curConfig;
|
||||
const {allowedOrigins} = svgEditor.configObj.curConfig;
|
||||
if (!allowedOrigins.includes('*') && !allowedOrigins.includes(e.origin)) {
|
||||
console.log(`Origin ${e.origin} not whitelisted for posting to ${window.origin}`); // eslint-disable-line no-console
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user