Module: ActionView::Helpers::CssBrowserSelector

Includes:
CaptureHelper, TagHelper, TextHelper
Defined in:
lib/action_view/helpers/css_browser_selector.rb

Instance Method Summary collapse

Instance Method Details

#body(html_options = {}, &block) ⇒ Object

Creates the body content element with css_browser_selectors added to its class attribute.



60
61
62
# File 'lib/action_view/helpers/css_browser_selector.rb', line 60

def body(html_options = {}, &block)
  add_css_browser_selectors_to_tag(:body, html_options, &block)
end

#css_browser_selector(tag = 'html', show_comments = true) ⇒ Object

Javascript version of the CSS Browser Selector, can be put inline into the page / layout by <%= javascript_tag css_browser_selector %>

Can pass in an tag name in which the script will place the css browser selectors: <%= javascript_tag css_browser_selector(‘body’)

To turn off comments for the smallest javascript possible, pass false as a second parameter: <%= javascript_tag css_browser_selector(‘body’, false)

This file is originally read off of disk from within the plugin’s lib at javascripts/css_browser_selector.js



22
23
24
25
# File 'lib/action_view/helpers/css_browser_selector.rb', line 22

def css_browser_selector(tag = 'html', show_comments = true)
  @javascript ||= ::CssBrowserSelector::Javascript.contents(show_comments)
  @javascript.gsub('html', tag)
end

#html(html_options = {}, &block) ⇒ Object

Creates the html content element with css_browser_selectors added to its class attribute. Includes by default the following attributes (which can be overridden):

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang=>"en" lang=>"en">


54
55
56
57
# File 'lib/action_view/helpers/css_browser_selector.rb', line 54

def html(html_options = {}, &block)
  html_options.reverse_merge!(:xmlns=>"http://www.w3.org/1999/xhtml", :"xml:lang"=>"en", :lang=>"en")
  add_css_browser_selectors_to_tag(:html, html_options, &block)
end

#javascript_to_add_js_to(tag) ⇒ Object

Page cached aware helper method that is equivalent to:

<%= javascript_tag window_on_load_add_js_to_tag(tag) unless controller.page_cached? %>

Example: if you are using the body content element:

<%= javascript_to_add_js_to :body %>


47
48
49
# File 'lib/action_view/helpers/css_browser_selector.rb', line 47

def javascript_to_add_js_to(tag)
  javascript_tag window_on_load_add_js_to_tag(tag) unless controller.page_cached?
end

#window_add_load_eventObject

Inline javascript to creates an addLoadEvent method on Window to allow onload functions to be chained together without clobbering any prior onloads that may have been attached. This can be added inline, standalone like so:

<%= javascript_tag window_add_load_event %>


31
32
33
# File 'lib/action_view/helpers/css_browser_selector.rb', line 31

def window_add_load_event
  %(window.addLoadEvent = function(f){var oldf=window.onload; window.onload=(typeof window.onload!='function')?f:function(){oldf();f();}})
end

#window_on_load_add_js_to_tag(tagname) ⇒ Object

Combines the window_add_load_event and window_add_js_to_tag methods to be run within one script element:

<%= javascript_tag window_on_load_add_js_to_tag(:body) %>


38
39
40
# File 'lib/action_view/helpers/css_browser_selector.rb', line 38

def window_on_load_add_js_to_tag(tagname)
  "#{window_add_load_event}\n#{window_add_js_to_tag(tagname)}"
end