Skip to content

Commit

Permalink
require a selector to load the request
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed May 26, 2015
1 parent 764891a commit 2045114
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions SCDomElementView/SCDomElementView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SCDomElementView: UIView, WKNavigationDelegate, UIScrollViewDelegat
}()

public var delegate: SCDomElementViewDelegate?
private var selector: String?

public override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -73,21 +74,24 @@ public class SCDomElementView: UIView, WKNavigationDelegate, UIScrollViewDelegat
}
}

public func loadRequest(request: NSURLRequest) {
public func showSelector(selector: String, withRequest request: NSURLRequest) {
self.selector = selector
delegate?.domElementViewDidStartRequest(self)
webView.loadRequest(request)
}

public func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
self.rectFromId("mobile") { rect in
var frame = rect
self.webView.scrollView.contentInset = UIEdgeInsets(top: -frame.origin.y, left: -frame.origin.x, bottom: (frame.origin.y + frame.size.height), right: (frame.origin.x + frame.size.width))
if let selector = selector {
self.rectFromId(selector) { rect in
var frame = rect
self.webView.scrollView.contentInset = UIEdgeInsets(top: -frame.origin.y, left: -frame.origin.x, bottom: (frame.origin.y + frame.size.height), right: (frame.origin.x + frame.size.width))

frame.origin = CGPointZero
self.frame = frame
self.webView.frame = frame
frame.origin = CGPointZero
self.frame = frame
self.webView.frame = frame

self.delegate?.domElementViewDidFinishRequest(self)
self.delegate?.domElementViewDidFinishRequest(self)
}
}
}
}
2 changes: 1 addition & 1 deletion iOS Example/iOS Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ViewController: UIViewController {
let request = NSMutableURLRequest(URL: nsUrl, cachePolicy: .ReturnCacheDataElseLoad, timeoutInterval: 30)
request.setValue("f28f3d351d03e881478ef0f3aae47113", forHTTPHeaderField: "OPAL-AUTH-TOKEN")

elementView.loadRequest(request)
elementView.showSelector("mobile", withRequest: request)
}
}

Expand Down

0 comments on commit 2045114

Please sign in to comment.