Merge pull request #171 from t8m/master
[openssl-web.git] / inc / octopress.js
1 function getNav() {
2   var mainNav = $('ul.main-navigation, ul[role=main-navigation]').before('<fieldset class="mobile-nav">')
3   var mobileNav = $('fieldset.mobile-nav').append('<select>');
4   mobileNav.find('select').append('<option value="">Navigate&hellip;</option>');
5   var addOption = function(i, option) {
6     mobileNav.find('select').append('<option value="' + this.href + '">&raquo; ' + $(this).text() + '</option>');
7   }
8   mainNav.find('a').each(addOption);
9   $('ul.subscription a').each(addOption);
10   mobileNav.find('select').bind('change', function(event) {
11     if (event.target.value) { window.location.href = event.target.value; }
12   });
13 }
14
15 function addSidebarToggler() {
16   if(!$('body').hasClass('sidebar-footer')) {
17     $('#content').append('<span class="toggle-sidebar"></span>');
18     $('.toggle-sidebar').bind('click', function(e) {
19       e.preventDefault();
20       $('body').toggleClass('collapse-sidebar');
21     });
22   }
23   var sections = $('aside.sidebar > section');
24   if (sections.length > 1) {
25     sections.each(function(index, section){
26       if ((sections.length >= 3) && index % 3 === 0) {
27         $(section).addClass("first");
28       }
29       var count = ((index +1) % 2) ? "odd" : "even";
30       $(section).addClass(count);
31     });
32   }
33   if (sections.length >= 3){ $('aside.sidebar').addClass('thirds'); }
34 }
35
36 function testFeatures() {
37   var features = ['maskImage'];
38   $(features).map(function(i, feature) {
39     if (Modernizr.testAllProps(feature)) {
40       $('html').addClass(feature);
41     } else {
42       $('html').addClass('no-'+feature);
43     }
44   });
45   if ("placeholder" in document.createElement("input")) {
46     $('html').addClass('placeholder');
47   } else {
48     $('html').addClass('no-placeholder');
49   }
50 }
51
52
53 $('document').ready(function() {
54   testFeatures();
55   getNav();
56   addSidebarToggler();
57 });
58
59 // iOS scaling bug fix
60 // Rewritten version
61 // By @mathias, @cheeaun and @jdalton
62 // Source url: https://gist.github.com/901295
63 (function(doc) {
64   var addEvent = 'addEventListener',
65       type = 'gesturestart',
66       qsa = 'querySelectorAll',
67       scales = [1, 1],
68       meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
69   function fix() {
70     meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
71     doc.removeEventListener(type, fix, true);
72   }
73   if ((meta = meta[meta.length - 1]) && addEvent in doc) {
74     fix();
75     scales = [0.25, 1.6];
76     doc[addEvent](type, fix, true);
77   }
78 }(document));