Skip to content

Commit

Permalink
feature: css: --is-mobile: add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Nov 6, 2024
1 parent 06cf0ee commit a733d81
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
9 changes: 1 addition & 8 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,8 @@ function CloudCmdProto(DOM) {
this.prefixSocket = '';
this.prefixURL = '';

const bodyStyle = getComputedStyle(document.body);

this.MIN_ONE_PANEL_WIDTH = bodyStyle.getPropertyValue('--min-one-panel-width');
this.MOBILE_ONE_PANEL_WIDTH = bodyStyle.getPropertyValue('--mobile-max-width');

this.MIN_ONE_PANEL_WIDTH = DOM.getCSSVar('min-one-panel-width');
this.HOST = location.origin || location.protocol + '//' + location.host;

this.TITLE = 'Cloud Commander';

this.sort = {
left: 'name',
right: 'name',
Expand Down
5 changes: 5 additions & 0 deletions client/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ module.exports.getPanelPosition = (panel) => {
return panel.dataset.name.replace('js-', '');
};

module.exports.getCSSVar = (name, {body = document.body} = {}) => {
const bodyStyle = getComputedStyle(body);
return bodyStyle.getPropertyValue(`--${name}`);
};

/** function getting panel active, or passive
* @param options = {active: true}
*/
Expand Down
30 changes: 30 additions & 0 deletions client/dom/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('css-modules-require-hook/preset');

const {test, stub} = require('supertape');
const mockRequire = require('mock-require');
const {getCSSVar} = require('./index');
const {reRequire, stopAll} = mockRequire;

global.CloudCmd = {};
Expand All @@ -29,3 +30,32 @@ test('cloudcmd: client: dom: goToDirectory', async (t) => {
t.calledWith(changeDir, [path]);
t.end();
});

test('cloudcmd: client: dom: getCSSVar', (t) => {
const body = {};
const getPropertyValue = stub().returns(0);

global.getComputedStyle = stub().returns({
getPropertyValue,
});
const result = getCSSVar('hello', {body});
delete global.getComputedStyle;

t.notOk(result);
t.end();
});

test('cloudcmd: client: dom: getCSSVar: 1', (t) => {
const body = {};
const getPropertyValue = stub().returns(1);

global.getComputedStyle = stub().returns({
getPropertyValue,
});
const result = getCSSVar('hello', {body});

delete global.getComputedStyle;

t.ok(result);
t.end();
});
4 changes: 3 additions & 1 deletion client/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ function copyPath(el) {
}

function execIfNotMobile(callback, event) {
if (window.innerWidth > CloudCmd.MOBILE_ONE_PANEL_WIDTH)
const isMobile = DOM.getCSSVar('is-mobile');

if (!isMobile)
callback(event);
}

Expand Down
9 changes: 8 additions & 1 deletion css/query.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
width: 15%;
}
}

:root {
--mobile-max-width: 600px;
--min-one-panel-width: 1155px;
--is-mobile: 0;
}

@media only screen and (height <= 900px) and (width <= 600px) {
Expand Down Expand Up @@ -56,6 +57,12 @@
}
}

@media only screen and (width <= 600px) {
:root {
--is-mobile: 1;
}
}

@media only screen and (height <= 550px) and (width <= 600px) {
.fm {
height: 65%;
Expand Down

0 comments on commit a733d81

Please sign in to comment.