Skip to content

Commit

Permalink
webview: Load JS files from assets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
borisyankov committed Jun 18, 2018
1 parent ae2bc6a commit a7e74f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/webview/html/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type InitOptionsType = {
};

export default (content: string, theme: ThemeType, initOptions: InitOptionsType) => template`
$!${script(initOptions.anchor)}
$!${css(theme, initOptions.highlightUnreadMessages)}
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<body style="overflow-x: hidden;">
$!${htmlBody(content, initOptions.showMessagePlaceholders)}
</body>
$!${script(initOptions.anchor)}
`;
18 changes: 7 additions & 11 deletions src/webview/js/script.js
Original file line number Diff line number Diff line change
@@ -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 => `
<script src="${getWebviewResource('smooth-scroll.js')}"></script>
<script src="${getWebviewResource('matches-polyfill.js')}"></script>
<script src="${getWebviewResource('zulip.js')}"></script>
<script>
window.__forceSmoothScrollPolyfill__ = true;
${smoothScroll}
${matchesPolyfill}
window.enableWebViewErrorDisplay = ${config.enableWebViewErrorDisplay.toString()};
document.addEventListener('DOMContentLoaded', function() {
${js}
scrollToAnchor(${anchor});
scrollEventsDisabled = false;
sendScrollMessageIfListShort();
});
scrollToAnchor(${anchor});
scrollEventsDisabled = false;
sendScrollMessageIfListShort();
</script>
`;

0 comments on commit a7e74f0

Please sign in to comment.