Sha256: 70593c6bc728edad25360a4b8194b228b487b74e7afa1d7a263ad339a0710c58
Contents?: true
Size: 1.63 KB
Versions: 3
Compression:
Stored size: 1.63 KB
Contents
module Crystal module ViewUrlHelper # # links # def link_to *args, &block # parse args content = if block capture(&block) else args.shift end special = nil html_options = if args.last.is_a?(Hash) if args[-2].is_a?(Hash) args.pop.stringify_keys! else {} end else args << {} {} end # build url url = special_url(*args) || url_for(*args) # add javascript add_js_link_options! url, html_options tag :a, content, html_options.merge('href' => url) end # TODO3 refactor to use data-remote, data-method, data-confirm def add_js_link_options! url, html_options confirm, remote, method = html_options.delete("confirm"), html_options.delete('remote'), html_options.delete("method") remote ||= config.remote_link_formats!.include? url.marks.format.to_s onclick = if remote method ||= :get %{$(this).link_to({method: '#{method}', ajax: true}); return false;} elsif method %{$(this).link_to({method: '#{method}'}); return false;} else nil end # if onclick and ActionController::Base.defer_static_scripts? # html_options['class'] ||= "" # end if confirm onclick = if onclick "if(confirm(#{confirm.js_escape})){#{onclick}}; return false;" else "return confirm(#{confirm.js_escape});" end end html_options["onclick"] = onclick if onclick end end end
Version data entries
3 entries across 3 versions & 2 rubygems