从外部触发FullCalendar的'dayClick'方法? [英] Externally triggering FullCalendar's 'dayClick' method?

查看:674
本文介绍了从外部触发FullCalendar的'dayClick'方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Arshaw的FullCalendar,我正在模拟用户在页面加载后单击单元格。我试图做到这一点,所以我可能会去一个URL,如 / Calendar / AddEvent ,日历将自动打开一个对话框,其中包含我的添加事件表单。



进行以下设置:(小提琴



HTML

 < div> 
< div id =calendardata-year =2013​​data-month =04>< / div>
< / div>

jQuery
< full_alendar({
firstDay:1,
selectable:true,
dayClick:function(start,allDay, jsEvent,view){
alert('你点了我!');
}
});

默认情况下,今天的单元格的类为 .fc-today ,我试着利用以下方法:

  $('。fc-今天 ')触发(' 点击'); 

虽然这似乎不起作用。无论如何,我可以做一些像

  $('#calendar')。fullCalendar('dayClick',date)

获得任何帮助。

解决方案

我在我的用例中遇到了这个问题,这是我在完整日历源代码中进行挖掘后发现的作品。您需要手动创建一个 mousedown mouseup 事件(技术上讲, mouseup 是可选的,但你可以用它来重置 td )的'clicked'状态,该状态包含元素X和Y位置的坐标想要点击。同样重要的是 which 参数,它需要设置为 1 ,以便传递 isPrimaryMouseButton 检查



考虑到这一点,代码看起来像这样(注意我改变了 $('#click')使用 mousedown 事件,以便它只运行一次):

  $('#click')。on('mousedown',function(){
var today = $('td.fc-today');
var down = new $ .Event( mousedown);
var up = new $ .Event(mouseup);
down.which = up.which = 1;
down.pageX = up.pageX = today.offset ().left;
down.pageY = up.pageY = today.offset()。top;
today.trigger(down);
today.trigger(up); // this如果你只是想要dayClick事件,那么它是可选的,但运行它可以让你重置'clicked'状态< td>
}});

下面是一个工作小提琴:
http://jsfiddle.net/vyxte25r/


I'm using Arshaw's FullCalendar and I'm looking to simulate a user clicking on a cell once the page has loaded. I'm trying to do this so I could potentially go to a URL such as /Calendar/AddEvent and the calendar will automatically open a dialog with my add event form in.

Take the following set up: (Fiddle here)

HTML

<div>
    <div id="calendar" data-year="2013" data-month="04" ></div>
</div>

jQuery

$('#calendar').fullCalendar({
        firstDay: 1,
        selectable: true,
        dayClick: function (start, allDay, jsEvent, view) {
                    alert('You clicked me!');
        }
    });

By default, the cell for today has the class .fc-today which I've tried to take advantage of by doing the following:

$('.fc-today').trigger('click');

This doesn't seem to work though. Is there anyway I could do something like

$('#calendar').fullCalendar('dayClick', date)

Any help is appreciated.

解决方案

I ran into this issue in my usecase as well, and this is what I found works for me, after digging around in the fullcalendar source code. You need to manually create a mousedown and mouseup event (technically the mouseup is optional, but you can use it to reset the 'clicked' state of the td), which contains the coordinates of the X and Y position of the element you want to "click". Also important is the which parameter, which needs to be set to 1 so that it passes the isPrimaryMouseButton check.

With this in mind, the code would look like this (note I changed the $('#click') to use a mousedown event so that it only runs once):

$('#click').on('mousedown', function () { 
    var today = $('td.fc-today');
    var down = new $.Event("mousedown");
    var up = new $.Event("mouseup");
    down.which = up.which = 1;
    down.pageX = up.pageX = today.offset().left;
    down.pageY = up.pageY = today.offset().top;
    today.trigger(down);
    today.trigger(up); //this is optional if you just want the dayClick event, but running this allows you to reset the 'clicked' state of the <td>
});

Here is a working fiddle: http://jsfiddle.net/vyxte25r/

这篇关于从外部触发FullCalendar的'dayClick'方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆