简体   繁体   English

在 fullcalendar 中处理单击和双击事件

[英]Handle single and double click events in fullcalendar

I am using fullcalendar and on single click to particular day of calendar it should fire single click event and on double click it should fire double click event.But on page load when I click 1st time it is not responding and single/double click not working properly.我正在使用 fullcalendar 并且单击到日历的特定日期它应该触发单击事件,双击它应该触发双击事件。但是在页面加载时,当我第一次单击它没有响应并且单击/双击不起作用适当地。

/* config object */
            $scope.uiConfig = {
              calendar:{
                height: 450,
                editable: false,
                    defaultView: 'month',
                    columnFormat: {
                        month: 'ddd',
                        week: 'ddd dd/MM',
                        day: 'dddd M/d'
                    },
                buttonText: {
                        month: "Mois",
                        week: "Semaine",
                        day: "Jour",
                        today:"aujourd'hui",
                },
                eventClick: $scope.alertEventOnClick,
              }
            };


$scope.alertEventOnClick = function(calEvent, jsEvent, view) {


                $("#onClick").click(function (e) {
                    var $this = $(this);
                    if ($this.hasClass('clicked')){
                        $this.removeClass('clicked'); 

                         //perform double-click action  
                    }else{
                         $this.addClass('clicked');
                         setTimeout(function() { 
                             if ($this.hasClass('clicked')){
                                 $this.removeClass('clicked'); 

                                  //perform single-click action    
                             }
                         },10);          
                    }
                });

        };

Use fullCalendar eventRender callback to attach your own events.使用 fullCalendar eventRender回调来附加您自己的事件。

For example:例如:

$('#calendar').fullCalendar({
    //events: [
        //....
    //],
    eventRender: function(event, element) {
         $(element).on({
             click: function() {
                 // Handle click...
             },
             dblclick: function() {
                 // Handle double click...
             }
         });
    }
});

I thought I would share how I address adding dblclick this through the API versus code modification with the fullcalendar version 4 that exposed the property through one object reference. 我想我会共享我地址如何通过该API与与fullcalendar版本4,其通过一个对象引用暴露出的属性代码修改添加DBLCLICK此。

Here is the working example: Codepen 这是工作示例: Codepen

eventRender: function (info) {

  //WON'T ALLOW ALSO WORK WITH single eventClick or single Click Listener
   //info.el.addEventListener('dblclick', function () {
     //  alert('DOUBLE CLICK!'+info.event.title);
   //});

  info.el.addEventListener('click', function() {
        clickCnt++;         
    if (clickCnt === 1) {
        oneClickTimer = setTimeout(function() {
            clickCnt = 0;
            alert('SINGLE CLICK example value grab:' + info.event.title );
        }, 400);
    } else if (clickCnt === 2) {
        clearTimeout(oneClickTimer);
        clickCnt = 0;
        alert('DOUBLE CLICK example value grab:' + info.event.start );

    }          
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM