Skip to content

Commit

Permalink
Workaround scroll issue
Browse files Browse the repository at this point in the history
  • Loading branch information
javalikescript committed Dec 21, 2024
1 parent ad26132 commit 87ff750
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions extensions/web-base/www/app/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@
* Setup AMD
************************************************************/
require(['_AMD'], function(_AMD) {
var extension = function(path) {
var slashIndex = path.lastIndexOf('/');
var index = path.lastIndexOf('.');
return index <= slashIndex ? '' : path.substring(index + 1);
};
_AMD.setLogFunction(console.warn);
_AMD.setLoadModuleFunction(function(pathname, callback, sync, prefix, suffix) {
var ext = extension(pathname);
var raw = pathname.charAt(pathname.length - 1) === '!';
if (raw) {
pathname = pathname.substring(0, pathname.length - 1)
}
var slashIndex = pathname.lastIndexOf('/');
var name = slashIndex < 0 ? pathname : pathname.substring(slashIndex + 1);
var dotIndex = name.lastIndexOf('.');
var ext = dotIndex < 0 ? '' : name.substring(dotIndex + 1);
fetch(pathname).then(function(response) {
//console.log('module "' + pathname + '" retrieved with extension "' + ext + '"');
if (ext === 'json') {
return response.json();
} else {
return response.text();
}
return ext === 'json' && !raw ? response.json() : response.text();
}).then(function(content) {
if (ext !== 'js') {
if (raw || ext !== 'js') {
callback(content);
} else {
var src = prefix + content + suffix;
try {
//var m = window.eval(src);
var m = Function('"use strict";return ' + src)();
//console.log('module "' + pathname + '" evaluated', m, src);
callback(m);
Expand Down Expand Up @@ -59,6 +56,13 @@ window.addEventListener('hashchange', function() {
app.navigateTo(getLocationPath());
});

// avoid horizontal scroll which could happen on a tab-focused element out of the view
window.addEventListener('scroll', function () {
if (window.scrollX !== 0) {
window.scroll(0, window.scrollY);
}
});

/************************************************************
* Load web base configuration and addons
************************************************************/
Expand Down

0 comments on commit 87ff750

Please sign in to comment.