From a4e966b25ac6816ba2a39f4d18753633d597cced Mon Sep 17 00:00:00 2001 From: Boris Yankov Date: Mon, 18 Jun 2018 05:25:11 +0300 Subject: [PATCH] webview: Load JS files from assets Instead of loading imported-strings-as-js we just refer to the asset files of the device. Also, move the `scripts` code to the bottom of the page. This was initially moved to the top so the reported error code-lines are more predictable (the different html was messing up the count). Now we don't need that, so simplify. --- src/webview/html/html.js | 2 +- src/webview/js/matchesPolyfill.js | 19 ------------------- src/webview/js/script.js | 18 +++++++----------- src/webview/js/smoothScroll.min.js | 4 ---- 4 files changed, 8 insertions(+), 35 deletions(-) delete mode 100644 src/webview/js/matchesPolyfill.js delete mode 100644 src/webview/js/smoothScroll.min.js diff --git a/src/webview/html/html.js b/src/webview/html/html.js index bc14f9d97ba..1fd61c76843 100644 --- a/src/webview/html/html.js +++ b/src/webview/html/html.js @@ -12,11 +12,11 @@ type InitOptionsType = { }; export default (content: string, theme: ThemeType, initOptions: InitOptionsType) => template` -$!${script(initOptions.anchor)} $!${css(theme, initOptions.highlightUnreadMessages)} $!${htmlBody(content, initOptions.showMessagePlaceholders)} +$!${script(initOptions.anchor)} `; diff --git a/src/webview/js/matchesPolyfill.js b/src/webview/js/matchesPolyfill.js deleted file mode 100644 index 93a595aad7d..00000000000 --- a/src/webview/js/matchesPolyfill.js +++ /dev/null @@ -1,19 +0,0 @@ -/* eslint-disable */ -// Official MDN polyfill for Element.matches -// Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/matches -export default ` -if (!Element.prototype.matches) { - Element.prototype.matches = - Element.prototype.matchesSelector || - Element.prototype.mozMatchesSelector || - Element.prototype.msMatchesSelector || - Element.prototype.oMatchesSelector || - Element.prototype.webkitMatchesSelector || - function(s) { - var matches = (this.document || this.ownerDocument).querySelectorAll(s), - i = matches.length; - while (--i >= 0 && matches.item(i) !== this) {} - return i > -1; - }; -} -`; diff --git a/src/webview/js/script.js b/src/webview/js/script.js index f6c48b8acaa..eed4dd2e536 100644 --- a/src/webview/js/script.js +++ b/src/webview/js/script.js @@ -1,20 +1,16 @@ /* @flow */ -import smoothScroll from './smoothScroll.min'; -import matchesPolyfill from './matchesPolyfill'; -import js from './generatedEs3'; import config from '../../config'; +import { getWebviewResource } from '../webviewHelpers'; export default (anchor: number): string => ` + + + `; diff --git a/src/webview/js/smoothScroll.min.js b/src/webview/js/smoothScroll.min.js deleted file mode 100644 index 0c0d4f6d0da..00000000000 --- a/src/webview/js/smoothScroll.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-disable */ -export default ` -!function(){"use strict";function o(o){var t=["MSIE ","Trident/","Edge/"];return new RegExp(t.join("|")).test(o)}function t(){function t(o,t){this.scrollLeft=o,this.scrollTop=t}function r(o){return.5*(1-Math.cos(Math.PI*o))}function i(o){if(null===o||"object"!=typeof o||void 0===o.behavior||"auto"===o.behavior||"instant"===o.behavior)return!0;if("object"==typeof o&&"smooth"===o.behavior)return!1;throw new TypeError("behavior member of ScrollOptions "+o.behavior+" is not a valid value for enumeration ScrollBehavior.")}function s(o,t){return"Y"===t?o.clientHeight+h1?1:s),e=o.startX+(o.x-o.startX)*t,i=o.startY+(o.y-o.startY)*t,o.method.call(o.scrollable,e,i),e===o.x&&i===o.y||l.requestAnimationFrame(a.bind(l,o))}function p(o,r,i){var s,c,n,f,p=y();o===e.body?(s=l,c=l.scrollX||l.pageXOffset,n=l.scrollY||l.pageYOffset,f=u.scroll):(s=o,c=o.scrollLeft,n=o.scrollTop,f=t),a({scrollable:s,method:f,startTime:p,startX:c,startY:n,x:r,y:i})}if(!("scrollBehavior"in e.documentElement.style&&!0!==l.__forceSmoothScrollPolyfill__)){var d=l.HTMLElement||l.Element,v=468,h=o(l.navigator.userAgent)?1:0,u={scroll:l.scroll||l.scrollTo,scrollBy:l.scrollBy,elementScroll:d.prototype.scroll||t,scrollIntoView:d.prototype.scrollIntoView},y=l.performance&&l.performance.now?l.performance.now.bind(l.performance):Date.now;l.scroll=l.scrollTo=function(){void 0!==arguments[0]&&(!0!==i(arguments[0])?p.call(l,e.body,void 0!==arguments[0].left?~~arguments[0].left:l.scrollX||l.pageXOffset,void 0!==arguments[0].top?~~arguments[0].top:l.scrollY||l.pageYOffset):u.scroll.call(l,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:l.scrollX||l.pageXOffset,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:l.scrollY||l.pageYOffset))},l.scrollBy=function(){void 0!==arguments[0]&&(i(arguments[0])?u.scrollBy.call(l,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:0,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:0):p.call(l,e.body,~~arguments[0].left+(l.scrollX||l.pageXOffset),~~arguments[0].top+(l.scrollY||l.pageYOffset)))},d.prototype.scroll=d.prototype.scrollTo=function(){if(void 0!==arguments[0])if(!0!==i(arguments[0])){var o=arguments[0].left,t=arguments[0].top;p.call(this,this,void 0===o?this.scrollLeft:~~o,void 0===t?this.scrollTop:~~t)}else{if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value couldn't be converted");u.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left:"object"!=typeof arguments[0]?~~arguments[0]:this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top:void 0!==arguments[1]?~~arguments[1]:this.scrollTop)}},d.prototype.scrollBy=function(){void 0!==arguments[0]&&(!0!==i(arguments[0])?this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior}):u.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop))},d.prototype.scrollIntoView=function(){if(!0!==i(arguments[0])){var o=f(this),t=o.getBoundingClientRect(),r=this.getBoundingClientRect();o!==e.body?(p.call(this,o,o.scrollLeft+r.left-t.left,o.scrollTop+r.top-t.top),"fixed"!==l.getComputedStyle(o).position&&l.scrollBy({left:t.left,top:t.top,behavior:"smooth"})):l.scrollBy({left:r.left,top:r.top,behavior:"smooth"})}else u.scrollIntoView.call(this,void 0===arguments[0]||arguments[0])}}}var l=window,e=document;"object"==typeof exports?module.exports={polyfill:t}:t()}(); -`;