jquery removal, isolate svgcavas from svgedit, tests
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @license MIT
|
||||
* @copyright 2011 Jeff Schiller
|
||||
*/
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js';
|
||||
import jQueryPluginSVG from './jQuery.attr.js';
|
||||
import {NS} from '../common/namespaces.js';
|
||||
|
||||
const $ = jQueryPluginSVG(jQuery);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* globals jQuery */
|
||||
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import {isWebkit} from '../common/browser.js';
|
||||
import {convertPath} from './path.js';
|
||||
import {preventClickDefault} from './utilities.js';
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
/**
|
||||
* @module jQueryPluginDBox
|
||||
*/
|
||||
/**
|
||||
* @param {external:jQuery} $
|
||||
* @param {PlainObject} [strings]
|
||||
* @param {PlainObject} [strings.ok]
|
||||
* @param {PlainObject} [strings.cancel]
|
||||
* @returns {external:jQuery}
|
||||
*/
|
||||
export default function jQueryPluginDBox ($, {
|
||||
ok: okString = 'Ok',
|
||||
cancel: cancelString = 'Cancel'
|
||||
} = {}) {
|
||||
// This sets up alternative dialog boxes. They mostly work the same way as
|
||||
// their UI counterparts, expect instead of returning the result, a callback
|
||||
// needs to be included that returns the result as its first parameter.
|
||||
// In the future we may want to add additional types of dialog boxes, since
|
||||
// they should be easy to handle this way.
|
||||
$('#dialog_container').draggable({
|
||||
cancel: '#dialog_content, #dialog_buttons *',
|
||||
containment: 'window'
|
||||
}).css('position', 'absolute');
|
||||
|
||||
const box = $('#dialog_box'),
|
||||
btnHolder = $('#dialog_buttons'),
|
||||
dialogContent = $('#dialog_content');
|
||||
|
||||
/**
|
||||
* @typedef {PlainObject} module:jQueryPluginDBox.PromiseResultObject
|
||||
* @property {string|true} response
|
||||
* @property {boolean} checked
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves to `false` (if cancelled), for prompts and selects
|
||||
* without checkboxes, it resolves to the value of the form control. For other
|
||||
* types without checkboxes, it resolves to `true`. For checkboxes, it resolves
|
||||
* to an object with the `response` key containing the same value as the previous
|
||||
* mentioned (string or `true`) and a `checked` (boolean) property.
|
||||
* @typedef {Promise<boolean|string|module:jQueryPluginDBox.PromiseResultObject>} module:jQueryPluginDBox.ResultPromise
|
||||
*/
|
||||
/**
|
||||
* @typedef {PlainObject} module:jQueryPluginDBox.SelectOption
|
||||
* @property {string} text
|
||||
* @property {string} value
|
||||
*/
|
||||
/**
|
||||
* @typedef {PlainObject} module:jQueryPluginDBox.CheckboxInfo
|
||||
* @property {string} label Label for the checkbox
|
||||
* @property {string} value Value of the checkbox
|
||||
* @property {string} tooltip Tooltip on the checkbox label
|
||||
* @property {boolean} checked Whether the checkbox is checked by default
|
||||
*/
|
||||
/**
|
||||
* Triggered upon a change of value for the select pull-down.
|
||||
* @callback module:jQueryPluginDBox.SelectChangeListener
|
||||
* @returns {void}
|
||||
*/
|
||||
/**
|
||||
* Creates a dialog of the specified type with a given message
|
||||
* and any defaults and type-specific metadata. Returns a `Promise`
|
||||
* which resolves differently depending on whether the dialog
|
||||
* was cancelled or okayed (with the response and any checked state).
|
||||
* @param {"alert"|"prompt"|"select"|"process"} type
|
||||
* @param {string} msg
|
||||
* @param {string} [defaultVal]
|
||||
* @param {module:jQueryPluginDBox.SelectOption[]} [opts]
|
||||
* @param {module:jQueryPluginDBox.SelectChangeListener} [changeListener]
|
||||
* @param {module:jQueryPluginDBox.CheckboxInfo} [checkbox]
|
||||
* @returns {jQueryPluginDBox.ResultPromise}
|
||||
*/
|
||||
function dbox (type, msg, defaultVal, opts, changeListener, checkbox) {
|
||||
dialogContent.html('<p>' + msg.replace(/\n/g, '</p><p>') + '</p>')
|
||||
.toggleClass('prompt', (type === 'prompt'));
|
||||
btnHolder.empty();
|
||||
|
||||
const ok = $('<input type="button" data-ok="" value="' + okString + '">').appendTo(btnHolder);
|
||||
|
||||
return new Promise((resolve, reject) => { // eslint-disable-line promise/avoid-new
|
||||
if (type !== 'alert') {
|
||||
$('<input type="button" value="' + cancelString + '">')
|
||||
.appendTo(btnHolder)
|
||||
.click(function () {
|
||||
box.hide();
|
||||
resolve(false);
|
||||
});
|
||||
}
|
||||
|
||||
let ctrl, chkbx;
|
||||
if (type === 'prompt') {
|
||||
ctrl = $('<input type="text">').prependTo(btnHolder);
|
||||
ctrl.val(defaultVal || '');
|
||||
ctrl.bind('keydown', 'return', function () { ok.click(); });
|
||||
} else if (type === 'select') {
|
||||
const div = $('<div style="text-align:center;">');
|
||||
ctrl = $(`<select aria-label="${msg}">`).appendTo(div);
|
||||
if (checkbox) {
|
||||
const label = $('<label>').text(checkbox.label);
|
||||
chkbx = $('<input type="checkbox">').appendTo(label);
|
||||
chkbx.val(checkbox.value);
|
||||
if (checkbox.tooltip) {
|
||||
label.attr('title', checkbox.tooltip);
|
||||
}
|
||||
chkbx.prop('checked', Boolean(checkbox.checked));
|
||||
div.append($('<div>').append(label));
|
||||
}
|
||||
$.each(opts || [], function (opt, val) {
|
||||
if (typeof val === 'object') {
|
||||
ctrl.append($('<option>').val(val.value).html(val.text));
|
||||
} else {
|
||||
ctrl.append($('<option>').html(val));
|
||||
}
|
||||
});
|
||||
dialogContent.append(div);
|
||||
if (defaultVal) {
|
||||
ctrl.val(defaultVal);
|
||||
}
|
||||
if (changeListener) {
|
||||
ctrl.bind('change', 'return', changeListener);
|
||||
}
|
||||
ctrl.bind('keydown', 'return', function () { ok.click(); });
|
||||
} else if (type === 'process') {
|
||||
ok.hide();
|
||||
}
|
||||
|
||||
box.show();
|
||||
|
||||
ok.click(function () {
|
||||
box.hide();
|
||||
const response = (type === 'prompt' || type === 'select') ? ctrl.val() : true;
|
||||
if (chkbx) {
|
||||
resolve({response, checked: chkbx.prop('checked')});
|
||||
return;
|
||||
}
|
||||
resolve(response);
|
||||
}).focus();
|
||||
|
||||
if (type === 'prompt' || type === 'select') {
|
||||
ctrl.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} msg Message to alert
|
||||
* @returns {jQueryPluginDBox.ResultPromise}
|
||||
*/
|
||||
$.alert = function (msg) {
|
||||
return dbox('alert', msg);
|
||||
};
|
||||
/**
|
||||
* @param {string} msg Message for which to ask confirmation
|
||||
* @returns {jQueryPluginDBox.ResultPromise}
|
||||
*/
|
||||
$.confirm = function (msg) {
|
||||
return dbox('confirm', msg);
|
||||
};
|
||||
/**
|
||||
* @param {string} msg Message to indicate upon cancelable indicator
|
||||
* @returns {jQueryPluginDBox.ResultPromise}
|
||||
*/
|
||||
$.process_cancel = function (msg) {
|
||||
return dbox('process', msg);
|
||||
};
|
||||
/**
|
||||
* @param {string} msg Message to accompany the prompt
|
||||
* @param {string} [defaultText=""] The default text to show for the prompt
|
||||
* @returns {jQueryPluginDBox.ResultPromise}
|
||||
*/
|
||||
$.prompt = function (msg, defaultText = '') {
|
||||
return dbox('prompt', msg, defaultText);
|
||||
};
|
||||
$.select = function (msg, opts, changeListener, txt, checkbox) {
|
||||
return dbox('select', msg, txt, opts, changeListener, checkbox);
|
||||
};
|
||||
return $;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
import * as hstry from './history.js';
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js';
|
||||
import jQueryPluginSVG from './jQuery.attr.js';
|
||||
import {NS} from '../common/namespaces.js';
|
||||
import {
|
||||
getVisibleElements, getStrokedBBoxDefaultVisible, findDefs,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @license MIT
|
||||
* @copyright 2011 Jeff Schiller
|
||||
*/
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute
|
||||
import {
|
||||
assignAttributes, cleanupElement, getElem, getRotationAngle, snapToGrid, walkTree,
|
||||
getBBox as utilsGetBBox, isNullish, preventClickDefault, setHref
|
||||
|
||||
79
src/svgcanvas/jQuery.attr.js
Normal file
79
src/svgcanvas/jQuery.attr.js
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* A jQuery module to work with SVG attributes.
|
||||
* @module jQueryAttr
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This fixes `$(...).attr()` to work as expected with SVG elements.
|
||||
* Does not currently use `*AttributeNS()` since we rarely need that.
|
||||
* Adds {@link external:jQuery.fn.attr}.
|
||||
* See {@link https://api.jquery.com/attr/} for basic documentation of `.attr()`.
|
||||
*
|
||||
* Additional functionality:
|
||||
* - When getting attributes, a string that's a number is returned as type number.
|
||||
* - If an array is supplied as the first parameter, multiple values are returned
|
||||
* as an object with values for each given attribute.
|
||||
* @function module:jQueryAttr.jQueryAttr
|
||||
* @param {external:jQuery} $ The jQuery object to which to add the plug-in
|
||||
* @returns {external:jQuery}
|
||||
*/
|
||||
export default function jQueryPluginSVG ($) {
|
||||
const proxied = $.fn.attr,
|
||||
svgns = 'http://www.w3.org/2000/svg';
|
||||
/**
|
||||
* @typedef {PlainObject<string, string|Float>} module:jQueryAttr.Attributes
|
||||
*/
|
||||
/**
|
||||
* @function external:jQuery.fn.attr
|
||||
* @param {string|string[]|PlainObject<string, string>} key
|
||||
* @param {string} value
|
||||
* @returns {external:jQuery|module:jQueryAttr.Attributes}
|
||||
*/
|
||||
$.fn.attr = function (key, value) {
|
||||
const len = this.length;
|
||||
if (!len) { return proxied.call(this, key, value); }
|
||||
for (let i = 0; i < len; ++i) {
|
||||
const elem = this[i];
|
||||
// set/get SVG attribute
|
||||
if (elem.namespaceURI === svgns) {
|
||||
// Setting attribute
|
||||
if (value !== undefined) {
|
||||
elem.setAttribute(key, value);
|
||||
} else if (Array.isArray(key)) {
|
||||
// Getting attributes from array
|
||||
const obj = {};
|
||||
let j = key.length;
|
||||
|
||||
while (j--) {
|
||||
const aname = key[j];
|
||||
let attr = elem.getAttribute(aname);
|
||||
// This returns a number when appropriate
|
||||
if (attr || attr === '0') {
|
||||
attr = isNaN(attr) ? attr : (attr - 0);
|
||||
}
|
||||
obj[aname] = attr;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
if (typeof key === 'object') {
|
||||
// Setting attributes from object
|
||||
for (const [name, val] of Object.entries(key)) {
|
||||
elem.setAttribute(name, val);
|
||||
}
|
||||
// Getting attribute
|
||||
} else {
|
||||
let attr = elem.getAttribute(key);
|
||||
if (attr || attr === '0') {
|
||||
attr = isNaN(attr) ? attr : (attr - 0);
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
} else {
|
||||
return proxied.call(this, key, value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
return $;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* globals jQuery */
|
||||
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import {
|
||||
getStrokedBBoxDefaultVisible
|
||||
} from './utilities.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import {NS} from '../common/namespaces.js';
|
||||
import {convertToNum} from '../common/units.js';
|
||||
import {isWebkit} from '../common/browser.js';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
|
||||
*/
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute
|
||||
import {NS} from '../common/namespaces.js';
|
||||
import * as hstry from './history.js';
|
||||
import * as pathModule from './path.js';
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
isNullish, getBBox as utilsGetBBox, getStrokedBBoxDefaultVisible
|
||||
} from './utilities.js';
|
||||
import {transformPoint, transformListToTransform, rectsIntersect} from './math.js';
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js';
|
||||
import jQueryPluginSVG from './jQuery.attr.js';
|
||||
import {
|
||||
getTransformList
|
||||
} from './svgtransformlist.js';
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import {jsPDF} from 'jspdf/dist/jspdf.es.min.js';
|
||||
import 'svg2pdf.js/dist/svg2pdf.es.js';
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js';
|
||||
import jQueryPluginSVG from './jQuery.attr.js';
|
||||
import * as hstry from './history.js';
|
||||
import {
|
||||
text2xml, cleanupElement, findDefs, getHref, preventClickDefault,
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
import {Canvg as canvg} from 'canvg';
|
||||
import 'pathseg';
|
||||
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import jQueryPluginDBox from './dbox.js';
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
|
||||
import * as pathModule from './path.js';
|
||||
import * as hstry from './history.js';
|
||||
@@ -117,7 +116,7 @@ import {
|
||||
init as clearInit
|
||||
} from './clear.js';
|
||||
|
||||
let $ = jQueryPluginSVG(jQuery);
|
||||
const $ = jQueryPluginSVG(jQuery);
|
||||
const {
|
||||
MoveElementCommand, InsertElementCommand, RemoveElementCommand,
|
||||
ChangeElementCommand, BatchCommand
|
||||
@@ -1741,7 +1740,6 @@ class SvgCanvas {
|
||||
*/
|
||||
this.setUiStrings = function (strs) {
|
||||
Object.assign(uiStrings, strs.notification);
|
||||
$ = jQueryPluginDBox($, strs.common);
|
||||
pathModule.setUiStrings(strs);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
|
||||
*/
|
||||
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js';
|
||||
import jQueryPluginSVG from './jQuery.attr.js';
|
||||
import {NS} from '../common/namespaces.js';
|
||||
import {
|
||||
transformPoint, getMatrix
|
||||
@@ -263,15 +263,6 @@ export const textActionsMethod = (function () {
|
||||
return out;
|
||||
}
|
||||
|
||||
/*
|
||||
// Not currently in use
|
||||
function hideCursor () {
|
||||
if (cursor) {
|
||||
cursor.setAttribute('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Event} evt
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @copyright 2010 Alexis Deveria, 2010 Jeff Schiller
|
||||
*/
|
||||
|
||||
import jQueryPluginSVG from '../common/jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import jQueryPluginSVG from './jQuery.attr.js'; // Needed for SVG attribute setting and array form with `attr`
|
||||
import {NS} from '../common/namespaces.js';
|
||||
import {getTransformList} from './svgtransformlist.js';
|
||||
import {setUnitAttr, getTypeMap} from '../common/units.js';
|
||||
|
||||
Reference in New Issue
Block a user