-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Fix redraw flashes at the JavaScript example roulette #1775
Conversation
Thanks for your pull request, @wilzbach! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
index.dd
Outdated
) | ||
))) | ||
<script src="$(ROOT_DIR)js/example_roulette.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline the script please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still would like to add the example selection as well (so the file will grow) and doing Js in Ddoc is really a pain.
Didn't you believe me, when I showed that using a separate file doesn't matter performance-wise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still would like to add the example selection as well (so the file will grow)
I don't understand how adding the dropdown should affect this part. The dropdown can only work when JavaScript is enabled, so it would need to be added at the end, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't you believe me, when I showed that using a separate file doesn't matter performance-wise?
- It doesn't matter today
- It doesn't matter in that browser
- Not an excuse to make a sub-ideal situation worse. What that shows is that more things need to be loaded lazily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dropdown can only work when JavaScript is enabled, so it would need to be added at the end, no?
No it should be done here as well - same motivation: preventing redraws
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to worry about relayouts first; redraws shouldn't be much of a problem as long as they aren't too distracting. Avoiding relayouts should be easy by reserving space for the interactive stuff that will be filled in later by JS.
As for redraws (I assume you mean pop-in when new UI elements are displayed), we have too much stuff redrawing anyway with all the widgets etc. Not sure if it's worth complicating the implementation much just to be able to have the drop-down there from the start, though even so, I think it would be like 1 more line to select the right option, right? And the buttons are going to be added in later either way, right?
js/example_roulette.js
Outdated
var rouletteChildNode = findFirst(rouletteChild.children, function(e) { return e.className.indexOf("runnable-example") != -1; }); | ||
// step 2: select the first <pre> element (of the .runnable-example <div>) | ||
var el = findFirst(rouletteChildNode.children, function(e) { return e.nodeName == "PRE";}); | ||
el.style.marginBottom = "20px"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, this is not necessary. You can use the have-javascript
class and do it with a CSS rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to reset this after the entire body has been parsed (and the JS for the building the examples layout gets triggered), not on start:
<body id='Home' class='doc'>
<script type="text/javascript">document.body.className += ' have-javascript'</script>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Err, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this how a browser behaves?
- Page gets fetched
- browser fetches all scripts in the header
- it starts evaluating the body -> adds the class
- it hits the examples and executes this js (with the marginBottom hack)
- it fetches all the scripts and stuff before and at the page bottom
- it reaches the end of the page and reverts the marginBottom hack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I understand what you mean now. Just because you need to reset it doesn't mean you have to add it via JS too - JS styles override CSS ones because they're going to be set on the element itself. Regardless I agree that undoing/resetting it is suboptimal, see my comment below.
js/run.js
Outdated
@@ -127,6 +127,8 @@ $(document).ready(function() | |||
{ | |||
var root = $(this); | |||
var el = root.children("pre"); | |||
// hack from the front page to avoid redraw flashes due to the buttons showing up | |||
el[0].style.marginBottom = "0px"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of removing the margin, can this be left in? As mentioned in the previous PR, my suggestion was to simply create a container (whose size is not going to change) for the buttons to be placed in. I think that would avoid a relayout.
8e962fe
to
51f7f9a
Compare
Okay, I have removed the |
index.dd
Outdated
var rouletteChild = examples[rouletteIndex]; | ||
|
||
// step 1: select the .runnable-example <div> | ||
var rouletteChildNode = findFirst(rouletteChild.children, function(e) { return e.className.indexOf("runnable-example") != -1; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not rouletteChild.getElementsByClassName
?
index.dd
Outdated
// step 1: select the .runnable-example <div> | ||
var rouletteChildNode = findFirst(rouletteChild.children, function(e) { return e.className.indexOf("runnable-example") != -1; }); | ||
// step 2: select the first <pre> element (of the .runnable-example <div>) | ||
var el = findFirst(rouletteChildNode.children, function(e) { return e.nodeName == "PRE";}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not getElementsByTagName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it looks like querySelector is good to use today:
http://caniuse.com/#feat=queryselector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I believe you can avoid traversing the element's children by setting a class on the rouletteChild
element.
51f7f9a
to
6d8eb93
Compare
Hmm, now that we don't do any layout modifications, I can simply drop the three lines in question - all we do is |
Btw if we already spent so much time on the examples, I really like how kotlin presents the first example: |
Awesome. So the coveted 5 lines of JS are possible after all :)
Honestly, I don't think it's any more of a hack that specifying the dimensions of an image on the |
OT: Not so sure whether you noticed, but someone pointed out on the NG had the fair point that the examples lack explanation and explanatory links. Python.org puts a good bar here: There's also a lot more on this discussion, e.g. how complex the examples should be etc. |
Yes, I saw that. Eye of the beholder etc. - the impression of any example depends on the reader's experience, and D has a pretty wide target audience. Not sure we can reasonably approach this without an overhaul of the front page. |
I think you forgot to approve? Maybe we should add a warning to the bot? |
Could have sworn I did. Maybe I just forgot to submit it. |
CC @popen2 |
FYI: the dlang-bot didn't receive the approval hook (they weren't sent). I have enabled this for all dlang repos now, but it needs a bit of handling on the dlang-bot side as well (though I need to wait a bit until a receive a relevant payload to put it into the testsuite). See also: dlang/dlang-bot#104 or dlang/dlang-bot#108 |
"Meh" solution instead of #1757
CC @CyberShadow