Module: Erector::JQuery

Included in:
HTMLWidget, Widget
Defined in:
lib/erector/jquery.rb

Instance Method Summary collapse

Instance Method Details

#jquery(*args) ⇒ Object

Emits a jQuery script, inside its own script tag, that is to be run on document ready or load.

Usage (from inside a widget method):

jquery “alert('hi')”

a jquery ready handler

jquery “alert('hi')”, :id => 'foo'

a jquery ready handler, with attributes in the script tag

jquery :load, “alert('hi')”

a jquery load handler


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/erector/jquery.rb', line 10

def jquery(*args)
  event = if args.first.is_a? Symbol
    args.shift
  else
    :ready
  end
  txt = args.shift
  attributes = args.shift || {}

  javascript attributes do
    rawtext "\n"
    rawtext "jQuery(document).#{event}(function($){\n"
    rawtext txt
    rawtext "\n});"
  end
end

#jquery_load(text) ⇒ Object

:nodoc:


27
28
29
# File 'lib/erector/jquery.rb', line 27

def jquery_load(text)    #:nodoc:
  $stderr.puts "jquery_load is deprecated; use jquery(:load, text) instead"
end

#jquery_ready(text) ⇒ Object

:nodoc:


31
32
33
# File 'lib/erector/jquery.rb', line 31

def jquery_ready(text)    #:nodoc:
  $stderr.puts "jquery_ready is deprecated; use jquery(:ready, text) instead"
end