From 5e8df0533ed08174dcd2ba0997a2f4ed1f25c27e Mon Sep 17 00:00:00 2001 From: Strugaru Alexandra Date: Mon, 20 Mar 2017 11:16:21 +0100 Subject: [PATCH 1/4] unwrapped url scheme in Folio reader page --- Source/FolioReaderPage.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index 8841c86df..c3ee639b2 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -266,7 +266,8 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe var isClassBasedOnClickListenerScheme = false for listener in readerConfig.classBasedOnClickListeners { - if url.scheme == listener.schemeName, + if let _urlScheme = url.scheme, + (_urlScheme == listener.schemeName), let absoluteURLString = request.url?.absoluteString, let range = absoluteURLString.range(of: "/clientX=") { let baseURL = absoluteURLString.substring(to: range.lowerBound) From 00d5790a7a6fba68ea8c9fb59b437b0ce5466d92 Mon Sep 17 00:00:00 2001 From: Strugaru Alexandra Date: Tue, 21 Mar 2017 10:27:48 +0100 Subject: [PATCH 2/4] unwrapped optional --- Source/FolioReaderPage.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index c3ee639b2..a18b0d24f 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -273,7 +273,7 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe 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: "\(_urlScheme)://", with: "").removingPercentEncoding) // Call the on click action block listener.onClickAction(attributeContentString, point) // Mark the scheme as class based click listener scheme From 3171e75cbd11f42eef3e413b3ba1601b134adf28 Mon Sep 17 00:00:00 2001 From: Hans Seiffert Date: Wed, 22 Mar 2017 15:21:40 +0100 Subject: [PATCH 3/4] Fix not working ClassBasedOnClickListener schemes --- Source/FolioReaderPage.swift | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index a18b0d24f..776e6d82e 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -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 @@ -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)) @@ -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 @@ -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!) @@ -266,14 +268,14 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe var isClassBasedOnClickListenerScheme = false for listener in readerConfig.classBasedOnClickListeners { - if let _urlScheme = url.scheme, - (_urlScheme == 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: "\(_urlScheme)://", 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 From 5672d71fcdf7140b1669fdeed7ad178c6d099850 Mon Sep 17 00:00:00 2001 From: Hans Seiffert Date: Wed, 22 Mar 2017 15:26:24 +0100 Subject: [PATCH 4/4] Use spaces instead of tabs for indentation --- Source/FolioReaderPage.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index 776e6d82e..221138e33 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -180,11 +180,11 @@ open class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRe } open func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool { - guard - let webView = webView as? FolioReaderWebView, - let scheme = request.url?.scheme 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 } @@ -264,12 +264,12 @@ 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 - (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)