Module: Rad::Html::JavascriptHelper

Defined in:
lib/rad/html/_helpers/javascript_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deferObject



25
# File 'lib/rad/html/_helpers/javascript_helper.rb', line 25

def self.defer; @defer ||= true end

.defer=(value) ⇒ Object



26
# File 'lib/rad/html/_helpers/javascript_helper.rb', line 26

def self.defer= value; @defer = value end

Instance Method Details

#call_deferred_jsObject



17
18
19
# File 'lib/rad/html/_helpers/javascript_helper.rb', line 17

def call_deferred_js
  javascript_tag 'rad.callDeferred();', defer: false
end

#javascript_include_tag(*scripts) ⇒ Object



2
3
4
5
6
# File 'lib/rad/html/_helpers/javascript_helper.rb', line 2

def javascript_include_tag *scripts
  scripts.collect{|script|
    tag :script, '', src: "#{script}", type: "text/javascript"
  }.join("\n")
end

#javascript_tag(script = nil, options = {}, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/rad/html/_helpers/javascript_helper.rb', line 8

def javascript_tag script = nil, options = {}, &block
  script = capture &block if block
  if options[:defer] or (!options.include?(:defer) and Rad::Html::JavascriptHelper.defer)
    script = "rad.defer(function(){#{script}});"
  end
  html = tag :script, script, {type: "text/javascript"}
  block ? concat(html) : html
end

#js(obj) ⇒ Object

Escape



22
# File 'lib/rad/html/_helpers/javascript_helper.rb', line 22

def js obj; obj.to_s.js_escape end