Permalink
Browse files

Updated OS switcher to try and auto-detect what operating system the …

…visitor is using.

This will only take place if an OS hasn't already been selected (i.e. when the cookie is not present).
  • Loading branch information...
amasses committed Aug 11, 2013
1 parent 6b85e43 commit d0885cdb21cc7fe214e374c872045a3d22752c62
Showing with 15 additions and 1 deletion.
  1. +15 −1 js/guides.js
View
@@ -6,20 +6,34 @@ function loadOs() {
var osFromCookie = $.cookie("os");
if(osFromCookie) {
$(".os-specific").find("." + osFromCookie + "-link").click();
+ } else if(detectOs()) {
+ $(".os-specific").find("." + detectOs() + "-link").click();
} else {
$(".os-specific").find(".win-link").click();
}
return osFromCookie;
}
+function detectOs() {
+ try {
+ if (navigator.appVersion.match(/Win/i)) {
+ return "win";
+ } else {
+ return "nix";
+ }
+ } catch(e) {
+ return false;
+ }
+}
+
function addIcons() {
$("code.sh, code.bat").closest('.highlight').before('<i class="icon-small-prompt"></i>');
$("code.erb, code.html, code.ruby, code.css").closest('.highlight').before('<i class="icon-small-text-editor"></i>');
$("code.browser").closest('.highlight').before('<i class="icon-small-browser"></i>');
}
function initializeOsSwitchers() {
- $(".os-specific").append("<span class='picker'>Choose your operating system: <a href='#' class='win-link'>Windows</a> <a href='#' class='nix-link'>Other</a></span>").find(".win-link").click(function(event) {
+ $(".os-specific").append("<span class='picker'>Choose your operating system: <a href='#' class='win-link'>Windows</a> | <a href='#' class='nix-link'>Other</a></span>").find(".win-link").click(function(event) {
event.preventDefault();
saveOs("win");

0 comments on commit d0885cd

Please sign in to comment.