0

我有 2 个链接到 Ruby on Rails 上的 Fancyboxes:

链接 1 的课程是:“why_am_i_here fancybox” 链接 2 的课程是:“feedback_link fancybox”

当我第一次单击链接 1 时,我需要链接 2 的幻想框。如果我再次单击,它会将我带到正确的链接。另一个按钮(链接 2)正常工作。

与其用各种可能/可能不相关的代码侵入你,不如告诉我你需要什么进一步的信息,我会提供。

这是为why_am_i_here渲染的HTML(链接1):

$(function(){
    var search_value;
    $(".why_am_i_here_button, .fancybox").fancybox({
        type : 'iframe',
        autoSize : true,
        afterLoad : function(){
                $(".fancybox-iframe").contents().find(".feedback_link").remove();
                $(".fancybox-iframe").contents().find("#app_header_right").remove();
                $(".fancybox-iframe").contents().find("#feed").remove();
            $(".fancybox-iframe").contents().find("#search_submit").unbind("type"); 
            block_off_default_clicks();
            set_click_listeners();
            $(".fancybox-iframe").contents().find("#search_submit").click(function(e){
                e.preventDefault();
                parent.$.fancybox.close();

            });
        },
        beforeClose : function(){
            search_value = $(".fancybox-iframe").contents().find('#search').val();
        },
        afterClose : function(){
            if (search_value){
                $("#searchbox_holder").html("<%= escape_javascript(render 'restaurants/searchbox') %>");
                $("#search").attr("value", search_value);
                $("#user_edit_wrapper").hide();
                $(".search_form").submit();
            }
        }
    }).eq(0).click().stopPropagation();

});

这是为 feedback_link 渲染的 HTML(链接 2):

$(function(){
    $(".feedback_link, .fancybox").fancybox({
        type : 'iframe',
        afterLoad : function(){
            $(".fancybox-iframe").contents().find(".feedback_link").remove();
            $(".fancybox-iframe").contents().find("#feed").remove();
                $(".fancybox-iframe").contents().find("#app_header_right").remove();
            block_off_default_clicks();

            $(".fancybox-iframe").contents().find(".feedback_form").submit(function(e){
                parent.$.fancybox.close();
            });
        }
    }).eq(0).click().stopPropagation();

});

这是每个链接的 HTML:

链接1:

<div id = "why_am_i_here_container">
<%= link_to "Here\'s how it works", info_path(:welcome => params[:welcome]), :remote => true, :class => "why_am_i_here_button fancybox rounded-corner", :id => "why_am_i_here" %></div>

链接2:

<li class = "app_header_item"><%= link_to 'Feedback (please)', new_feedback_path, :remote => true, :class => "feedback_link fancybox", :id => "feedback_link" %></li>
4

1 回答 1

0

很难跟踪您在来回移动代码的操作,但我会做的是:

链接1:

<div id = "why_am_i_here_container">
<%= link_to "Here\'s how it works", info_path(:welcome => params[:welcome]), :remote => true, :class => "why_am_i_here_button rounded-corner", :id => "why_am_i_here" %>
</div>

链接 2

<li class = "app_header_item"><%= link_to 'Feedback (please)', new_feedback_path, :remote => true, :class => "feedback_link", :id => "feedback_link" %></li>

请注意fancybox,我从两个链接中删除了该类。

然后是 jQuery 代码:

$(function () {
    var search_value;
    $(".why_am_i_here_button").fancybox({
        // options for why_am_i_here_button
        type: "iframe" // etc
    });
    $(".feedback_link").fancybox({
        // options for feedback_link
        type: "iframe" // etc
    });
}); // ready

两个 init 都在同一个$(function(){})ready 方法中。上面的代码应该可以工作。

我不确定您使用.eq(0).click().stopPropagation();的是什么,但现在将其删除并测试您的链接。

于 2013-05-03T06:50:00.807 回答