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() {
|
||||
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() {
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.1832</string>
|
||||
<string>1.8.1862</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.1832</string>
|
||||
<string>1.8.1862</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
@ -116,17 +116,20 @@ 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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user