Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Add pageWillLoad() delegate method #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ var isScrolling = false
/// Protocol which is used from `FolioReaderCenter`s.
@objc public protocol FolioReaderCenterDelegate: class {

/**
Notifies that page did load. A page load doesn't mean that this page is displayed right away, use `pageDidAppear` to get informed about the appearance of a page.

- parameter page: The loaded page
*/
optional func pageDidLoad(page: FolioReaderPage)

/**
Notifies that a page appeared. This is triggered is a page is chosen and displayed.

Expand All @@ -50,6 +43,7 @@ public class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICo

/// This delegate receives the events from the current `FolioReaderPage`s delegate.
public weak var delegate: FolioReaderCenterDelegate?
public weak var pageDelegate: FolioReaderPageDelegate?

var collectionView: UICollectionView!
let collectionViewLayout = UICollectionViewFlowLayout()
Expand Down Expand Up @@ -1127,9 +1121,14 @@ extension FolioReaderCenter: FolioReaderPageDelegate {
page.webView.scrollView.setContentOffset(offsetPoint, animated: false)
}

// Pass the event to the reader center delegate
delegate?.pageDidLoad?(page)
// Pass the event to the centers `pageDelegate`
pageDelegate?.pageDidLoad?(page)
}

public func pageWillLoad(page: FolioReaderPage) {
// Pass the event to the centers `pageDelegate`
pageDelegate?.pageWillLoad?(page)
}
}

// MARK: FolioReaderChapterListDelegate
Expand Down
26 changes: 18 additions & 8 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ import UIMenuItem_CXAImageSupport
import JSQWebViewController

/// Protocol which is used from `FolioReaderPage`s.
protocol FolioReaderPageDelegate: class {
/**
Notify that page did loaded

- parameter page: The loaded page
*/
func pageDidLoad(page: FolioReaderPage)
@objc public protocol FolioReaderPageDelegate: class {

/**
Notify that the page will be loaded. Note: The webview content itself is already loaded at this moment. But some java script operations like the adding of class based on click listeners will happen right after this method. If you want to perform custom java script before this happens this method is the right choice. If you want to modify the html content (and not run java script) you have to use `htmlContentForPage()` from the `FolioReaderCenterDelegate`.

- parameter page: The loaded page
*/
optional func pageWillLoad(page: FolioReaderPage)

/**
Notifies that page did load. A page load doesn't mean that this page is displayed right away, use `pageDidAppear` to get informed about the appearance of a page.

- parameter page: The loaded page
*/
optional func pageDidLoad(page: FolioReaderPage)
}

public class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecognizerDelegate {
Expand Down Expand Up @@ -137,6 +145,8 @@ public class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGesture

public func webViewDidFinishLoad(webView: UIWebView) {

delegate?.pageWillLoad?(self)

// Add the custom class based onClick listener
self.setupClassBasedOnClickListeners()

Expand All @@ -161,7 +171,7 @@ public class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGesture
self.webView.createMenu(options: false)
}

delegate?.pageDidLoad(self)
delegate?.pageDidLoad?(self)
}

public func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
Expand Down