move handlers

master
JFH 2021-03-14 22:01:12 +01:00
parent c19c53565d
commit 89b11f4571
2 changed files with 88 additions and 138 deletions

View File

@ -18,8 +18,7 @@
*/
import './touch.js';
import {isChrome, isMac, isTouch} from '../common/browser.js';
import {convertUnit, isValidUnit} from '../common/units.js';
import {isMac} from '../common/browser.js';
import SvgCanvas from '../svgcanvas/svgcanvas.js';
import ConfigObj from './ConfigObj.js';
@ -38,8 +37,6 @@ import MainMenu from './MainMenu.js';
const {$id, $qa, isNullish, encode64, decode64, blankPageObjectURL} = SvgCanvas;
// JFH hotkey is used for text input.
const homePage = 'https://github.com/SVG-Edit/svgedit';
/**
*
*/
@ -777,76 +774,6 @@ class Editor extends EditorStartup {
$(elem).empty().append(icon);
}
/**
* @param {string} elemSel
* @param {string} listSel
* @param {external:jQuery.Function} callback
* @param {PlainObject} opts
* @param {boolean} opts.dropUp
* @param {boolean} opts.seticon
* @param {boolean} opts.multiclick
* @todo Combine this with `addDropDown` or find other way to optimize.
* @returns {void}
*/
addAltDropDown (elemSel, listSel, callback, opts) {
const self = this;
const button = $(elemSel);
const {dropUp} = opts;
const list = $(listSel);
if (dropUp) {
$(elemSel).addClass('dropup');
}
list.find('li').bind('mouseup', function (...args) {
if (opts.seticon) {
self.setIcon('#cur_' + button[0].id, $(this).children());
$(this).addClass('current').siblings().removeClass('current');
}
callback.apply(this, ...args);
});
let onButton = false;
$(window).mouseup(function (evt) {
if (!onButton) {
button.removeClass('down');
list.hide();
list.css({top: 0, left: 0});
}
onButton = false;
});
// const height = list.height(); // Currently unused
button.bind('mousedown', function () {
const off = button.offset();
if (dropUp) {
off.top -= list.height();
off.left += 8;
} else {
off.top += button.height();
}
list.offset(off);
if (!button.hasClass('down')) {
list.show();
onButton = true;
} else {
// CSS position must be reset for Webkit
list.hide();
list.css({top: 0, left: 0});
}
button.toggleClass('down');
}).hover(function () {
onButton = true;
}).mouseout(function () {
onButton = false;
});
if (opts.multiclick) {
list.mousedown(function () {
onButton = true;
});
}
}
/**
* @param {external:Window} win
* @param {module:svgcanvas.SvgCanvas#event:extension_added} ext
@ -1027,56 +954,6 @@ class Editor extends EditorStartup {
this.leftPanel.clickSelect();
}
/**
*
* @returns {void}
*/
hideDocProperties () {
const $imgDialog = document.getElementById('se-img-prop');
$imgDialog.setAttribute('dialog', 'close');
$imgDialog.setAttribute('save', this.configObj.pref('img_save'));
this.docprops = false;
}
/**
*
* @returns {void}
*/
hidePreferences () {
const $editDialog = document.getElementById('se-edit-prefs');
$editDialog.setAttribute('dialog', 'close');
this.configObj.preferences = false;
}
/**
* @param {Event} e
* @returns {boolean} Whether there were problems saving the document properties
*/
saveDocProperties (e) {
// set title
const {title, w, h, save} = e.detail;
// set document title
this.svgCanvas.setDocumentTitle(title);
if (w !== 'fit' && !isValidUnit('width', w)) {
seAlert(this.uiStrings.notification.invalidAttrValGiven);
return false;
}
if (h !== 'fit' && !isValidUnit('height', h)) {
seAlert(this.uiStrings.notification.invalidAttrValGiven);
return false;
}
if (!this.svgCanvas.setResolution(w, h)) {
seAlert(this.uiStrings.notification.noContentToFitTo);
return false;
}
// Set image save option
this.configObj.pref('img_save', save);
this.updateCanvas();
this.hideDocProperties();
return true;
}
/**
* @param {Event} e
* @returns {void} Resolves to `undefined`

View File

@ -1,6 +1,10 @@
/* globals $ */
import SvgCanvas from "../svgcanvas/svgcanvas.js";
import {convertUnit, isValidUnit} from '../common/units.js';
import {isChrome} from '../common/browser.js';
const { $id } = SvgCanvas;
const homePage = 'https://github.com/SVG-Edit/svgedit';
/**
*
@ -33,19 +37,80 @@ class MainMenu {
this.editor.svgCanvas.runExtensions("onNewDocument");
}
/**
* Save user preferences based on current values in the UI.
* @param {Event} e
* @function module:SVGthis.savePreferences
* @returns {Promise<void>}
*/
async savePreferences (e) {
const {lang, bgcolor, bgurl, gridsnappingon, gridsnappingstep, gridcolor, showrulers, baseunit} = e.detail;
*
* @returns {void}
*/
hideDocProperties() {
const $imgDialog = document.getElementById("se-img-prop");
$imgDialog.setAttribute("dialog", "close");
$imgDialog.setAttribute("save", this.editor.configObj.pref("img_save"));
this.editor.docprops = false;
}
/**
*
* @returns {void}
*/
hidePreferences() {
const $editDialog = document.getElementById("se-edit-prefs");
$editDialog.setAttribute("dialog", "close");
this.editor.configObj.preferences = false;
}
/**
* @param {Event} e
* @returns {boolean} Whether there were problems saving the document properties
*/
saveDocProperties(e) {
// set title
const { title, w, h, save } = e.detail;
// set document title
this.editor.svgCanvas.setDocumentTitle(title);
if (w !== "fit" && !isValidUnit("width", w)) {
seAlert(this.editor.uiStrings.notification.invalidAttrValGiven);
return false;
}
if (h !== "fit" && !isValidUnit("height", h)) {
seAlert(this.editor.uiStrings.notification.invalidAttrValGiven);
return false;
}
if (!this.editor.svgCanvas.setResolution(w, h)) {
seAlert(this.editor.uiStrings.notification.noContentToFitTo);
return false;
}
// Set image save option
this.editor.configObj.pref("img_save", save);
this.editor.updateCanvas();
this.editor.hideDocProperties();
return true;
}
/**
* Save user preferences based on current values in the UI.
* @param {Event} e
* @function module:SVGthis.savePreferences
* @returns {Promise<void>}
*/
async savePreferences(e) {
const {
lang,
bgcolor,
bgurl,
gridsnappingon,
gridsnappingstep,
gridcolor,
showrulers,
baseunit
} = e.detail;
// Set background
this.editor.setBackground(bgcolor, bgurl);
// set language
if (lang && lang !== this.configObj.pref('lang')) {
const {langParam, langData} = await this.editor.putLocale(lang, this.goodLangs);
if (lang && lang !== this.editor.configObj.pref("lang")) {
const { langParam, langData } = await this.editor.putLocale(
lang,
this.editor.goodLangs
);
await this.editor.svgCanvassetLang(langParam, langData);
}
@ -55,10 +120,12 @@ class MainMenu {
this.editor.configObj.curConfig.gridColor = gridcolor;
this.editor.configObj.curConfig.showRulers = showrulers;
$('#rulers').toggle(this.editor.configObj.curConfig.showRulers);
if (this.editor.configObj.curConfig.showRulers) { this.editor.rulers.updateRulers(); }
$("#rulers").toggle(this.editor.configObj.curConfig.showRulers);
if (this.editor.configObj.curConfig.showRulers) {
this.editor.rulers.updateRulers();
}
this.editor.configObj.curConfig.baseUnit = baseunit;
this.editor.svgCanvas.setConfig(this.configObj.curConfig);
this.editor.svgCanvas.setConfig(this.editor.configObj.curConfig);
this.editor.updateCanvas();
this.editor.hidePreferences();
}
@ -120,7 +187,10 @@ class MainMenu {
}
this.editor.loadingURL = popURL;
}
this.editor.exportWindow = window.open(popURL, this.editor.exportWindowName);
this.editor.exportWindow = window.open(
popURL,
this.editor.exportWindowName
);
};
const chrome = isChrome();
if (imgType === "PDF") {
@ -210,7 +280,10 @@ class MainMenu {
"gridsnappingstep",
this.editor.configObj.curConfig.snappingStep
);
$editDialog.setAttribute("gridcolor", this.editor.configObj.curConfig.gridColor);
$editDialog.setAttribute(
"gridcolor",
this.editor.configObj.curConfig.gridColor
);
$editDialog.setAttribute("canvasbg", canvasBg);
$editDialog.setAttribute("dialog", "open");
}