Add ?language= linking [feature]
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
### March 17, 2016
|
||||||
|
|
||||||
|
* Support for linking to specific languages. URLs were previously like
|
||||||
|
`#the-section` but now are `?language=JavaScript#the-section` when a language
|
||||||
|
is selected, so that you can link to both a specific section and a specific
|
||||||
|
language.
|
||||||
|
|
||||||
### March 14, 2016
|
### March 14, 2016
|
||||||
|
|
||||||
* Support for toggling between 1 and 2 column mode
|
* Support for toggling between 1 and 2 column mode
|
||||||
|
@ -6,11 +6,13 @@ import PureRenderMixin from 'react-pure-render/mixin';
|
|||||||
import GithubSlugger from 'github-slugger';
|
import GithubSlugger from 'github-slugger';
|
||||||
import debounce from 'lodash.debounce';
|
import debounce from 'lodash.debounce';
|
||||||
import { brandNames, brandClasses } from '../../custom';
|
import { brandNames, brandClasses } from '../../custom';
|
||||||
|
import qs from 'querystring';
|
||||||
|
|
||||||
let slugger = new GithubSlugger();
|
let slugger = new GithubSlugger();
|
||||||
let slug = title => { slugger.reset(); return slugger.slug(title); };
|
let slug = title => { slugger.reset(); return slugger.slug(title); };
|
||||||
|
|
||||||
let languageOptions = ['cURL', 'CLI', 'Python', 'JavaScript'];
|
let languageOptions = ['cURL', 'CLI', 'Python', 'JavaScript'];
|
||||||
|
let defaultLanguage = 'cURL';
|
||||||
|
|
||||||
let debouncedReplaceState = debounce(hash => {
|
let debouncedReplaceState = debounce(hash => {
|
||||||
window.history.replaceState('', '', hash);
|
window.history.replaceState('', '', hash);
|
||||||
@ -27,6 +29,9 @@ var App = React.createClass({
|
|||||||
|
|
||||||
if (process.browser) {
|
if (process.browser) {
|
||||||
let hash = window.location.hash.split('#').pop();
|
let hash = window.location.hash.split('#').pop();
|
||||||
|
let languageFromURL = qs.parse(window.location.search.substring(1)).language;
|
||||||
|
let language = languageOptions.includes(languageFromURL) ?
|
||||||
|
languageFromURL : defaultLanguage;
|
||||||
let mqls = {
|
let mqls = {
|
||||||
desktop: window.matchMedia('(min-width: 961px)'),
|
desktop: window.matchMedia('(min-width: 961px)'),
|
||||||
tablet: window.matchMedia('(max-width: 960px)'),
|
tablet: window.matchMedia('(max-width: 960px)'),
|
||||||
@ -48,7 +53,7 @@ var App = React.createClass({
|
|||||||
mqls: mqls,
|
mqls: mqls,
|
||||||
// object of currently matched queries, like { desktop: true }
|
// object of currently matched queries, like { desktop: true }
|
||||||
queryMatches: {},
|
queryMatches: {},
|
||||||
language: 'cURL',
|
language: language,
|
||||||
columnMode: 2,
|
columnMode: 2,
|
||||||
activeSection: active,
|
activeSection: active,
|
||||||
// for the toggle-able navigation on mobile
|
// for the toggle-able navigation on mobile
|
||||||
@ -62,7 +67,7 @@ var App = React.createClass({
|
|||||||
queryMatches: {
|
queryMatches: {
|
||||||
desktop: true
|
desktop: true
|
||||||
},
|
},
|
||||||
language: 'cURL',
|
language: defaultLanguage,
|
||||||
activeSection: '',
|
activeSection: '',
|
||||||
showNav: false
|
showNav: false
|
||||||
};
|
};
|
||||||
@ -105,7 +110,12 @@ var App = React.createClass({
|
|||||||
document.body.removeEventListener('scroll', this.onScroll);
|
document.body.removeEventListener('scroll', this.onScroll);
|
||||||
},
|
},
|
||||||
onChangeLanguage(language) {
|
onChangeLanguage(language) {
|
||||||
this.setState({ language });
|
this.setState({ language }, () => {
|
||||||
|
if (window.history) {
|
||||||
|
window.history.pushState(null, null,
|
||||||
|
`?${qs.stringify({ language })}${window.location.hash}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
componentDidUpdate(_, prevState) {
|
componentDidUpdate(_, prevState) {
|
||||||
if (prevState.activeSection !== this.state.activeSection) {
|
if (prevState.activeSection !== this.state.activeSection) {
|
||||||
|
Reference in New Issue
Block a user