Sha256: e73a6abf40a2348a51d3d5d1822ab4303c44aab819df5663e718127ea5204ed8

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module Jquery
  module Helpers

    # Creates a link tag to a given url or path and ensures that the linke will be rendered
    # as jquery modal dialog
    #
    # ==== Signatures
    #
    #   link_to(body, url, html_options = {})
    #   link_to(body, url)
    #
    def link_to_modal(*args, &block)
      if block_given?
        options      = args.first || {}
        html_options = args.second
        block_result = yield(*args)
        link_to_modal(block_result, options, html_options)
      else
        name         = args[0]
        options      = args[1] || {}
        html_options = args[2] || {}

        # extend the html_options
        html_options[:rel] = "modal:open"
        if (html_options.has_key?(:remote))
          if (html_options[:remote] == true)
            html_options[:rel] = "modal:open:ajaxpost"
          end

          # remove the remote tag
          html_options.delete(:remote)
        end

        # check if we have an id
        html_options[:id] = UUIDTools::UUID.random_create().to_s unless html_options.has_key?(:id)

        # perform the normal link_to operation
        html_link = link_to(name, options, html_options)

        # emit both
        html_link.html_safe
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jquery-modal-rails-0.0.2 lib/jquery/modal/helpers/link_helpers.rb