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.0.17 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.16 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.15 lib/rad/html/_helpers/javascript_helper.rb
rad_core-0.0.14 lib/rad/html/_helpers/javascript_helper.rb