Giter Site home page Giter Site logo

Comments (7)

lord avatar lord commented on May 6, 2024

I decided on that because it's important to have the language in the URL. That is, if you're looking at the Ruby tab, you should be able to copy the URL and have it automatically point to the Ruby tab.

There's a way to change the URL with pushstate and popstate, but I couldn't figure out how to make it work well with the back button and tocify, so that the back button properly sends you to the correct position in the ToC. If you can figure out a way, I'd be glad to accept a pull request!

from slate.

lord avatar lord commented on May 6, 2024

Ah, and there was one other reason I chose to reload the page — it ensures when you switch languages, you stay in the same section. A good implementation pushstate should make sure that if the user switching tab while in a section, they remain in that section, even if the code samples above them are of different lengths. Maybe I can look into this in a couple weeks, I agree, reloading the page isn't optimal.

from slate.

bootstraponline avatar bootstraponline commented on May 6, 2024

This seems to work:

  // if we click on a language tab, activate that language
  $("#lang-selector a").bind("click", function() {
    var lang = $(this).data("language-name");
    var hash = window.location.hash;
    if (hash) hash = hash.replace(/^#+/, '');
    // do not reload the page every time the language is changed
    if (history) history.pushState({}, '', '?' + lang + '#' + hash);

    activateLanguage(lang);
    return false;
  });

from slate.

lord avatar lord commented on May 6, 2024

I'll take a look at this over the weekend, thanks!

from slate.

lord avatar lord commented on May 6, 2024

Ah, nice! It works for me, although I needed to add a onpopstate to handle users pressing history buttons. Thanks.

from slate.

bootstraponline avatar bootstraponline commented on May 6, 2024

Awesome. Thanks for fixing this.

from slate.

lord avatar lord commented on May 6, 2024

No problem. Let me know if you run into any issues with it, I haven't tested it super extensively.

from slate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.