From 37424278d148c7a4a33cd7194f76545e00d1dce3 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 5 Jan 2020 08:53:41 +0800 Subject: [PATCH] - BREAKING CHANGE: Remove `$.pref` in favor of new `svgEditor.pref` (avoiding polluting jQuery). (Might be moved to own module in future.) - BREAKING CHANGE: `putLocale` (a function called automatically by `svg-editor.js`) no longer checks `pref`. Should not impact average consumers. `putLocale` now also logs lang and checks `goodLangs` even if an explicit lang param is provided --- CHANGES.md | 8 +++- editor/extensions/ext-storage.js | 6 +-- editor/locale/locale.js | 29 +++++--------- editor/svg-editor.js | 66 ++++++++++++++++---------------- svgedit-config-es.js | 52 +++++++++++++++++-------- 5 files changed, 88 insertions(+), 73 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e78d1ff6..7dab65fb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # SVG-Edit CHANGES -## ? +## 6.0.0 (unreleased) - License: Relicense ext-mathjax from Apache-2.0 to MIT per @@ -8,6 +8,12 @@ "(MIT OR GPL-2.0-or-later)" per subsequent text - License: Reorder license listing in `jquery.contextMenu.js` so that more permissive is noticeable first +- BREAKING CHANGE: Remove `$.pref` in favor of new `svgEditor.pref` + (avoiding polluting jQuery). (Might be moved to own module in + future.) +- BREAKING CHANGE: `putLocale` (a function called automatically by + `svg-editor.js`) no longer checks `pref`. Should not impact + average consumers. - Fix: main menu style and text #371 - Fix (Accessibility): Avoid duplicate IDs - Fix (openclipart browser): Redirect on lacking browser support diff --git a/editor/extensions/ext-storage.js b/editor/extensions/ext-storage.js index ce4f318c..fbc01008 100644 --- a/editor/extensions/ext-storage.js +++ b/editor/extensions/ext-storage.js @@ -14,9 +14,9 @@ * @license MIT * * @copyright 2010 Brett Zamir - * @todo Revisit on whether to use $.pref over directly setting curConfig in all - * extensions for a more public API (not only for extPath and imagePath, - * but other currently used config in the extensions) + * @todo Revisit on whether to use `svgEditor.pref` over directly setting + * `curConfig` in all extensions for a more public API (not only for `extPath` + * and `imagePath`, but other currently used config in the extensions) * @todo We might provide control of storage settings through the UI besides the * initial (or URL-forced) dialog. * */ diff --git a/editor/locale/locale.js b/editor/locale/locale.js index 3ccbef13..adc1ef17 100644 --- a/editor/locale/locale.js +++ b/editor/locale/locale.js @@ -374,28 +374,17 @@ export const readLang = async function (langData) { export const putLocale = async function (givenParam, goodLangs, conf) { if (givenParam) { langParam = givenParam; - } else { - langParam = $.pref('lang'); - if (!langParam) { - if (navigator.userLanguage) { // Explorer - langParam = navigator.userLanguage; - } else if (navigator.language) { // FF, Opera, ... - langParam = navigator.language; - } - } + } else if (navigator.userLanguage) { // Explorer + langParam = navigator.userLanguage; + } else if (navigator.language) { // FF, Opera, ... + langParam = navigator.language; + } - console.log('Lang: ' + langParam); // eslint-disable-line no-console + console.log('Lang: ' + langParam); // eslint-disable-line no-console - // Set to English if language is not in list of good langs - if (!goodLangs.includes(langParam) && langParam !== 'test') { - langParam = 'en'; - } - - // don't bother on first run if language is English - // The following line prevents setLang from running - // extensions which depend on updated uiStrings, - // so commenting it out. - // if (langParam.startsWith('en')) {return;} + // Set to English if language is not in list of good langs + if (!goodLangs.includes(langParam) && langParam !== 'test') { + langParam = 'en'; } const url = conf.langPath + 'lang.' + langParam + '.js'; diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 813319e9..ee111dfb 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -392,14 +392,14 @@ function getImportLocale ({defaultLang, defaultName}) { * @param {boolean} [mayBeEmpty] If value may be falsey. * @returns {string|void} If val is missing or falsey and `mayBeEmpty` is not set, the * value of the previously stored preference will be returned. -* @todo Can we change setting on the jQuery namespace (onto editor) to avoid conflicts? * @todo Review whether any remaining existing direct references to -* getting `curPrefs` can be changed to use `$.pref()` getting to ensure -* `defaultPrefs` fallback (also for sake of `allowInitialUserOverride`); specifically, `bkgd_color` could be changed so that -* the pref dialog has a button to auto-calculate background, but otherwise uses `$.pref()` to be able to get default prefs -* or overridable settings +* getting `curPrefs` can be changed to use `svgEditor.pref()` getting to ensure +* `defaultPrefs` fallback (also for sake of `allowInitialUserOverride`); +* specifically, `bkgd_color` could be changed so that the pref dialog has a +* button to auto-calculate background, but otherwise uses `svgEditor.pref()` to +* be able to get default prefs or overridable settings */ -$.pref = function (key, val, mayBeEmpty) { +editor.pref = function (key, val, mayBeEmpty) { if (mayBeEmpty || val) { curPrefs[key] = val; /** @@ -526,7 +526,7 @@ editor.setConfig = function (opts, cfgCfg) { if (cfgCfg.allowInitialUserOverride === true) { defaultPrefs[key] = val; } else { - $.pref(key, val); + editor.pref(key, val); } } else if (['extensions', 'stylesheets', 'allowedOrigins'].includes(key)) { if (cfgCfg.overwrite === false && @@ -816,7 +816,9 @@ editor.init = function () { */ const extAndLocaleFunc = async function () { // const lang = ('lang' in curPrefs) ? curPrefs.lang : null; - const {langParam, langData} = await editor.putLocale(null, goodLangs, curConfig); + const {langParam, langData} = await editor.putLocale( + editor.pref('lang'), goodLangs, curConfig + ); await setLang(langParam, langData); const {ok, cancel} = uiStrings.common; @@ -1012,7 +1014,7 @@ editor.init = function () { hiddenPs.css('visibility', 'visible').hide(); // return; - $.pref('iconsize', size); + editor.pref('iconsize', size); $('#iconsize').val(size); // Change icon size @@ -1397,7 +1399,7 @@ editor.init = function () { minHeight = tleft.offset().top + tleft.outerHeight(); } - const size = $.pref('iconsize'); + const size = editor.pref('iconsize'); editor.setIconSize(size || ($(window).height() < minHeight ? 's' : 'm')); // Look for any missing flyout icons from plugins @@ -1724,7 +1726,7 @@ editor.init = function () { // Alert will only appear the first time saved OR the // first time the bug is encountered - let done = $.pref('save_notice_done'); + let done = editor.pref('save_notice_done'); if (done !== 'all') { let note = uiStrings.notification.saveFromBrowser.replace('%s', 'SVG'); @@ -1733,13 +1735,13 @@ editor.init = function () { if (svg.includes('