mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 22:10:57 -04:00
toc position
This commit is contained in:
parent
795d129234
commit
8d594535ba
@ -158,6 +158,7 @@ class MainController: UIViewController {
|
|||||||
|
|
||||||
func configureTableOfContents() {
|
func configureTableOfContents() {
|
||||||
guard isShowingTableOfContents else {return}
|
guard isShowingTableOfContents else {return}
|
||||||
|
guard tableOfContentsController?.articleURL != article?.url else {return}
|
||||||
tableOfContentsController?.headings = JS.getTableOfContents(webView)
|
tableOfContentsController?.headings = JS.getTableOfContents(webView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +195,6 @@ class MainController: UIViewController {
|
|||||||
func tableOfContentButtonTapped(sender: UIBarButtonItem) {
|
func tableOfContentButtonTapped(sender: UIBarButtonItem) {
|
||||||
guard let _ = article else {return}
|
guard let _ = article else {return}
|
||||||
isShowingTableOfContents ? hideTableOfContentsController() : showTableOfContentsController()
|
isShowingTableOfContents ? hideTableOfContentsController() : showTableOfContentsController()
|
||||||
configureTableOfContents()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func showLibraryButtonTapped() {
|
func showLibraryButtonTapped() {
|
||||||
|
@ -54,11 +54,16 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
|
|||||||
article.thumbImagePath = URLResponseCache.shared.firstImage()?.path
|
article.thumbImagePath = URLResponseCache.shared.firstImage()?.path
|
||||||
self.article = article
|
self.article = article
|
||||||
|
|
||||||
|
// JS
|
||||||
|
JS.inject(webView)
|
||||||
|
JS.adjustFontSizeIfNeeded(webView)
|
||||||
|
if isShowingTableOfContents {
|
||||||
|
configureTableOfContents()
|
||||||
|
JS.startTOCCallBack(webView)
|
||||||
|
}
|
||||||
|
|
||||||
// UI Updates
|
// UI Updates
|
||||||
configureNavigationButtonTint()
|
configureNavigationButtonTint()
|
||||||
configureTableOfContents()
|
|
||||||
JS.adjustFontSizeIfNeeded(webView)
|
|
||||||
JS.inject(webView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
|
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
|
||||||
|
@ -13,8 +13,10 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV
|
|||||||
|
|
||||||
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var tableView: UITableView!
|
||||||
private let visibleHeaderIndicator = UIView()
|
private let visibleHeaderIndicator = UIView()
|
||||||
|
|
||||||
weak var delegate: TableOfContentsDelegate?
|
weak var delegate: TableOfContentsDelegate?
|
||||||
private var headinglevelMin = 0
|
private var headinglevelMin = 0
|
||||||
|
var articleURL: NSURL?
|
||||||
|
|
||||||
var headings = [HTMLHeading]() {
|
var headings = [HTMLHeading]() {
|
||||||
didSet {
|
didSet {
|
||||||
@ -38,6 +40,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV
|
|||||||
tableView.emptyDataSetSource = self
|
tableView.emptyDataSetSource = self
|
||||||
tableView.emptyDataSetDelegate = self
|
tableView.emptyDataSetDelegate = self
|
||||||
tableView.tableFooterView = UIView()
|
tableView.tableFooterView = UIView()
|
||||||
|
tableView.addSubview(visibleHeaderIndicator)
|
||||||
visibleHeaderIndicator.backgroundColor = UIColor.redColor()
|
visibleHeaderIndicator.backgroundColor = UIColor.redColor()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +53,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV
|
|||||||
func configureVisibleHeaderView(animated animated: Bool) {
|
func configureVisibleHeaderView(animated animated: Bool) {
|
||||||
// no visible header
|
// no visible header
|
||||||
guard visibleHeaderIDs.count > 0 else {
|
guard visibleHeaderIDs.count > 0 else {
|
||||||
visibleHeaderIndicator.removeFromSuperview()
|
visibleHeaderIndicator.hidden = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,13 +62,13 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV
|
|||||||
let maxIndex = headings.indexOf({$0.id == visibleHeaderIDs.last}) else {return}
|
let maxIndex = headings.indexOf({$0.id == visibleHeaderIDs.last}) else {return}
|
||||||
let topIndexPath = NSIndexPath(forRow: minIndex, inSection: 0)
|
let topIndexPath = NSIndexPath(forRow: minIndex, inSection: 0)
|
||||||
let bottomIndexPath = NSIndexPath(forRow: maxIndex, inSection: 0)
|
let bottomIndexPath = NSIndexPath(forRow: maxIndex, inSection: 0)
|
||||||
let topCell = tableView(tableView, cellForRowAtIndexPath: topIndexPath)
|
let topCellFrame = tableView.rectForRowAtIndexPath(topIndexPath)
|
||||||
let bottomCell = tableView(tableView, cellForRowAtIndexPath: bottomIndexPath)
|
let bottomCellFrame = tableView.rectForRowAtIndexPath(bottomIndexPath)
|
||||||
let top = topCell.frame.origin.y + topCell.frame.height * 0.1
|
let top = topCellFrame.origin.y + topCellFrame.height * 0.1
|
||||||
let bottom = bottomCell.frame.origin.y + bottomCell.frame.height * 0.9
|
let bottom = bottomCellFrame.origin.y + bottomCellFrame.height * 0.9
|
||||||
|
|
||||||
// indicator frame
|
// indicator frame
|
||||||
if !tableView.subviews.contains(visibleHeaderIndicator) {tableView.addSubview(visibleHeaderIndicator)}
|
visibleHeaderIndicator.hidden = false
|
||||||
if animated {
|
if animated {
|
||||||
UIView.animateWithDuration(0.1, animations: {
|
UIView.animateWithDuration(0.1, animations: {
|
||||||
self.visibleHeaderIndicator.frame = CGRectMake(0, top, 3, bottom - top)
|
self.visibleHeaderIndicator.frame = CGRectMake(0, top, 3, bottom - top)
|
||||||
@ -73,7 +76,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV
|
|||||||
} else {
|
} else {
|
||||||
visibleHeaderIndicator.frame = CGRectMake(0, top, 3, bottom - top)
|
visibleHeaderIndicator.frame = CGRectMake(0, top, 3, bottom - top)
|
||||||
}
|
}
|
||||||
|
|
||||||
// tableview scroll
|
// tableview scroll
|
||||||
let topCellVisible = tableView.indexPathsForVisibleRows?.contains(topIndexPath) ?? false
|
let topCellVisible = tableView.indexPathsForVisibleRows?.contains(topIndexPath) ?? false
|
||||||
let bottomCellVisible = tableView.indexPathsForVisibleRows?.contains(bottomIndexPath) ?? false
|
let bottomCellVisible = tableView.indexPathsForVisibleRows?.contains(bottomIndexPath) ?? false
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.1832</string>
|
<string>1.8.1862</string>
|
||||||
<key>ITSAppUsesNonExemptEncryption</key>
|
<key>ITSAppUsesNonExemptEncryption</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.8.1832</string>
|
<string>1.8.1862</string>
|
||||||
<key>NSExtension</key>
|
<key>NSExtension</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>NSExtensionMainStoryboard</key>
|
<key>NSExtensionMainStoryboard</key>
|
||||||
|
@ -115,18 +115,21 @@ function startCallBack() {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function callBack(visibleHeaderIDs) {
|
||||||
|
var parameter = visibleHeaderIDs.map(function(x){ return 'header=' + x }).join('&');
|
||||||
|
window.location = 'pagescroll:scrollEnded?' + parameter;
|
||||||
|
}
|
||||||
|
|
||||||
visibleHeaderIDs = getVisibleElementsChecker().getVisibleHeaderIDs();
|
visibleHeaderIDs = getVisibleElementsChecker().getVisibleHeaderIDs();
|
||||||
window.onscroll = function() {
|
window.onscroll = function() {
|
||||||
var newVisibleHeaderIDs = getVisibleElementsChecker().getVisibleHeaderIDs();
|
var newVisibleHeaderIDs = getVisibleElementsChecker().getVisibleHeaderIDs();
|
||||||
if (!arraysEqual(visibleHeaderIDs, newVisibleHeaderIDs)) {
|
if (!arraysEqual(visibleHeaderIDs, newVisibleHeaderIDs)) {
|
||||||
visibleHeaderIDs = newVisibleHeaderIDs;
|
visibleHeaderIDs = newVisibleHeaderIDs;
|
||||||
console.log(visibleHeaderIDs);
|
callBack(visibleHeaderIDs);
|
||||||
|
|
||||||
var parameter = visibleHeaderIDs.map(function(x){ return 'header=' + x }).join('&');
|
|
||||||
window.location = 'pagescroll:scrollEnded?' + parameter;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
callBack(visibleHeaderIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopCallBack() {
|
function stopCallBack() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user