Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit 6ca45c6

Browse files
committed
hopefully improve UI for mobile devices (#828)
1 parent 06d7612 commit 6ca45c6

File tree

3 files changed

+76
-40
lines changed

3 files changed

+76
-40
lines changed

src/css/popup.css

+16-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ body[dir="rtl"] #gotoDashboard > span:last-of-type {
4949

5050
.paneHead {
5151
background-color: white;
52-
left:0;
52+
left: 0;
5353
padding: 0;
5454
position: fixed;
5555
right: 0;
@@ -621,3 +621,18 @@ body.colorblind .rw .matCell.t2 #blacklist:hover {
621621
#domainOnly:hover {
622622
opacity: 1;
623623
}
624+
625+
/* Mobile-friendly rules */
626+
627+
body.hConstrained {
628+
overflow-x: auto;
629+
}
630+
body.hConstrained .paneHead {
631+
left: auto;
632+
position: absolute;
633+
right: auto;
634+
width: 100%;
635+
}
636+
body[data-touch="true"] .matCell {
637+
line-height: 200%;
638+
}

src/js/popup.js

+59-38
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,66 @@
3232
/******************************************************************************/
3333
/******************************************************************************/
3434

35-
var paneContentPaddingTop;
36-
try {
37-
paneContentPaddingTop = localStorage.getItem('paneContentPaddingTop');
38-
} catch(ex) {
39-
}
35+
// Stuff which is good to do very early so as to avoid visual glitches.
4036

41-
if ( typeof paneContentPaddingTop === 'string' ) {
42-
document.querySelector('.paneContent').style.setProperty(
43-
'padding-top',
44-
paneContentPaddingTop
45-
);
46-
}
37+
(function() {
38+
var paneContentPaddingTop,
39+
touchDevice;
40+
try {
41+
paneContentPaddingTop = localStorage.getItem('paneContentPaddingTop');
42+
touchDevice = localStorage.getItem('touchDevice');
43+
} catch(ex) {
44+
}
45+
46+
if ( typeof paneContentPaddingTop === 'string' ) {
47+
document.querySelector('.paneContent').style.setProperty(
48+
'padding-top',
49+
paneContentPaddingTop
50+
);
51+
}
52+
if ( touchDevice === 'true' ) {
53+
document.body.setAttribute('data-touch', 'true');
54+
} else {
55+
document.addEventListener('touchstart', function onTouched(ev) {
56+
document.removeEventListener(ev.type, onTouched);
57+
document.body.setAttribute('data-touch', 'true');
58+
try {
59+
localStorage.setItem('touchDevice', 'true');
60+
} catch(ex) {
61+
}
62+
resizePopup();
63+
});
64+
}
65+
})();
66+
67+
var resizePopup = (function() {
68+
var timer;
69+
var fix = function() {
70+
timer = undefined;
71+
var doc = document;
72+
// Manually adjust the position of the main matrix according to the
73+
// height of the toolbar/matrix header.
74+
var paddingTop = (doc.querySelector('.paneHead').clientHeight + 2) + 'px',
75+
paneContent = doc.querySelector('.paneContent');
76+
if ( paddingTop !== paneContent.style.paddingTop ) {
77+
paneContent.style.setProperty('padding-top', paddingTop);
78+
try {
79+
localStorage.setItem('paneContentPaddingTop', paddingTop);
80+
} catch(ex) {
81+
}
82+
}
83+
document.body.classList.toggle(
84+
'hConstrained',
85+
window.innerWidth < document.body.clientWidth
86+
);
87+
};
88+
return function() {
89+
if ( timer !== undefined ) {
90+
clearTimeout(timer);
91+
}
92+
timer = vAPI.setTimeout(fix, 97);
93+
};
94+
})();
4795

4896
/******************************************************************************/
4997
/******************************************************************************/
@@ -1303,33 +1351,6 @@ var onMatrixSnapshotReady = function(response) {
13031351

13041352
/******************************************************************************/
13051353

1306-
var resizePopup = (function() {
1307-
var timer;
1308-
var fix = function() {
1309-
timer = undefined;
1310-
var doc = document;
1311-
// Manually adjust the position of the main matrix according to the
1312-
// height of the toolbar/matrix header.
1313-
var paddingTop = (doc.querySelector('.paneHead').clientHeight + 2) + 'px';
1314-
doc.querySelector('.paneContent').style.setProperty(
1315-
'padding-top',
1316-
paddingTop
1317-
);
1318-
try {
1319-
localStorage.setItem('paneContentPaddingTop', paddingTop);
1320-
} catch(ex) {
1321-
}
1322-
};
1323-
return function() {
1324-
if ( timer !== undefined ) {
1325-
clearTimeout(timer);
1326-
}
1327-
timer = vAPI.setTimeout(fix, 97);
1328-
};
1329-
})();
1330-
1331-
/******************************************************************************/
1332-
13331354
var matrixSnapshotPoller = (function() {
13341355
var timer = null;
13351356

src/popup.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6-
<meta name="viewport" content="width=device-width">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<link rel="stylesheet" href="css/common.css" type="text/css">
88
<link rel="stylesheet" href="css/popup.css" type="text/css">
99
<title>uMatrix panel</title>

0 commit comments

Comments
 (0)