class Formotion::RowType::WebViewRow
Constants
- WEB_VIEW_TAG
Public Instance Methods
build_cell(cell)
click to toggle source
# File lib/formotion/row_type/web_view_row.rb, line 29 def build_cell(cell) cell.selectionStyle = self.row.selection_style || UITableViewCellSelectionStyleBlue @loading = true @web_view = UIWebView.alloc.init @web_view.delegate = self set_page observe(self.row, "value") do |old_value, new_value| break_with_semaphore do set_page end end @web_view.tag = WEB_VIEW_TAG @web_view.contentMode = UIViewContentModeScaleAspectFit @web_view.backgroundColor = UIColor.clearColor cell.addSubview(@web_view) cell.swizzle(:layoutSubviews) do def layoutSubviews old_layoutSubviews # viewWithTag is terrible, but I think it's ok to use here... formotion_field = self.viewWithTag(WEB_VIEW_TAG) field_frame = formotion_field.frame field_frame.origin.y = 10 field_frame.origin.x = self.textLabel.frame.origin.x + self.textLabel.frame.size.width + Formotion::RowType::Base.field_buffer field_frame.size.width = self.frame.size.width - field_frame.origin.x - Formotion::RowType::Base.field_buffer field_frame.size.height = self.frame.size.height - Formotion::RowType::Base.field_buffer formotion_field.frame = field_frame end end end
layoutSubviews()
click to toggle source
# File lib/formotion/row_type/web_view_row.rb, line 49 def layoutSubviews old_layoutSubviews # viewWithTag is terrible, but I think it's ok to use here... formotion_field = self.viewWithTag(WEB_VIEW_TAG) field_frame = formotion_field.frame field_frame.origin.y = 10 field_frame.origin.x = self.textLabel.frame.origin.x + self.textLabel.frame.size.width + Formotion::RowType::Base.field_buffer field_frame.size.width = self.frame.size.width - field_frame.origin.x - Formotion::RowType::Base.field_buffer field_frame.size.height = self.frame.size.height - Formotion::RowType::Base.field_buffer formotion_field.frame = field_frame end
loading()
click to toggle source
# File lib/formotion/row_type/web_view_row.rb, line 25 def loading @loading end
on_select(tableView, tableViewDelegate)
click to toggle source
# File lib/formotion/row_type/web_view_row.rb, line 65 def on_select(tableView, tableViewDelegate) if !row.editable? return end end
set_page()
click to toggle source
# File lib/formotion/row_type/web_view_row.rb, line 10 def set_page if row.value =~/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?\/?([a-zA-Z0-9\-\._\?\,\'\/\+&%\$#\=~])*$/ @loading = true req = NSURLRequest.requestWithURL(NSURL.URLWithString(row.value)) @web_view.loadRequest(req) else @web_view.loadHTMLString(row.value, baseURL:nil) if row.value @loading = false end end
stringByEvaluatingJavaScriptFromString(script)
click to toggle source
# File lib/formotion/row_type/web_view_row.rb, line 21 def stringByEvaluatingJavaScriptFromString(script) @web_view.stringByEvaluatingJavaScriptFromString(script) end
webViewDidFinishLoad(web_view)
click to toggle source
def webViewDidStartLoad(web_view) end
# File lib/formotion/row_type/web_view_row.rb, line 77 def webViewDidFinishLoad(web_view) @loading = false end