-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix redraw flashes at the JavaScript example roulette
- Loading branch information
Showing
5 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
Picking the frontpage example after the page has loaded leads to reflows | ||
and re-rendering. Hence, we pick the example as soon as possible | ||
Copyright: 1999-2017 by D Language Foundation | ||
License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0 | ||
*/ | ||
/** | ||
Searches any object for the first hit. | ||
Params: | ||
el = object to filter | ||
fn = function to be applied as filter | ||
Returns: first hit, `undefined` otherwise | ||
*/ | ||
function findFirst(el, fn) { | ||
return Array.prototype.filter.call(el, fn)[0]; | ||
} | ||
(function() { | ||
// randomly pick one example and bootstrap the runnable editor | ||
var examples = document.getElementsByClassName('your-code-here-extra'); | ||
var rouletteIndex = Math.floor(Math.random() * examples.length); | ||
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; }); | ||
// 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"; | ||
rouletteChild.style.display = "block"; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters