Sha256: 8c5d2273b81c0317769fdf74dd220ff9c8d3781f4a83e6decaae4f2ccde1989b

Contents?: true

Size: 778 Bytes

Versions: 24

Compression:

Stored size: 778 Bytes

Contents

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

  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
  
  def call_deferred_js
    javascript_tag 'rad.callDeferred();', defer: false
  end

  # Escape
  def js obj; obj.to_s.js_escape end
  
  
  def self.defer; @defer ||= true end
  def self.defer= value; @defer = value end        
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rad_core-0.2.6 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.2.5 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.2.4 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.2.3 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.2.2 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.2.1 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.2.0 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.30 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.29 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.28 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.27 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.26 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.25 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.24 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.23 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.22 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.21 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.20 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.19 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.18 lib/rad/html/_helpers/javascript_helper.rb