Skip to content

Commit

Permalink
Making dialog_link work with multiple DOM IDs and templates in one call
Browse files Browse the repository at this point in the history
  • Loading branch information
Winton Welsh committed Aug 1, 2008
1 parent 4910a36 commit f48ebd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
19 changes: 12 additions & 7 deletions dialog_link/javascripts/init.js
@@ -1,15 +1,20 @@
<% templates.each do |template| -%>
<% id = template.respond_to?(:keys) ? template.keys.first : template -%>
<% template = template.respond_to?(:keys) ? template[id] : template -%>
$('<%= id %>').addEvent('click', function(e) {
Global.dialog.render({ element: $('template_<%= template %>').render(<%= options.to_json %>) });
return false;
});
<% end -%>
<% urls.each do |id, url| -%>
$('<%= id %>').addEvent('click', function(e) {
<% case resource_type -%>
<% when :url -%>
Global.dialog.render({
url: this.get('href'),
url: <%= url ? url.inspect : 'null' %> || this.get('href'),
data: {
authenticity_token: Global.authenticity_token,
implementation: 'eborhood/widgets'
}
});
<% when :template -%>
Global.dialog.render({ element: $('template_<%= id %>').render(<%= options.to_json %>) });
<% end -%>
return false;
});
});
<% end -%>
6 changes: 4 additions & 2 deletions dialog_link/options.rb
@@ -1,4 +1,6 @@
{
:id => 'dialog_link',
:resource_type => :url # :template or :url
#:templates => [ :id_and_template, { :dom_id_here => 'template' } ],
:templates => [],
#:urls => { :dom_id_here => '/some_resource' }
:urls => []
}

0 comments on commit f48ebd4

Please sign in to comment.