Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: src/site/js/os-switcher.js

Issue 701913002: Editing Sam's downloads page (Closed) Base URL: https://github.com/dart-lang/www.dartlang.org.git@master
Patch Set: Add back original download page for A-B testing Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 $(document).ready(function() { 1 $(document).ready(function() {
2 var osList = ['macos', 'windows', 'linux']; 2 var osList = ['macos', 'windows', 'linux'];
3 3
4 function detectPlatform() { 4 function detectPlatform() {
5 // default to 'linux', since linux strings are unpredictable. 5 // default to 'linux', since linux strings are unpredictable.
6 if (navigator.platform.indexOf('Win') != -1) { 6 if (navigator.platform.indexOf('Win') != -1) {
7 return 'windows'; 7 return 'windows';
8 } else if (navigator.platform.indexOf('Mac') != -1) { 8 } else if (navigator.platform.indexOf('Mac') != -1) {
9 return 'macos'; 9 return 'macos';
10 } else { 10 } else {
11 return 'linux'; 11 return 'linux';
12 } 12 }
13 } 13 }
14 14
15 function filterPlatformText(showId) { 15 function filterPlatformText(showId) {
16 // Get all the platform-specific elements. 16 // Get all the platform-specific elements.
17 for (var i = 0; i < osList.length; i++) { 17 for (var i = 0; i < osList.length; i++) {
18 var os = osList[i]; 18 var os = osList[i];
19 var shouldShow = (os === showId); 19 var shouldShow = (os === showId);
20 $('.' + os).each(function(i, el) { 20 $('.' + os).each(function(i, el) { $(el).toggle(shouldShow); });
21 if (shouldShow) {
22 $(el).show();
23 } else {
24 $(el).hide();
25 }
26 });
27 } 21 }
28 } 22 }
29 23
24 function resetButtons(el) {
25 if (el.tagName == "BUTTON") {
26 $('.btn-group.os-choices button').removeClass('active').addClass('inactive ');
27 }
28 $(el).removeClass('inactive').addClass('active');
29 }
30
30 function registerHandlers() { 31 function registerHandlers() {
31 for (var i = 0; i < osList.length; i++) { 32 for (var i = 0; i < osList.length; i++) {
32 var os = document.getElementById(osList[i]); 33 var os = document.getElementById(osList[i]);
33 if (os) { 34 if (os) {
34 os.addEventListener('click', function(e) { 35 os.addEventListener('click', function(e) {
35 filterPlatformText(e.target.id); 36 filterPlatformText(e.target.id);
37 resetButtons(e.target);
36 }); 38 });
37 } 39 }
38 } 40 }
39 } 41 }
40 42
41 var defaultOs = detectPlatform(); 43 var defaultOs = detectPlatform();
42 var defaultOsElem = document.getElementById(defaultOs);
43 $('.' + defaultOs+'-option').prop('selected', true); 44 $('.' + defaultOs+'-option').prop('selected', true);
44 if (defaultOsElem) { 45 var defaultOsElem;
45 defaultOsElem.setAttribute('checked', 'checked'); 46 defaultOsElem = $('input#' + defaultOs);
47 if (defaultOsElem.length > 0) {
48 defaultOsElem.attr('checked', 'checked')
49 }
50
51 defaultOsElem = $('button#' + defaultOs);
52 if (defaultOsElem.length > 0) {
53 resetButtons(defaultOsElem[0]);
54 }
55 //if (defaultOsElem.length > 0) {
46 filterPlatformText(defaultOs); 56 filterPlatformText(defaultOs);
47 registerHandlers(); 57 registerHandlers();
48 } 58 //}
49
50 }); 59 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698