jquery fullcalendar删除popover

时间:2014-11-28 10:10:31

标签: javascript jquery twitter-bootstrap fullcalendar

我发现样本几乎像地雷一样,如果我点击屏幕上的任何地方,popover会隐藏,我需要它。可能吗?如果是,怎么样?

$.fn.popover.defaults.container = 'body';

$('#mycalendar').fullCalendar(
        {
            defaultView: "agendaWeek",
            slotMinutes:60,
            allDaySlot:false,
             header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'agendaWeek,agendaDay'
                    },
        eventRender: function (event, element) {
                    element.popover({
                        title: "My Title",
                        placement:             event.start.getHours()>12?'top':'bottom',
                        html:true,
                        content: event.msg
                    });
                  },
                 editable: false,        
          events: [
                    {
                        title  : 'Click me 3',
                        msg: 'I am clipped to the right which is annoying',                            
                        start  : '2011-05-07 12:00:00',
                        end  : '2011-05-07 13:00:00',
                        editable: false,                                                        
                        allDay : false 
                    }                  
                ]
        }); 
 $('#mycalendar').fullCalendar( 'gotoDate', 2011,04,7 );

可以找到jsfiddle HERE

我将不胜感激的任何帮助

2 个答案:

答案 0 :(得分:3)

在eventrender函数中尝试以下更改:

eventRender: function (event, element) {
    element.popover({
        title: "My Title",
        placement:             event.start.getHours()>12?'top':'bottom',
        html:true,
        content: event.msg,
        trigger: 'focus' // trigger popover on element focus
    });
    element.attr('tabindex', -1); // make the element (div) focusable
},

我还更新了jsfiddle here

答案 1 :(得分:0)

只需在脚本中添加以下J查询代码:

$(document).on('click', function (e) {
        $('[data-toggle="popover"],[data-original-title]').each(function () {
            //the 'is' for buttons that trigger popups
            //the 'has' for icons within a button that triggers a popup
            if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
                (($(this).popover('hide').data('bs.popover') || {}).inState || {}).click = false  // fix for BS 3.3.6
            }

        });
    });

注意:它将关闭上一个弹出窗口。