为jquery bubble-popup实现click事件

时间:2013-04-26 21:51:06

标签: javascript jquery jquery-click-event bubble-popup

我正在尝试在我的网站上实现jquery-bubble-popup但是我完全卡住了。我正在努力做到以下几点。

  1. 如果有人点击“报告信息”div,则会显示与该报告相关的气泡弹出窗口。
  2. 我希望能够在弹出窗口中更改内容,然后单击“提交”,将该数据发布到该服务器。
  3. 如果在弹出窗口外点击一下。我希望它只是关闭。
  4. 非常简单的设置,但我拉我的头发。如果没有乱七八糟的话,就无法关闭弹出窗口。

    小提琴http://jsfiddle.net/rECnm/1/

    jQueryBubblePopup http://www.maxvergelli.com/jquery-bubble-popup

    代码

    $(document).ready(function () {
        $('div.emailReportIcon').CreateBubblePopup({
            manageMouseEvents: false
        });
        $('div.emailReportIcon').click(function (event) {
            var button = $(this);
            var email = button.attr("data-email");
            var message = '<div style="padding:10px;width: 250px;"><p><input type="checkbox"> Email me when new reports are ready.</p>' + '<p>Email Address<br /><input type="text" value="' + email + '"></p>' + '<div >' + '<input type="image" name="submit" value="submit"  class="submitButton">' + '</div></div>';
            button.ShowBubblePopup({
                manageMouseEvents: false,
                position: 'bottom',
                align: 'left',
                tail: {
                    align: 'left'
                },
                innerHtml: message,
                innerHtmlStyle: {
                    color: '#000',
                    'text-align': 'left'
                },
                themePath: 'http://www.maxvergelli.com/docs/jquery-bubble-popup-examples/images/jquerybubblepopup-themes',
                alwaysVisible: false,
                closingDelay: 200,
                selectable: true
            });
        });
    });
    

1 个答案:

答案 0 :(得分:2)

http://jsfiddle.net/rECnm/9/

var button = false;
var active = true;
$(document).ready(function () {
    $('div.emailReportIcon').CreateBubblePopup({
        manageMouseEvents: false
    });
    $('div.emailReportIcon').click(function (event) {
        resetActiveBubble();
        button = $(this);
        active = true;
        var email = button.attr("data-email");
        var message = '<div style="padding:10px;width: 250px;"><p><input type="checkbox"> Email me when new reports are ready.</p>' + '<p>Email Address<br /><input type="text" value="' + email + '"></p>' + '<div >' + '<input type="image" name="submit" value="submit"  class="submitButton">' + '</div></div>';
        button.ShowBubblePopup({
            manageMouseEvents: false,
            position: 'bottom',
            align: 'left',
            tail: {
                align: 'left'
            },
            innerHtml: message,
            innerHtmlStyle: {
                color: '#000',
                'text-align': 'left'
            },
            themePath: 'http://www.maxvergelli.com/docs/jquery-bubble-popup-examples/images/jquerybubblepopup-themes',
            alwaysVisible: false,
            closingDelay: 200,
            selectable: true,
            afterShown: function() {
                active = false;
                $(".jquerybubblepopup").bind("mouseenter",function() {
                    active = true;
                }).bind("mouseleave", function() {
                    active = false; 
                });
            }
        });
    });
    $(window).bind('click',function() {
        resetActiveBubble();
    });
});
function resetActiveBubble() {
    if ( button && active == false ) {
        button.RemoveBubblePopup();
        button.CreateBubblePopup({
            manageMouseEvents: false
        });    
    }
}

上面的代码有一个窗口点击监听器和一个布尔变量来确定气泡是否“活动”(例如鼠标位于气泡上)。

此解决方案无法解析ipads等(您需要触摸侦听器),并且在使用jsfiddle时,您仍然可以通过在加载期间单击它来关闭气泡;在激活AfterShown之后,活动状态才会被附加。

我确信它可以被优化(还要注意jsfiddle中的console.logs)。我希望这会有所帮助。