Created
August 28, 2010 20:14
-
-
Save Achillefs/555528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
# Your own stuff | |
def ajax_actions opts = {} | |
container = opts.delete(:container) || "actions_container" | |
actions_selector = opts.delete(:actions_selector) || "td.actions a" | |
raise ArgumentError.new("Please specify a container element identifier") if container.empty? or container.nil? | |
raise ArgumentError.new("The action links selector cannot be empty") if actions_selector.empty? or actions_selector.nil? | |
html = %[<div id="#{container}"></div>\n] | |
html << javascript_tag(%[ | |
$("##{container}").hide(); | |
$("#{actions_selector}").bind("click",function(event){ | |
var element = $(this); | |
element.parent().addClass("loading"); | |
$.get(this.href,{},function(data){ | |
$("##{container}").html(data).css({ | |
position: 'absolute', | |
left: $(window).width()/2 - 200, | |
top: $(window).height()/2 - 200, | |
}).fadeIn("slow"); | |
element.parent().removeClass("loading"); | |
}); | |
return false; | |
});]) | |
end | |
def link_to_close_or_back | |
if request.xhr? | |
link_to("Close", "#close", {:id => "closedetails"}) + | |
javascript_tag(%[$("#closedetails").click(function(){$("#details_container").fadeOut("slow");return false;});]) | |
else | |
link_to("Back to previous page" , :back) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment