From 545e585ccc36fed10796e7d113b7b3c00adf51f3 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Sat, 15 Oct 2022 11:04:22 +0300 Subject: [PATCH] [DE] load icon's svg dynamically --- apps/common/main/lib/util/htmlutils.js | 35 +++++++++++++++---- apps/common/main/lib/util/utils.js | 6 ++++ .../main/app/controller/Toolbar.js | 2 ++ apps/documenteditor/main/index.html | 1 + .../main/resources/img/iconssmall@2.5x.svg | 14 ++++++++ 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 apps/documenteditor/main/resources/img/iconssmall@2.5x.svg diff --git a/apps/common/main/lib/util/htmlutils.js b/apps/common/main/lib/util/htmlutils.js index d75a54d0a..af67055c6 100644 --- a/apps/common/main/lib/util/htmlutils.js +++ b/apps/common/main/lib/util/htmlutils.js @@ -16,13 +16,34 @@ function checkScaling() { } } - if ( !window.matchMedia("screen and (-webkit-device-pixel-ratio: 1.5)," + - "screen and (-webkit-device-pixel-ratio: 1)," + - "screen and (-webkit-device-pixel-ratio: 2)").matches ) - { - // don't add zoom for mobile devices - // if (!(/android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent || navigator.vendor || window.opera))) - // document.getElementsByTagName('html')[0].setAttribute('style', 'zoom: ' + (1 / window.devicePixelRatio) + ';'); + matches = { + 'pixel-ratio__2_5': `screen and (-webkit-min-device-pixel-ratio: 2.5), screen and (min-resolution: 2.5dppx)`, + }; + for (let c in matches) { + if ( window.matchMedia(matches[c]).matches ) { + document.body.classList.add(c); + Common.Utils.injectSvgIcons(); + break; + } + } +} + +window.Common = { + Utils: { + injectSvgIcons: function () { + const el = document.querySelector('div.inlined-svg'); + if (!el || !el.innerHTML.firstChild) { + fetch('./resources/img/iconssmall@2.5x.svg') + .then(r => { + if (r.ok) return r.text(); + else {/* error */ + } + }).then(text => { + const el = document.querySelector('div.inlined-svg') + el.innerHTML = text; + }).catch(console.error.bind(console)); + } + } } } diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index bab0f3cff..109b223e6 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -144,6 +144,8 @@ var utils = new(function() { "screen and (min-resolution: 1.75dppx) and (max-resolution: 1.99dppx)"; var str_mq_200 = "screen and (-webkit-min-device-pixel-ratio: 2), " + "screen and (min-resolution: 2dppx), screen and (min-resolution: 192dpi)"; + const str_mq_250 = "screen and (-webkit-min-device-pixel-ratio: 2.5), " + + "screen and (min-resolution: 2.5dppx), screen and (min-resolution: 240dpi)"; if ( window.matchMedia(str_mq_125).matches ) { scale.devicePixelRatio = 1.5; @@ -157,6 +159,10 @@ var utils = new(function() { if ( window.matchMedia(str_mq_200).matches ) scale.devicePixelRatio = 2; else scale.devicePixelRatio = 1; + + if ( window.matchMedia(str_mq_250).matches ) { + scale.devicePixelRatio = 2.5; + } } var $root = $(document.body); diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 83849e598..900e7d99a 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -3193,6 +3193,8 @@ define([ this.toolbar.createDelayedElements(); this.attachUIEvents(this.toolbar); this.onChangeProtectDocument(); + + Common.Utils.injectSvgIcons(); }, onAppShowed: function (config) { diff --git a/apps/documenteditor/main/index.html b/apps/documenteditor/main/index.html index c5d3b2cc3..35fcc3e0e 100644 --- a/apps/documenteditor/main/index.html +++ b/apps/documenteditor/main/index.html @@ -331,6 +331,7 @@ +