Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always call evalscripts in fill. #110

Merged
merged 2 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 1 addition & 3 deletions src/content/api.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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
@js_(o, Blink.fill($sel, $html, $fade))

content!(o, sel, html; fade = true) =
content!(o, sel, stringmime(MIME"text/html"(), html), fade = fade)
Expand Down
35 changes: 35 additions & 0 deletions test/api.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Blink
using Base.Test

@testset "content! Tests" begin
w = Window(Blink.@d(:show => false)); sleep(5.0)
body!(w, ""); sleep(1.0) # body! is not synchronous.
@test (@js w document.querySelector("body").innerHTML) == ""

# Test reloading body and a selector element.
html = """<div id="a">hi world</div><div id="b">bye</div>"""
body!(w, html); sleep(1.0)
@test (@js w document.getElementById("a").innerHTML) == "hi world"
@test (@js w document.getElementById("b").innerHTML) == "bye"
content!(w, "div", "hello world"); sleep(1.0)
@test (@js w document.getElementById("a").innerHTML) == "hello world"
# TODO(nhdaly): Is this right? Should content!(w,"div",...) change _all_ divs?
@test (@js w document.getElementById("b").innerHTML) == "bye"

# Test `fade` parameter and scripts:
fadeTestHtml = """<script>var testJS = "test";</script><div id="d">hi world</div>"""
@testset "Fade True" begin
# Must create a new window to ensure javascript is reset.
w = Window(Blink.@d(:show => false)); sleep(5.0)

body!(w, fadeTestHtml; fade=true); sleep(1.0)
@test (@js w testJS) == "test"
end
@testset "Fade False" begin
# Must create a new window to ensure javascript is reset.
w = Window(Blink.@d(:show => false)); sleep(5.0)

body!(w, fadeTestHtml; fade=false); sleep(1.0)
@test (@js w testJS) == "test"
end
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ w = Window(Blink.@d(:show => false)); sleep(5.0)

@test sprint(Blink.jsexpr, :(Dict("a" => 1, :b => 10))) == "{\"a\":1,b:10}"

include("api.jl");

cleanup && AtomShell.uninstall()