From f1035b07d61df8083d62b84a5340fa43d732edf5 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 5 Jan 2017 13:43:54 -0500 Subject: [PATCH] bug fixes in toc system --- Kiwix-iOS/Controller/Main/MainDelegates.swift | 14 +++++++------- Kiwix/JavaScripts/injection.js | 4 ++-- Kiwix/Operations/ArticleOperation.swift | 5 ++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Kiwix-iOS/Controller/Main/MainDelegates.swift b/Kiwix-iOS/Controller/Main/MainDelegates.swift index 45f4e0fb..14be85d9 100644 --- a/Kiwix-iOS/Controller/Main/MainDelegates.swift +++ b/Kiwix-iOS/Controller/Main/MainDelegates.swift @@ -42,6 +42,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate { func webViewDidFinishLoad(_ webView: UIWebView) { JS.inject(webView: webView) JS.preventDefaultLongTap(webView: webView) + tableOfContentsController?.headings = JS.getTableOfContents(webView: webView) JS.startTOCCallBack(webView: webView) URLResponseCache.shared.stop() @@ -93,10 +94,10 @@ extension MainController: SearchBarDelegate, SearchContainerDelegate { controller.delegate = self guard !childViewControllers.contains(controller) else {return} - navigationController?.setToolbarHidden(true, animated: animated) - - // add cancel button if needed + // hide toolbar + // add cancel button if traitCollection.horizontalSizeClass == .compact { + navigationController?.setToolbarHidden(true, animated: animated) navigationItem.setRightBarButton(buttons.cancel, animated: animated) } @@ -125,10 +126,10 @@ extension MainController: SearchBarDelegate, SearchContainerDelegate { private func hideSearch(animated: Bool) { guard let searchController = childViewControllers.flatMap({$0 as? SearchContainer}).first else {return} - navigationController?.setToolbarHidden(false, animated: animated) - - // remove cancel button if needed + // show toolbar + // remove cancel button if traitCollection.horizontalSizeClass == .compact { + navigationController?.setToolbarHidden(false, animated: animated) navigationItem.setRightBarButton(nil, animated: animated) } @@ -167,7 +168,6 @@ extension MainController: ButtonDelegates { } func didTapTOCButton() { - tableOfContentsController?.headings = JS.getTableOfContents(webView: webView) isShowingTableOfContents ? hideTableOfContents(animated: true) : showTableOfContents(animated: true) } diff --git a/Kiwix/JavaScripts/injection.js b/Kiwix/JavaScripts/injection.js index 2d894f4f..9fb36c6e 100644 --- a/Kiwix/JavaScripts/injection.js +++ b/Kiwix/JavaScripts/injection.js @@ -29,7 +29,7 @@ function TableOfContents () { var element = this.headings[i]; var rect = element.getBoundingClientRect(); - var isAboveTopBorder = rect.bottom < 0; + var isAboveTopBorder = rect.top - 10 < 0; var isBelowBottomBorder = viewHeight - rect.top < 0; if (isAboveTopBorder) { @@ -64,4 +64,4 @@ function TableOfContents () { } } -var tableOfContents = new TableOfContents(); \ No newline at end of file +var tableOfContents = new TableOfContents(); diff --git a/Kiwix/Operations/ArticleOperation.swift b/Kiwix/Operations/ArticleOperation.swift index 3edf9a2c..02bcb4ec 100644 --- a/Kiwix/Operations/ArticleOperation.swift +++ b/Kiwix/Operations/ArticleOperation.swift @@ -78,10 +78,13 @@ class ArticleLoadOperation: Procedure { OperationQueue.main.addOperation { _ = main.searchBar.resignFirstResponder() - main.hideTableOfContents(animated: true) main.presentingViewController?.dismiss(animated: self.animated, completion: nil) main.hideWelcome() + if main.traitCollection.horizontalSizeClass == .compact { + main.hideTableOfContents(animated: true) + } + let webView = main.webView if webView?.request?.url != url { webView?.loadRequest(request)