Skip to content

Commit 81a6f81

Browse files
committed
Merge pull request bcit-ci#4167 from zhanghongyi/fix-pulldown
disable pulldown menu on mobile devices
2 parents 3013f53 + 99c8ff3 commit 81a6f81

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

user_guide_src/source/_themes/sphinx_rtd_theme/static/css/citheme.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,19 @@ div#pulldown-menu {
7070
font-weight: 300;
7171
font-family: Lucida Grande,Verdana,Geneva,sans-serif;
7272
color: #aaaaaa;
73+
}
74+
75+
/*hide pulldown menu on mobile devices*/
76+
@media (max-width: 768px) { /*tablet size defined by theme*/
77+
#closeMe {
78+
display: none;
79+
}
80+
81+
#pulldown {
82+
display: none;
83+
}
84+
85+
#openToc {
86+
display: none;
87+
}
7388
}

user_guide_src/source/_themes/sphinx_rtd_theme/static/js/theme.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $(document).ready(function () {
2525
$('#closeMe').toggle(
2626
function ()
2727
{
28-
setCookie('ciNav', true, 365);
28+
setCookie('ciNav', 'yes', 365);
2929
$('#nav2').show();
3030
$('#topMenu').remove();
3131
$('body').css({background: 'none'});
@@ -35,7 +35,7 @@ $(document).ready(function () {
3535
},
3636
function ()
3737
{
38-
setCookie('ciNav', false, 365);
38+
setCookie('ciNav', 'no', 365);
3939
$('#topMenu').remove();
4040
$('#nav').hide();
4141
$('#nav2').hide();
@@ -44,20 +44,25 @@ $(document).ready(function () {
4444
$('.wy-nav-side').show();
4545
}
4646
);
47-
if (getCookie('ciNav') == 'true')
47+
if (getCookie('ciNav') == 'yes')
4848
{
4949
$('#closeMe').trigger('click');
5050
//$('#nav').slideToggle();
5151
}
5252
// END MODIFICATION ---
53+
5354
});
5455

5556
// Rufnex Cookie functions
5657
function setCookie(cname, cvalue, exdays) {
58+
// expire the old cookie if existed to avoid multiple cookies with the same name
59+
if (getCookie(cname)) {
60+
document.cookie = cname + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
61+
}
5762
var d = new Date();
5863
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
5964
var expires = "expires=" + d.toGMTString();
60-
document.cookie = cname + "=" + cvalue + "; " + expires;
65+
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
6166
}
6267
function getCookie(cname) {
6368
var name = cname + "=";
@@ -70,10 +75,31 @@ function getCookie(cname) {
7075
return c.substring(name.length, c.length);
7176
}
7277
}
73-
return false;
78+
return '';
7479
}
7580
// End
7681

82+
// resize window
83+
$(window).on('resize', function(){
84+
// show side nav on small screens when pulldown is enabled
85+
if (getCookie('ciNav') == 'yes' && $(window).width() <= 768) { // 768px is the tablet size defined by the theme
86+
$('.wy-nav-side').show();
87+
}
88+
// changing css with jquery seems to override the default css media query
89+
// change margin
90+
else if (getCookie('ciNav') == 'no' && $(window).width() <= 768) {
91+
$('.wy-nav-content-wrap').css({'margin-left': 0});
92+
}
93+
// hide side nav on large screens when pulldown is enabled
94+
else if (getCookie('ciNav') == 'yes' && $(window).width() > 768) {
95+
$('.wy-nav-side').hide();
96+
}
97+
// change margin
98+
else if (getCookie('ciNav') == 'no' && $(window).width() > 768) {
99+
$('.wy-nav-content-wrap').css({'margin-left': '300px'});
100+
}
101+
});
102+
77103
window.SphinxRtdTheme = (function (jquery) {
78104
var stickyNav = (function () {
79105
var navBar,

0 commit comments

Comments
 (0)