//
//  Copyright © 2015 Itty Bitty Apps. All rights reserved.

import UIKit

final class InfoViewController: UIViewController, SettableHomeItem {
  @IBOutlet private weak var imageView: UIImageView!
  @IBOutlet private weak var webView: UIWebView!
  @IBOutlet private weak var titleLabel: UILabel!

  var item: HomeItem?

  override func viewDidLoad() {
    super.viewDidLoad()

    guard let item = self.item else {
      fatalError("Item should be set before `-viewDidLoad`")
    }

    // Configure the view
    self.imageView.image = UIImage(named: item.iconName)
    self.titleLabel.text = item.title

    let htmlString = infoHTMLWithContent(item.infoFilename)
    self.webView.loadHTMLString(htmlString, baseURL: nil)
  }

  @IBAction func doneButtonTapped(sender: UIBarButtonItem) {
    self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  }
}

// MARK: UIWebViewDelegate
extension InfoViewController: UIWebViewDelegate {
  func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    if let URL = request.URL where URL != NSURL(string: "about:blank") {
      UIApplication.sharedApplication().openURL(URL)
      return false
    }
    return true
  }
}

//
//  Copyright © 2015 Itty Bitty Apps. All rights reserved.

import UIKit

final class InfoViewController: UIViewController, SettableHomeItem {
  @IBOutlet private weak var imageView: UIImageView!
  @IBOutlet private weak var webView: UIWebView!
  @IBOutlet private weak var titleLabel: UILabel!

  var item: HomeItem?

  override func viewDidLoad() {
    super.viewDidLoad()

    guard let item = self.item else {
      fatalError("Item should be set before `-viewDidLoad`")
    }

    // Configure the view
    self.imageView.image = UIImage(named: item.iconName)
    self.titleLabel.text = item.title

    self.webView.opaque = false
    self.webView.backgroundColor = UIColor.clearColor()
    
    let htmlString = infoHTMLWithContent(item.infoFilename)
    self.webView.loadHTMLString(htmlString, baseURL: nil)
  }

  @IBAction func doneButtonTapped(sender: UIBarButtonItem) {
    self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  }
}

// MARK: UIWebViewDelegate
extension InfoViewController: UIWebViewDelegate {
  func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    if let URL = request.URL where URL != NSURL(string: "about:blank") {
      UIApplication.sharedApplication().openURL(URL)
      return false
    }
    return true
  }
}

Remove black line along the bottom of webviews for the info view controller
Remove black line along the bottom of webviews for the info view controller

Fixes #23
