Skip to content

Commit 2dae661

Browse files
authored
Merge pull request #163 from Zzull/topBot_drawer
Vertical drawer
2 parents 1f5bef1 + d182fbd commit 2dae661

File tree

3 files changed

+104
-30
lines changed

3 files changed

+104
-30
lines changed

css/ot_drawer.css

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ html.ot-drawer-open, html.ot-drawer-open > body {
5252
.ot-drawer {
5353

5454
position: fixed;
55-
top: 0;
55+
width: 100%;
5656
height: 100%;
5757
z-index: 1;
5858

@@ -63,10 +63,8 @@ html.ot-drawer-open, html.ot-drawer-open > body {
6363
* with overflow-y: auto ; touch-action: pan-y; */
6464
overflow: visible ;
6565

66-
transform: translateX(0);
6766
transition: -webkit-transform .2s ease-out;
6867
transition: transform .2s ease-out;
69-
width: calc(100% - 50px) ;
7068

7169
/* We set up drawer so that the default transform is the identity
7270
* Otherwise, with Firefox, a transition is performed on page
@@ -76,23 +74,54 @@ html.ot-drawer-open, html.ot-drawer-open > body {
7674
}
7775

7876
@media (min-width: 720px) {
79-
.ot-drawer {
77+
.ot-drawer.ot-dr-left, .ot-drawer.ot-dr-right {
8078
width: 300px;
8179
}
80+
81+
.ot-drawer.ot-dr-top, .ot-drawer.ot-dr-bottom {
82+
height: 300px;
83+
}
84+
}
85+
86+
@media (max-width: 720px) {
87+
.ot-drawer.ot-dr-left, .ot-drawer.ot-dr-right {
88+
width: calc(100% - 50px);
89+
}
90+
91+
.ot-drawer.ot-dr-top, .ot-drawer.ot-dr-bottom {
92+
height: calc(100% - 50px);
93+
}
8294
}
8395

84-
.ot-drawer.ot-dr-left { right: 100% ; }
85-
.ot-drawer.ot-dr-right { left: 100% ; }
96+
.ot-drawer.ot-dr-top { bottom: 100% ; }
97+
.ot-drawer.ot-dr-right { left: 100% ; top: 0 }
98+
.ot-drawer.ot-dr-bottom { top: 100% ; }
99+
.ot-drawer.ot-dr-left { right: 100% ; top: 0 }
86100

87101
.ot-dr-toggle-button::before { content: "≡"; }
88-
.ot-drawer-bckgrnd.ot-dr-open .ot-dr-toggle-button::before { content: "⟨"; }
102+
103+
.ot-drawer-bckgrnd.ot-dr-open .ot-dr-top .ot-dr-toggle-button::before {
104+
content: "︿" ;
105+
}
106+
107+
.ot-drawer-bckgrnd.ot-dr-open .ot-dr-right .ot-dr-toggle-button::before {
108+
content: "⟩" ;
109+
}
110+
111+
.ot-drawer-bckgrnd.ot-dr-open .ot-dr-bottom .ot-dr-toggle-button::before {
112+
content: "﹀" ;
113+
}
114+
115+
.ot-drawer-bckgrnd.ot-dr-open .ot-dr-left .ot-dr-toggle-button::before {
116+
content: "⟨" ;
117+
}
118+
89119
.ot-drawer-bckgrnd.ot-dr-open .ot-dr-toggle-button {
90120
background-color: #445;
91121
}
92122

93123
.ot-drawer > .ot-dr-toggle-button {
94124
position: absolute ;
95-
top: 0 ;
96125
cursor: pointer ;
97126
height: 50px;
98127
width: 50px;
@@ -103,6 +132,21 @@ html.ot-drawer-open, html.ot-drawer-open > body {
103132
outline: none;
104133
}
105134

135+
.ot-drawer.ot-dr-top > .ot-dr-toggle-button {
136+
top: 100% ;
137+
right: calc(50% - 25px) ;
138+
}
139+
140+
.ot-drawer.ot-dr-right > .ot-dr-toggle-button,
141+
.ot-drawer.ot-dr-left > .ot-dr-toggle-button {
142+
top: 0 ;
143+
}
144+
145+
.ot-drawer.ot-dr-bottom > .ot-dr-toggle-button {
146+
bottom: 100% ;
147+
left: calc(50% - 25px) ;
148+
}
149+
106150
.ot-drawer.ot-dr-left > .ot-dr-toggle-button { left: 100% ; }
107151
.ot-drawer.ot-dr-right > .ot-dr-toggle-button { right: 100% ; }
108152

@@ -114,5 +158,15 @@ html.ot-drawer-open, html.ot-drawer-open > body {
114158

115159
.ot-drawer-bckgrnd.ot-dr-open .ot-drawer.ot-dr-right {
116160
-webkit-transform: translateX(-100%);
117-
transform: translate(-100%);
161+
transform: translateX(-100%);
162+
}
163+
164+
.ot-drawer-bckgrnd.ot-dr-open .ot-drawer.ot-dr-top {
165+
-webkit-transform: translateY(100%);
166+
transform: translateY(100%);
167+
}
168+
169+
.ot-drawer-bckgrnd.ot-dr-open .ot-drawer.ot-dr-bottom {
170+
-webkit-transform: translateY(-100%);
171+
transform: translateY(-100%);
118172
}

src/widgets/ot_drawer.eliom

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ let%shared drawer
9595
in
9696
let d = D.div ~a:[a_class [ "ot-drawer"
9797
; match position with
98-
| `Left -> "ot-dr-left"
99-
| `Right -> "ot-dr-right"]]
98+
| `Top -> "ot-dr-top"
99+
| `Right -> "ot-dr-right"
100+
| `Bottom -> "ot-dr-bottom"
101+
| `Left -> "ot-dr-left"]]
100102
(toggle_button :: (content :> Html_types.div_content elt list))
101103
in
102104
let bckgrnd_init_class = if opened then ["ot-dr-open"] else [] in
@@ -193,10 +195,15 @@ let%shared drawer
193195
animation_frame_requested := false;
194196
(match !action with
195197
| `Move delta ->
196-
let s = Js.string ((if ~%position = `Right
197-
then "translateX(calc(-100% + "
198-
else "translateX(calc(100% + ")^
199-
string_of_int delta^"px))") in
198+
let s =
199+
(match ~%position with
200+
| `Top -> "translateY(calc(100% + "
201+
| `Right -> "translateX(calc(-100% + "
202+
| `Bottom -> "translateY(calc(-100% + "
203+
| `Left -> "translateX(calc(100% + ")
204+
|> (fun t -> Printf.sprintf "%s%dpx" t delta)
205+
|> Js.string
206+
in
200207
(Js.Unsafe.coerce (dr##.style))##.transform := s;
201208
(Js.Unsafe.coerce (dr##.style))##.webkitTransform := s
202209
| `Close ->
@@ -226,26 +233,36 @@ let%shared drawer
226233
let status = ref Stopped in
227234
let onpan ev _ =
228235
let left = clX ev - !startx in
236+
let top = clY ev - !starty in
229237
if !status = Start
230-
then begin
231-
status := if abs (clY ev - !starty) > abs left
232-
then Aborted (* vertical scrolling *)
233-
else if abs left > Ot_swipe.threshold
234-
then begin (* We decide to take the event *)
238+
then
239+
status :=
240+
if ((~%position = `Top || ~%position = `Bottom)
241+
&& abs left > abs top)
242+
|| ((~%position = `Left || ~%position = `Right)
243+
&& abs top > abs left)
244+
then Aborted (* Orthogonal scrolling *)
245+
else if ((~%position = `Top || ~%position = `Bottom)
246+
&& abs top <= Ot_swipe.threshold)
247+
|| ((~%position = `Left || ~%position = `Right) &&
248+
abs left <= Ot_swipe.threshold)
249+
then !status
250+
else begin (* We decide to take the event *)
235251
Manip.Class.add ~%bckgrnd "ot-swiping";
236252
(Js.Unsafe.coerce (dr##.style))##.transition :=
237253
Js.string "-webkit-transform 0s, transform 0s";
238254
In_progress
239-
end
240-
else !status
241-
end;
255+
end;
242256
if !status = In_progress
243257
then begin
244258
Dom.preventDefault ev;
245259
Dom_html.stopPropagation ev;
246-
if (~%position = `Left && left <= 0)
247-
|| (~%position = `Right && left >= 0)
248-
then perform_animation (`Move left)
260+
let move = ref 0 in
261+
if (~%position = `Top && top <= 0 && (move := top; true))
262+
|| (~%position = `Right && left >= 0 && (move := left; true))
263+
|| (~%position = `Bottom && top >= 0 && (move := top; true))
264+
|| (~%position = `Left && left <= 0 && (move := left; true))
265+
then perform_animation (`Move !move)
249266
else Lwt.return_unit
250267
end
251268
else Lwt.return_unit
@@ -257,9 +274,12 @@ let%shared drawer
257274
(Js.Unsafe.coerce (dr##.style))##.transition :=
258275
Js.string "-webkit-transform .35s, transform .35s";
259276
let width = dr##.offsetWidth in
260-
let delta = float_of_int (clX ev - !startx) in
261-
if (~%position = `Left && delta < -0.3 *. float width)
262-
|| (~%position = `Right && delta > 0.3 *. float width)
277+
let deltaX = float_of_int (clX ev - !startx) in
278+
let deltaY = float_of_int (clY ev - !starty) in
279+
if (~%position = `Top && deltaY < -0.3 *. float width)
280+
|| (~%position = `Right && deltaX > 0.3 *. float width)
281+
|| (~%position = `Bottom && deltaY > 0.3 *. float width)
282+
|| (~%position = `Left && deltaX < -0.3 *. float width)
263283
then perform_animation `Close
264284
else perform_animation `Open
265285
end

src/widgets/ot_drawer.eliomi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*)
4444
val drawer :
4545
?a:[< Html_types.div_attrib] Eliom_content.Html.attrib list ->
46-
?position:[ `Left | `Right ] ->
46+
?position:[ `Top | `Right | `Bottom | `Left ] ->
4747
?opened:bool ->
4848
?swipe:bool ->
4949
?onclose:(unit -> unit) Eliom_client_value.t ->

0 commit comments

Comments
 (0)