Module: Waterpig::TinyMCETools

Defined in:
lib/waterpig/tinymce-tools.rb

Instance Method Summary collapse

Instance Method Details

#fill_in_tinymce(id, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/waterpig/tinymce-tools.rb', line 3

def fill_in_tinymce(id, options = {})
  content =
    case options
    when Hash
      content = options.fetch(:with)
    when String
      options
    else
      raise "Must pass a string or a hash containing 'with'"
    end

  case page.driver
  when Capybara::Selenium::Driver
    page.execute_script("$('##{id}').tinymce().setContent('#{content}')")
  when Capybara::Poltergeist::Driver
    within_frame("#{id}_ifr") do
      element = find("body")
      element.native.send_keys(content)
    end
  else
    raise "fill_in_tinymce called with unrecognized page.driver: #{page.driver.class.name}"
  end
end