Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
61033b2d
Commit
61033b2d
authored
Aug 10, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increase performance of the breakpoint size checker
parent
53ee3805
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
61 deletions
+33
-61
app/assets/javascripts/breakpoints.js
app/assets/javascripts/breakpoints.js
+18
-61
spec/javascripts/breakpoints_spec.js
spec/javascripts/breakpoints_spec.js
+15
-0
No files found.
app/assets/javascripts/breakpoints.js
View file @
61033b2d
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, quotes, no-shadow, prefer-arrow-callback, prefer-template, consistent-return, no-return-assign, new-parens, no-param-reassign, max-len */
export
const
breakpoints
=
{
lg
:
1200
,
md
:
992
,
sm
:
768
,
xs
:
0
,
};
var
Breakpoints
=
(
function
()
{
const
BreakpointInstance
=
{
var
BreakpointInstance
,
instance
;
windowWidth
:
()
=>
window
.
innerWidth
,
getBreakpointSize
()
{
const
windowWidth
=
this
.
windowWidth
();
function
Breakpoints
()
{}
const
breakpoint
=
Object
.
keys
(
breakpoints
).
find
(
key
=>
windowWidth
>
breakpoints
[
key
]);
instance
=
null
;
return
breakpoint
;
},
};
BreakpointInstance
=
(
function
()
{
// For legacy reasons, this is added to window
var
BREAKPOINTS
;
// one day this should be deleted
window
.
bp
=
BreakpointInstance
;
BREAKPOINTS
=
[
"
xs
"
,
"
sm
"
,
"
md
"
,
"
lg
"
];
export
default
BreakpointInstance
;
function
BreakpointInstance
()
{
this
.
setup
();
}
BreakpointInstance
.
prototype
.
setup
=
function
()
{
var
allDeviceSelector
,
els
;
allDeviceSelector
=
BREAKPOINTS
.
map
(
function
(
breakpoint
)
{
return
"
.device-
"
+
breakpoint
;
});
if
(
$
(
allDeviceSelector
.
join
(
"
,
"
)).
length
)
{
return
;
}
// Create all the elements
els
=
$
.
map
(
BREAKPOINTS
,
function
(
breakpoint
)
{
return
"
<div class='device-
"
+
breakpoint
+
"
visible-
"
+
breakpoint
+
"
'></div>
"
;
});
return
$
(
"
body
"
).
append
(
els
.
join
(
''
));
};
BreakpointInstance
.
prototype
.
visibleDevice
=
function
()
{
var
allDeviceSelector
;
allDeviceSelector
=
BREAKPOINTS
.
map
(
function
(
breakpoint
)
{
return
"
.device-
"
+
breakpoint
;
});
return
$
(
allDeviceSelector
.
join
(
"
,
"
)).
filter
(
"
:visible
"
);
};
BreakpointInstance
.
prototype
.
getBreakpointSize
=
function
()
{
var
$visibleDevice
;
$visibleDevice
=
this
.
visibleDevice
;
// TODO: Consider refactoring in light of turbolinks removal.
// the page refreshed via turbolinks
if
(
!
$visibleDevice
().
length
)
{
this
.
setup
();
}
$visibleDevice
=
this
.
visibleDevice
();
return
$visibleDevice
.
attr
(
"
class
"
).
split
(
"
visible-
"
)[
1
];
};
return
BreakpointInstance
;
})();
Breakpoints
.
get
=
function
()
{
return
instance
!=
null
?
instance
:
instance
=
new
BreakpointInstance
;
};
return
Breakpoints
;
})();
$
(()
=>
{
window
.
bp
=
Breakpoints
.
get
();
});
window
.
Breakpoints
=
Breakpoints
;
spec/javascripts/breakpoints_spec.js
0 → 100644
View file @
61033b2d
import
bp
,
{
breakpoints
,
}
from
'
~/breakpoints
'
;
describe
(
'
breakpoints
'
,
()
=>
{
Object
.
keys
(
breakpoints
).
forEach
((
key
)
=>
{
const
size
=
breakpoints
[
key
];
it
(
`returns
${
key
}
when larger than
${
size
}
`
,
()
=>
{
spyOn
(
bp
,
'
windowWidth
'
).
and
.
returnValue
(
size
+
10
);
expect
(
bp
.
getBreakpointSize
()).
toBe
(
key
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment