1

我们使用 BeautyTips 作为一种机制来创建各种气泡以与用户交流。例如,我们有一个帮助图标,它显示一个包含更多信息的气泡。我们还使用 BT 来显示错误和警告消息。

这是实践中的样子。

大量错误消息堆叠在一起。

您可以看到错误消息一个接一个地堆叠在一起,并且使它们的父消息枯萎。

在 form_validator 我有一个用于 errorPlacement 参数的函数:

    errorPlacement: function (er, el) {
        if (el && el.length > 0) {
            if (el.attr('id') == 'ContractOpenEnded') {
                createErrorBubble($('#contractDuration'), er.text())
            }
            else {
                createErrorBubble($(el), er.text());
            }
        }
    }

以下是创建这些气泡的繁重功能。

function createErrorBubble(element, text) {    
    // In a conversation with pcobar the spec was changed for the bubbles to be to the right of the element
    createBubble(element, text, 2, "none", "right", "#fe0000", "#b2cedc", "#ffffff", true);
    element.btOn();
}

这里是 createBubble 函数。

function createBubble(element, content, messageType, trigger, positions, fillColor, strokeColor, foreColor, useShadow) {
    var btInstance = element.bt(
        content,
        {
            trigger: trigger,
            positions: positions,
            shrinkToFit: true,
            spikeLength: 12,
            showTip: function (box) {
                $(box).fadeIn(100);
            },
            hideTip: function (box, callback) {
                $(box).animate({ opacity: 0 }, 100, callback);
            },
            fill: fillColor,
            strokeStyle: strokeColor,
            shadow: useShadow,
            clickAnywhereToClose: false,
            closeWhenOthersOpen: false, // Closing when others open hides page validation errors. This should be false.
            preShow: function (box) {
                if (messageType != 1) return;

                var whiteboard = $($(box).children()[0]);
                var content = whiteboard.html();

                if (content.substr(0, 5).toLowerCase() == "<div>") {
                    content = content.substr(5, content.length -11);
                }

                whiteboard.html('<div><span class="helpWarningPrefix">Warning:</span> ' + content + "</div>");
            },
            cssStyles: { color: foreColor },
            textzIndex: 3602, // z-index for the text
            boxzIndex: 3601, // z-index for the "talk" box (should always be less than textzIndex)
            wrapperzIndex: 3600
        });
}

这个问题的答案让我难以捉摸。

更新:

这实际上看起来更像是一个尝试为不在页面可视区域中的内容创建气泡的问题。

编辑:更新了标题以更清楚地反映问题的名称。

4

1 回答 1

0

从之前的更新中意识到(问题在于屏幕外的元素),我想出了一个“修复”问题的技巧,但它并不优雅,而且远非最好的东西,因为我的猫进入了工艺闪光并且没有知道发生了什么。

这是黑客:

errorPlacement: function (er, el) {
    if (el && el.length > 0) {
        if (el.attr('id') == 'ContractOpenEnded') {
            $('#contractDuration').focus();
            createErrorBubble($('#contractDuration'), er.text())
        }
        else {
            $(el).focus();
            createErrorBubble($(el), er.text());
        }
    }
},

这里的神奇之处在于 .focus() 调用将元素带回视图端口。

于 2011-08-31T20:45:54.157 回答