         
         delegate.pageDidLoad!(self)
     }
-    
 }

    }
    
    func loadHTMLString(string: String) {
        if hasWebKit {
            var castWebView = (webView as! WKWebView)
            castWebView.alpha = 0
            castWebView.loadHTMLString(string, baseURL: nil)
        } else {
            var castWebView = (webView as! UIWebView)
            castWebView.alpha = 0
            castWebView.loadHTMLString(string, baseURL: nil)
        }
    }
    
    // MARK: - WKWebView Navigation Delegate
    
    func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
        if scrollDirection == .Down {
            let bottomOffset = CGPointMake(0, webView.scrollView.contentSize.height - webView.scrollView.bounds.height)
            if bottomOffset.y >= 0 {
                dispatch_async(dispatch_get_main_queue(), {
                    webView.scrollView.setContentOffset(bottomOffset, animated: false)
                })
            }
        }
        
        UIView.animateWithDuration(0.2, animations: { () -> Void in
            webView.alpha = 1
        })
        
        delegate.pageDidLoad!(self)
    }
    
    // MARK: - UIWebView Delegate

//

import UIKit

@objc protocol FolioPageDelegate {
    optional func pageDidLoad(page: FolioReaderPage)
}

class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate {
    
    var webView: UIWebView!
    var delegate: FolioPageDelegate!
    
    // MARK: - View life cicle
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.whiteColor()
        
        if webView == nil {
            webView = UIWebView(frame: self.bounds)
        }
        
        webView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
        webView.delegate = self
        webView.backgroundColor = UIColor.whiteColor()
        self.addSubview(webView)
    }

    required init(coder aDecoder: NSCoder) {
