mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 13:59:04 -04:00
refactor
This commit is contained in:
parent
9bd8c3e462
commit
c1a40805ad
@ -1,5 +1,5 @@
|
||||
//
|
||||
// JSInjection.swift
|
||||
// JS.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 9/9/16.
|
||||
@ -9,13 +9,12 @@
|
||||
import UIKit
|
||||
import JavaScriptCore
|
||||
|
||||
class JSInjection {
|
||||
class JS {
|
||||
|
||||
class func inject(webView: UIWebView) {
|
||||
let context = webView.valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as? JSContext
|
||||
let path = NSBundle.mainBundle().pathForResource("injection", ofType: "js")
|
||||
let jString = try? String(contentsOfFile: path!)
|
||||
context?.evaluateScript(jString!)
|
||||
webView.context.evaluateScript(jString!)
|
||||
}
|
||||
|
||||
class func adjustFontSizeIfNeeded(webView: UIWebView) {
|
||||
@ -48,3 +47,9 @@ class JSInjection {
|
||||
return snippet == "null" ? nil : snippet
|
||||
}
|
||||
}
|
||||
|
||||
extension UIWebView {
|
||||
var context: JSContext {
|
||||
return valueForKeyPath("documentView.webView.mainFrame.javaScriptContext") as! JSContext
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ class MainController: UIViewController {
|
||||
|
||||
func configureTableOfContents() {
|
||||
guard isShowingTableOfContents else {return}
|
||||
tableOfContentsController?.headings = JSInjection.getTableOfContents(webView)
|
||||
tableOfContentsController?.headings = JS.getTableOfContents(webView)
|
||||
}
|
||||
|
||||
func configureUserActivity() {
|
||||
|
@ -44,15 +44,15 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
|
||||
// Create article object
|
||||
guard let url = webView.request?.URL,
|
||||
let article = Article.addOrUpdate(url: url, context: NSManagedObjectContext.mainQueueContext) else {return}
|
||||
article.title = JSInjection.getTitle(from: webView)
|
||||
article.title = JS.getTitle(from: webView)
|
||||
article.thumbImagePath = URLResponseCache.shared.firstImage()?.path
|
||||
self.article = article
|
||||
|
||||
// UI Updates
|
||||
configureNavigationButtonTint()
|
||||
configureTableOfContents()
|
||||
JSInjection.adjustFontSizeIfNeeded(webView)
|
||||
JSInjection.inject(webView)
|
||||
JS.adjustFontSizeIfNeeded(webView)
|
||||
JS.inject(webView)
|
||||
}
|
||||
|
||||
func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
|
||||
@ -83,7 +83,7 @@ extension MainController: UIWebViewDelegate, SFSafariViewControllerDelegate, LPT
|
||||
|
||||
article.isBookmarked = !article.isBookmarked
|
||||
if article.isBookmarked {article.bookmarkDate = NSDate()}
|
||||
if article.snippet == nil {article.snippet = JSInjection.getSnippet(webView)}
|
||||
if article.snippet == nil {article.snippet = JS.getSnippet(webView)}
|
||||
|
||||
// let cloudKitUpdateOperation = BookmarkCloudKitOperation(article: article)
|
||||
// GlobalQueue.shared.addOperation(cloudKitUpdateOperation)
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.1783</string>
|
||||
<string>1.8.1787</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.1783</string>
|
||||
<string>1.8.1787</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
Loading…
x
Reference in New Issue
Block a user