From 87857b200224c42ae28577000013786035b91e87 Mon Sep 17 00:00:00 2001 From: Dillon Date: Thu, 22 Aug 2019 00:32:52 +0800 Subject: [PATCH] fix: fix iPad TOC orientation css bug --- assets/css/_core/_media.scss | 18 +++++++++++++++++- assets/js/main.js | 21 +++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/assets/css/_core/_media.scss b/assets/css/_core/_media.scss index 2d625fd2..00771bb1 100644 --- a/assets/css/_core/_media.scss +++ b/assets/css/_core/_media.scss @@ -150,7 +150,23 @@ /* iPads (portrait and landscape) ----------- */ -@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) { +@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:portrait) { + .post-warp { + max-width: 600px !important; + } + + .navbar-mobile { + display: none !important; + } + + .post-toc { + display: none !important; + } +} + +/* iPads (portrait and landscape) ----------- */ + +@media only screen and (min-device-width: 768px) and (max-device-width: 1024px) and (orientation:landscape) { .post-warp { max-width: 560px !important; } diff --git a/assets/js/main.js b/assets/js/main.js index f8eced0f..b15f6c77 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -54,7 +54,7 @@ jQuery(function($) { }; _Blog._initToc = function() { - if ($('.post-toc').length) { + if ($('.post-toc').length && $('.post-toc').css('display') !== 'none') { const SPACING = 20; const $toc = $('.post-toc'); const $footer = $('.post-footer'); @@ -90,7 +90,6 @@ jQuery(function($) { } }; changeTocState(); - $(window).scroll(changeTocState); const HEADERFIX = 100; const $toclink = $('.toc-link'); @@ -127,7 +126,11 @@ jQuery(function($) { } }; activeIndex(); - $(window).scroll(activeIndex); + if (!this._initTocOnce) { + $(window).scroll(changeTocState); + $(window).scroll(activeIndex); + this._initTocOnce = true; + } } }; @@ -136,12 +139,14 @@ jQuery(function($) { if (tocContainer !== null) { const toc = document.getElementById('TableOfContents'); if (toc === null) { - // toc = true, but there are no headings - tocContainer.parentNode.removeChild(tocContainer); + // toc = true, but there are no headings + tocContainer.parentNode.removeChild(tocContainer); } else { - this._refactorToc(toc); - this._linkToc(); - this._initToc(); + this._refactorToc(toc); + this._linkToc(); + this._initToc(); + // Listen for orientation changes + window.addEventListener("orientationchange", this._initToc, false); } } };