Skip to content

Commit d9c785f

Browse files
committed
Play: Explore replacing jQuery effects with CSS transitions
1 parent 4f667a3 commit d9c785f

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

priv/www/nitrogen.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,15 @@ a.upload_delete_file:hover {
297297
left:-10000px;
298298
}
299299

300+
.n2-effect-appear {
301+
transition: height 0ms 500ms, opacity 500ms;
302+
height: auto;
303+
opacity: inherit;
304+
}
305+
306+
.n2-effect-fade {
307+
transition: height 0ms 500ms, opacity 500ms;
308+
height: 0;
309+
opacity: 0;
310+
overflow: hidden;
311+
}

src/actions/action_jquery_effect.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ render_action(Record) ->
3939
'toggle' when Effect==none ->
4040
["toggle(", ActionsFun, ");"];
4141
'appear' ->
42-
if_visible(Actions, [wf:f("$(this).fadeIn(~p, ", [Speed]), ActionsFun, ");"]);
42+
{raw, [wf:f("document.querySelectorAll('~s')", [Target]), ".forEach(node => { node.classList.remove('n2-effect-fade'); node.classList.add('n2-effect', 'n2-effect-appear'); } )"]};
4343
'fade' ->
44-
if_visible([wf:f("$(this).fadeOut(~p, ", [Speed]), ActionsFun, ");"], Actions);
45-
'slideup'->
44+
{raw, [wf:f("document.querySelectorAll('~s')", [Target]), ".forEach(node => { node.classList.remove('n2-effect-appear'); node.classList.add('n2-effect', 'n2-effect-fade'); } )"]};
45+
'slideup' ->
4646
if_visible([wf:f("$(this).slideUp(~p, ",[Speed]), ActionsFun, ");"], Actions);
4747
'slidedown' ->
4848
if_visible(Actions, [wf:f("$(this).slideDown(~p, ",[Speed]), ActionsFun, ");"]);
@@ -65,7 +65,12 @@ render_action(Record) ->
6565
'animate' ->
6666
[wf:f("animate(~s, ~p, '~s', ", [Options, Speed, Easing]), ActionsFun, ");"]
6767
end,
68-
[wf:f("objs('~s').", [Target]), Script].
68+
R = case Script of
69+
{raw, S} -> S;
70+
S -> [wf:f("objs('~s').", [Target]), Script]
71+
end,
72+
io:format("Effect: ~p~n", [R]),
73+
R.
6974

7075
execute_actions_fun("null") ->
7176
"";

0 commit comments

Comments
 (0)