diff --git a/Kiwix-iOS/Controller/Main/MainController.swift b/Kiwix-iOS/Controller/Main/MainController.swift index 33f59fb1..5eb9a271 100644 --- a/Kiwix-iOS/Controller/Main/MainController.swift +++ b/Kiwix-iOS/Controller/Main/MainController.swift @@ -158,6 +158,7 @@ class MainController: UIViewController { func configureTableOfContents() { guard isShowingTableOfContents else {return} + guard tableOfContentsController?.articleURL != article?.url else {return} tableOfContentsController?.headings = JS.getTableOfContents(webView) } @@ -194,7 +195,6 @@ class MainController: UIViewController { func tableOfContentButtonTapped(sender: UIBarButtonItem) { guard let _ = article else {return} isShowingTableOfContents ? hideTableOfContentsController() : showTableOfContentsController() - configureTableOfContents() } func showLibraryButtonTapped() { diff --git a/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift b/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift index 9ea61231..57d53fe8 100644 --- a/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift +++ b/Kiwix-iOS/Controller/Main/MainControllerDelegates.swift @@ -54,11 +54,16 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT article.thumbImagePath = URLResponseCache.shared.firstImage()?.path self.article = article + // JS + JS.inject(webView) + JS.adjustFontSizeIfNeeded(webView) + if isShowingTableOfContents { + configureTableOfContents() + JS.startTOCCallBack(webView) + } + // UI Updates configureNavigationButtonTint() - configureTableOfContents() - JS.adjustFontSizeIfNeeded(webView) - JS.inject(webView) } func webView(webView: UIWebView, didFailLoadWithError error: NSError) { diff --git a/Kiwix-iOS/Controller/Others/TableOfContentsController.swift b/Kiwix-iOS/Controller/Others/TableOfContentsController.swift index fd728078..d7360f79 100644 --- a/Kiwix-iOS/Controller/Others/TableOfContentsController.swift +++ b/Kiwix-iOS/Controller/Others/TableOfContentsController.swift @@ -13,8 +13,10 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV @IBOutlet weak var tableView: UITableView! private let visibleHeaderIndicator = UIView() + weak var delegate: TableOfContentsDelegate? private var headinglevelMin = 0 + var articleURL: NSURL? var headings = [HTMLHeading]() { didSet { @@ -38,6 +40,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self tableView.tableFooterView = UIView() + tableView.addSubview(visibleHeaderIndicator) visibleHeaderIndicator.backgroundColor = UIColor.redColor() } @@ -50,7 +53,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV func configureVisibleHeaderView(animated animated: Bool) { // no visible header guard visibleHeaderIDs.count > 0 else { - visibleHeaderIndicator.removeFromSuperview() + visibleHeaderIndicator.hidden = true return } @@ -59,13 +62,13 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV let maxIndex = headings.indexOf({$0.id == visibleHeaderIDs.last}) else {return} let topIndexPath = NSIndexPath(forRow: minIndex, inSection: 0) let bottomIndexPath = NSIndexPath(forRow: maxIndex, inSection: 0) - let topCell = tableView(tableView, cellForRowAtIndexPath: topIndexPath) - let bottomCell = tableView(tableView, cellForRowAtIndexPath: bottomIndexPath) - let top = topCell.frame.origin.y + topCell.frame.height * 0.1 - let bottom = bottomCell.frame.origin.y + bottomCell.frame.height * 0.9 + let topCellFrame = tableView.rectForRowAtIndexPath(topIndexPath) + let bottomCellFrame = tableView.rectForRowAtIndexPath(bottomIndexPath) + let top = topCellFrame.origin.y + topCellFrame.height * 0.1 + let bottom = bottomCellFrame.origin.y + bottomCellFrame.height * 0.9 // indicator frame - if !tableView.subviews.contains(visibleHeaderIndicator) {tableView.addSubview(visibleHeaderIndicator)} + visibleHeaderIndicator.hidden = false if animated { UIView.animateWithDuration(0.1, animations: { self.visibleHeaderIndicator.frame = CGRectMake(0, top, 3, bottom - top) @@ -73,7 +76,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV } else { visibleHeaderIndicator.frame = CGRectMake(0, top, 3, bottom - top) } - + // tableview scroll let topCellVisible = tableView.indexPathsForVisibleRows?.contains(topIndexPath) ?? false let bottomCellVisible = tableView.indexPathsForVisibleRows?.contains(bottomIndexPath) ?? false diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 4d6c4d36..cc422a71 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -49,7 +49,7 @@ CFBundleVersion - 1.8.1832 + 1.8.1862 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist index cb4fbb1d..34cf59f5 100644 --- a/Kiwix-iOSWidgets/Bookmarks/Info.plist +++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.8.1832 + 1.8.1862 NSExtension NSExtensionMainStoryboard diff --git a/Kiwix/JavaScripts/injection.js b/Kiwix/JavaScripts/injection.js index ecd4f649..67f6e9bd 100644 --- a/Kiwix/JavaScripts/injection.js +++ b/Kiwix/JavaScripts/injection.js @@ -115,18 +115,21 @@ function startCallBack() { } return true; } + + function callBack(visibleHeaderIDs) { + var parameter = visibleHeaderIDs.map(function(x){ return 'header=' + x }).join('&'); + window.location = 'pagescroll:scrollEnded?' + parameter; + } visibleHeaderIDs = getVisibleElementsChecker().getVisibleHeaderIDs(); window.onscroll = function() { var newVisibleHeaderIDs = getVisibleElementsChecker().getVisibleHeaderIDs(); if (!arraysEqual(visibleHeaderIDs, newVisibleHeaderIDs)) { visibleHeaderIDs = newVisibleHeaderIDs; - console.log(visibleHeaderIDs); - - var parameter = visibleHeaderIDs.map(function(x){ return 'header=' + x }).join('&'); - window.location = 'pagescroll:scrollEnded?' + parameter; + callBack(visibleHeaderIDs); } }; + callBack(visibleHeaderIDs); } function stopCallBack() {