File tree Expand file tree Collapse file tree 5 files changed +48
-10
lines changed
Expand file tree Collapse file tree 5 files changed +48
-10
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const {
2525} = require ( '../common/cloudfunc' ) ;
2626
2727const loadModule = require ( './load-module' ) ;
28+ const { getCSSVar} = require ( './dom' ) ;
2829
2930const noJS = ( a ) => a . replace ( / .j s $ / , '' ) ;
3031
@@ -59,15 +60,8 @@ function CloudCmdProto(DOM) {
5960 this . prefixSocket = '' ;
6061 this . prefixURL = '' ;
6162
62- const bodyStyle = getComputedStyle ( document . body ) ;
63-
64- this . MIN_ONE_PANEL_WIDTH = bodyStyle . getPropertyValue ( '--min-one-panel-width' ) ;
65- this . MOBILE_ONE_PANEL_WIDTH = bodyStyle . getPropertyValue ( '--mobile-max-width' ) ;
66-
63+ this . MIN_ONE_PANEL_WIDTH = DOM . getCSSVar ( 'min-one-panel-width' ) ;
6764 this . HOST = location . origin || location . protocol + '//' + location . host ;
68-
69- this . TITLE = 'Cloud Commander' ;
70-
7165 this . sort = {
7266 left : 'name' ,
7367 right : 'name' ,
Original file line number Diff line number Diff line change @@ -520,6 +520,11 @@ module.exports.getPanelPosition = (panel) => {
520520 return panel . dataset . name . replace ( 'js-' , '' ) ;
521521} ;
522522
523+ module . exports . getCSSVar = ( name , { body = document . body } = { } ) => {
524+ const bodyStyle = getComputedStyle ( body ) ;
525+ return bodyStyle . getPropertyValue ( `--${ name } ` ) ;
526+ } ;
527+
523528/** function getting panel active, or passive
524529 * @param options = {active: true}
525530 */
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ require('css-modules-require-hook/preset');
44
55const { test, stub} = require ( 'supertape' ) ;
66const mockRequire = require ( 'mock-require' ) ;
7+ const { getCSSVar} = require ( './index' ) ;
78const { reRequire, stopAll} = mockRequire ;
89
910global . CloudCmd = { } ;
@@ -29,3 +30,32 @@ test('cloudcmd: client: dom: goToDirectory', async (t) => {
2930 t . calledWith ( changeDir , [ path ] ) ;
3031 t . end ( ) ;
3132} ) ;
33+
34+ test ( 'cloudcmd: client: dom: getCSSVar' , ( t ) => {
35+ const body = { } ;
36+ const getPropertyValue = stub ( ) . returns ( 0 ) ;
37+
38+ global . getComputedStyle = stub ( ) . returns ( {
39+ getPropertyValue,
40+ } ) ;
41+ const result = getCSSVar ( 'hello' , { body} ) ;
42+ delete global . getComputedStyle ;
43+
44+ t . notOk ( result ) ;
45+ t . end ( ) ;
46+ } ) ;
47+
48+ test ( 'cloudcmd: client: dom: getCSSVar: 1' , ( t ) => {
49+ const body = { } ;
50+ const getPropertyValue = stub ( ) . returns ( 1 ) ;
51+
52+ global . getComputedStyle = stub ( ) . returns ( {
53+ getPropertyValue,
54+ } ) ;
55+ const result = getCSSVar ( 'hello' , { body} ) ;
56+
57+ delete global . getComputedStyle ;
58+
59+ t . ok ( result ) ;
60+ t . end ( ) ;
61+ } ) ;
Original file line number Diff line number Diff line change @@ -222,7 +222,9 @@ function copyPath(el) {
222222}
223223
224224function execIfNotMobile ( callback , event ) {
225- if ( window . innerWidth > CloudCmd . MOBILE_ONE_PANEL_WIDTH )
225+ const isMobile = DOM . getCSSVar ( 'is-mobile' ) ;
226+
227+ if ( ! isMobile )
226228 callback ( event ) ;
227229}
228230
Original file line number Diff line number Diff line change 1919 width : 15% ;
2020 }
2121}
22+
2223: root {
23- --mobile-max-width : 600px ;
2424 --min-one-panel-width : 1155px ;
25+ --is-mobile : 0 ;
2526}
2627
2728@media only screen and (height <= 900px) and (width <= 600px) {
5657 }
5758}
5859
60+ @media only screen and (width <= 600px) {
61+ : root {
62+ --is-mobile : 1 ;
63+ }
64+ }
65+
5966@media only screen and (height <= 550px) and (width <= 600px) {
6067 .fm {
6168 height : 65% ;
You can’t perform that action at this time.
0 commit comments