Skip to content

Commit

Permalink
Fixes JuliaGizmos#109. Always calls evalscripts in fill.
Browse files Browse the repository at this point in the history
Moves the fade/no-fade decision from julia down into javascript, so that
more code can be reused between the two.

This also simplifies the `content!` function body, which will make
fixing JuliaGizmos#108 a bit easier.

Updates "Fade False" test to not @test_throws. Tests still pass.
  • Loading branch information
NHDaly committed Jan 17, 2018
1 parent d9c00f1 commit fe421f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
15 changes: 12 additions & 3 deletions res/blink.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,27 @@
}
}

function fill(node, html) {
function fill(node, html, fade) {
node = select(node);
fade ?
fillfade(node, html) :
fillnofade(node, html)
}
function fillfade(node, html) {
node = select(node);
node.classList.add('blink-show');
callback(function () {
node.classList.add('blink-fade');
callback(0.2, function() {
node.innerHTML = html;
evalscripts(node);
fillnofade(node, html);
node.classList.remove('blink-fade');
});
});
}
function fillnofade(node, html) {
node.innerHTML = html;
evalscripts(node);
}

Blink.fill = fill;

Expand Down
8 changes: 3 additions & 5 deletions src/content/api.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
export body!, content!, loadcss!, loadjs!, load!, importhtml!

content!(o, sel, html::AbstractString; fade = true) =
fade ?
@js_(o, Blink.fill($sel, $html)) :
@js_ o document.querySelector($sel).innerHTML = $html
content!(o, sel, html::AbstractString; fade=true) =
@js_(o, Blink.fill($sel, $html, $fade))

content!(o, sel, html; fade = true) =
content!(o, sel, html; fade=true) =
content!(o, sel, stringmime(MIME"text/html"(), html), fade = fade)

body!(w, html; fade = true) = content!(w, "body", html, fade = fade)
Expand Down
2 changes: 1 addition & 1 deletion test/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ using Base.Test
w = Window(Blink.@d(:show => false)); sleep(5.0)

body!(w, fadeTestHtml; fade=false); sleep(1.0)
@test_throws Blink.JSError (@js w testJS) == "test" # THIS IS AN ERROR, should not throw.
@test (@js w testJS) == "test"
end
end

0 comments on commit fe421f5

Please sign in to comment.