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

Commit

Permalink
Merge pull request #223 from smartmobilefactory/master
Browse files Browse the repository at this point in the history
Fix not working ClassBasedOnClickListener schemes
  • Loading branch information
hebertialmeida authored Apr 5, 2017
2 parents 019a6dd + 5672d71 commit 32f7133
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Source/FolioReaderPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
}

open func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
guard let webView = webView as? FolioReaderWebView else {
return true
}
guard
let webView = webView as? FolioReaderWebView,
let scheme = request.url?.scheme else {
return true
}

guard let url = request.url else { return false }

if url.scheme == "highlight" {
if scheme == "highlight" {

shouldShowBar = false

Expand All @@ -198,7 +200,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
menuIsVisible = true

return false
} else if url.scheme == "play-audio" {
} else if scheme == "play-audio" {

guard let decoded = url.absoluteString.removingPercentEncoding else { return false }
let playID = decoded.substring(from: decoded.index(decoded.startIndex, offsetBy: 13))
Expand All @@ -207,7 +209,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
FolioReader.shared.readerAudioPlayer?.playAudio(href, fragmentID: playID)

return false
} else if url.scheme == "file" {
} else if scheme == "file" {

let anchorFromURL = url.fragment

Expand Down Expand Up @@ -245,10 +247,10 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
}

return true
} else if url.scheme == "mailto" {
} else if scheme == "mailto" {
print("Email")
return true
} else if url.absoluteString != "about:blank" && url.scheme!.contains("http") && navigationType == .linkClicked {
} else if url.absoluteString != "about:blank" && scheme.contains("http") && navigationType == .linkClicked {

if #available(iOS 9.0, *) {
let safariVC = SFSafariViewController(url: request.url!)
Expand All @@ -262,17 +264,18 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe
}
return false
} else {
// Check if the url is a custom class based onClick listerner
var isClassBasedOnClickListenerScheme = false
for listener in readerConfig.classBasedOnClickListeners {
// Check if the url is a custom class based onClick listerner
var isClassBasedOnClickListenerScheme = false
for listener in readerConfig.classBasedOnClickListeners {

if url.scheme == listener.schemeName,
if
(scheme == listener.schemeName),
let absoluteURLString = request.url?.absoluteString,
let range = absoluteURLString.range(of: "/clientX=") {
let baseURL = absoluteURLString.substring(to: range.lowerBound)
let positionString = absoluteURLString.substring(from: range.lowerBound)
if let point = getEventTouchPoint(fromPositionParameterString: positionString) {
let attributeContentString = (baseURL.replacingOccurrences(of: "\(url.scheme)://", with: "").removingPercentEncoding)
let attributeContentString = (baseURL.replacingOccurrences(of: "\(scheme)://", with: "").removingPercentEncoding)
// Call the on click action block
listener.onClickAction(attributeContentString, point)
// Mark the scheme as class based click listener scheme
Expand Down

0 comments on commit 32f7133

Please sign in to comment.