Browse Source

Switch Installation to a tab when hash is present (#9422)

main
Dan Abramov 8 years ago
committed by GitHub
parent
commit
1e3b36dfdf
  1. 39
      docs/installation.md

39
docs/installation.md

@ -195,6 +195,10 @@ To load a specific version of `react` and `react-dom`, replace `15` with the ver
If you use Bower, React is available via the `react` package. If you use Bower, React is available via the `react` package.
<script> <script>
/**
* The code below is based on a snippet from React Native Getting Started page.
*/
// Convert <div>...<span><block /></span>...</div> // Convert <div>...<span><block /></span>...</div>
// Into <div>...<block />...</div> // Into <div>...<block />...</div>
var blocks = document.getElementsByTagName('block'); var blocks = document.getElementsByTagName('block');
@ -219,4 +223,39 @@ function display(type, value) {
container.className = 'display-' + type + '-' + value + ' ' + container.className = 'display-' + type + '-' + value + ' ' +
container.className.replace(RegExp('display-' + type + '-[a-z]+ ?'), ''); container.className.replace(RegExp('display-' + type + '-[a-z]+ ?'), '');
} }
// If we are coming to the page with a hash in it (i.e. from a search, for example), try to get
// us as close as possible to the correct platform and dev os using the hashtag and block walk up.
var foundHash = false;
if (window.location.hash !== '' && window.location.hash !== 'content') { // content is default
// Hash links are added a bit later so we wait for them.
window.addEventListener('DOMContentLoaded', selectTabForHashLink);
}
function selectTabForHashLink() {
var hashLinks = document.querySelectorAll('a.hash-link');
for (var i = 0; i < hashLinks.length && !foundHash; ++i) {
if (hashLinks[i].hash === window.location.hash) {
var parent = hashLinks[i].parentElement;
while (parent) {
if (parent.tagName === 'BLOCK') {
var target = null;
if (parent.className.indexOf('fiddle') > -1) {
target = 'fiddle';
} else if (parent.className.indexOf('newapp') > -1) {
target = 'newapp';
} else if (parent.className.indexOf('existingapp') > -1) {
target = 'existingapp';
} else {
break; // assume we don't have anything.
}
display('target', target);
foundHash = true;
break;
}
parent = parent.parentElement;
}
}
}
}
</script> </script>
Loading…
Cancel
Save