Sha256: b10fab38b10e4756c5ac25bcfd8ed33b5a2c85f6917264e60ad8c44a6a444fc4

Contents?: true

Size: 1020 Bytes

Versions: 8

Compression:

Stored size: 1020 Bytes

Contents

module Erector
  module JQuery
    # 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
    #
    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

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

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

  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
erector-0.10.0 lib/erector/jquery.rb
erector-0.9.0 lib/erector/jquery.rb
erector-0.9.0.pre1 lib/erector/jquery.rb
erector-0.8.3 lib/erector/jquery.rb
erector-0.8.2 lib/erector/jquery.rb
honkster-erector-0.8.1 lib/erector/jquery.rb
erector-0.8.1 lib/erector/jquery.rb
erector-0.8.0 lib/erector/jquery.rb