25

Tôi đã tạo một ứng dụng fullcalendar cho thiết bị di động như Android và iPhone bằng cách sử dụng Phonegap. Tôi đang sử dụng Jquery Touch Punch Plugin cùng với plugin Jquery fullcalendar. Phương thức 'chọn' của fullcalendar đang hoạt động tốt trên web. Tôi có thể chọn nhiều ô trên chế độ xem theo tháng của toàn bộ lịch trên trình duyệt web. Tuy nhiên, trên ứng dụng Android/iPhone gốc tôi không thể chọn nhiều ô (phạm vi ngày) của lịch. Tất cả những gì xảy ra là khi tôi nhấp vào ô để chọn phạm vi ngày thì phương pháp 'chọn' được kích hoạt trước khi cho phép tôi chọn nhiều ngày trên thiết bị. Có anyway để khắc phục vấn đề này? Cảm ơn bạn trước. Đây là Jsfiddle.fullcalendar nhiều ô được chọn trên thiết bị di động?

mẫu mã:

// FullCalendar v1.5 
// Script modified from the "theme.html" demo file 

$(document).ready(function() {  
var date = new Date(); 
var d = date.getDate(); 
var m = date.getMonth(); 
var y = date.getFullYear(); 

$('#calendar').fullCalendar({ 
    theme: true, 
    header: { 
     left: 'prev,next today', 
     center: 'title', 
     right: 'month' 
    }, 
    editable: true, 
    disableDragging: true, 
    disableResizing: true, 
    droppable: true, 
    drop: function(date, allDay, jsEvent, ui){ 
     console.log(jsEvent); 
     console.log(ui); 
    }, 
    // add event name to title attribute on mouseover 
    eventMouseover: function(event, jsEvent, view) {    
     if (view.name == "month") { 
      $(jsEvent.target).attr('title', event.title); 
     } 
     //alert(event.id); 
    }, 
    // For DEMO only 
    // ************* 
    events: [ 
     { id: 1, 
      title: 'User1', 
      start: '2012-09-01', 
      end: '2012-09-01', 
      color:'#E9B33E', 
      className: 'user-class1'}, 
     { id: 2, 
      title: 'User2', 
      start: '2012-09-06', 
      end: '2012-09-06', 
      color:'#00813E', 
      className: 'user-class2'},  
     { id: 3, 
      title: 'User3', 
      start: '2012-09-06', 
      end: '2012-09-06', 
      color:'#E59238', 
      className: 'user-class3'},  
     { id: 4, 
      title: 'User4', 
      start: '2012-09-06', 
      end: '2012-09-06', 
      color:'#00813E', 
      className: 'user-class4'},    
     { id: 5, 
      title: 'User5', 
      start: '2012-09-08', 
      end: '2012-09-08', 
      color:'#00813E', 
      className: 'user-class5'}, 
     ], 
    eventRender: function(event,element,calEvent) {     
     element.attr('id',this.id); 
     if(this.id!=5){      
      element.find(".fc-event-title").after($("<br/><span class=\"fc-event-icons\"></span>") 
      .html("<img src=\"http://png-5.findicons.com/files//icons/2018/business_icons_for/16/passport.png\" onclick=\"javascript:iconsAlert("+this.id+",'passport')\" class=\"icon\"/>"+ 
       "<img src=\"http://findicons.com/files//icons/1571/chalkwork_payments/16/card_visa.png\" onclick=\"javascript:iconsAlert("+this.id+",'visa')\" class=\"icon\" />"+ 
       "<img src=\"http://findicons.com/files//icons/894/banking_stuff/16/postage_stamp.png\" onclick=\"javascript:iconsAlert("+this.id+",'traveldoc')\" class=\"icon\" />"+ 
       "<img src=\"http://findicons.com/files//icons/756/ginux/16/richtext.png\" onclick=\"javascript:iconsAlert("+this.id+",'entrystamp')\" class=\"icon\" />")); 
     } 
     element.droppable({ 
       accept: '*', 
       tolerance: 'touch', 
       //activeClass: 'ui-state-hover', 
       //hoverClass: 'ui-state-active', 
       drop: function(ev, ui) {     
        //console.log(ev.id); 
        alert(this.id); 
        //for(param in ui){ console.log(ev.id);} 
       } 
       }); 
}, 
selectable: true, 
selectHelper: true, 
select: function(start, end, allDay) { 
    alert("Cell selected from "+$.fullCalendar.formatDate(start, 'yyyy-MM-dd')+" to "+$.fullCalendar.formatDate(end, 'yyyy-MM-dd')); 
}, 
eventClick: function(calEvent, jsEvent, view) { 
    if (!$(jsEvent.target).hasClass("icon")) { 
     alert("UserID:"+calEvent.id); 
    }     
} 

}); 


$('#external-events div.passport-event,.visa-event,.entrystamp-event,.traveldoc-event').each(function() { 

     // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/) 
     // it doesn't need to have a start or end 
     var eventObject = { 
      title: $.trim($(this).text()), // use the element's text as the event title 
      className: $(this).attr('class') 
     }; 

     // store the Event Object in the DOM element so we can get to it later 
     $(this).data('eventObject', eventObject); 

     // make the event draggable using jQuery UI 
     $(this).draggable({ 
      zIndex: 999, 
      revert: true,  // will cause the event to go back to its 
      revertDuration: 0 // original position after the drag 
     }); 

    }); 
}); 

[Humble yêu cầu kiểm duyệt: Xin đừng đóng câu hỏi này trừ khi nó được giải quyết. Cảm ơn]

+0

có bất kỳ giao diện điều khiển đầu ra từ Mobile Safari? $ (document) .ready() có thể là một vấn đề cũng như jQM sử dụng $ (document) .bind ('pageinit') http://jquerymobile.com/demos/1.1.1/docs/api/events.html –

+0

@PhillPafford không thể thấy bất kỳ điều gì trong bảng điều khiển. Cảm ơn bạn rất nhiều vì đã xem xét điều này. Xin hãy xem http://jsfiddle.net/veer712/KrZJr/17/ cũng như –

+0

Nếu bạn đang cố gắng nhấp vào + kéo, hãy tận tâm thực tế là tôi cũng phải giải quyết bằng nhấp chuột. :) –

Trả lời

0

Câu trả lời này đã được tìm thấy trong một bài StackOverflow: How can we specify custom date range with fullcalendar?

Bạn có thể gọi chức năng này để có được sự kiện từ một phạm vi ngày. Tuy nhiên, điều này sẽ mang lại cho bạn sự kiện chỉ 30 ngày.

function GetAgendaEvents(datefrom, dateTo) { 
    var fromDate = new Date($("#from").val()); 
    var toDate = new Date($("#to").val()); 

    if (fromDate.getTime() <= toDate.getTime()) { 
     $('#fullcal').fullCalendar('removeEvents').fullCalendar('addEventSource', events); 
     $('#fullcal').fullCalendar('refetchEvents'); 

     var filteredEvent = $('#fullcal').fullCalendar('clientEvents', function (event) { 
      return event.start >= fromDate && event.start <= toDate; 
     }); 

     $('#fullcal').fullCalendar('gotoDate', fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate()); 
     $('#fullcal').fullCalendar('changeView', 'agenda'/* or 'basicDay' */); 

     $('#fullcal').fullCalendar('removeEvents').fullCalendar('addEventSource', filteredEvent); 
     $('#fullcal').fullCalendar('refetchEvents'); 
    } 
} 
0

giải pháp khác là Hộp ngày. Tôi đã thực hiện nó trong ứng dụng di động jquery của tôi, nó dễ sử dụng. và rất tốt cho cả trên máy tính, điện thoại di động, tblet http://dev.jtsage.com/jQM-DateBox2/

+0

Không liên quan đến câu hỏi yêu cầu. –

1

Làm thế nào về việc thêm người nghe sự kiện cho các tế bào của lịch đã khởi tạo và áp dụng một số ma thuật, như thế này:

$('#calendar table.fc-border-separate td.ui-widget-content').on('touchstart', function (event) { 
    /* touch start processing, probably cancelling like*/ 
    event.preventDefault(); 
    event.stopImmediatePropagation(); 

    function mouseMoveHandler (event) { 
     /* processing actual drag */ 
     /* possible also cancelling default behavior and instead calling Calendar API */ 
    } 

    function mouseUpHandler (event) { 
     /* processing mouse up */ 

     /* some clean up */   
     $(document).off('touchmove', mouseMoveHandler) 
     .off('touchend touchleave touchcancel', mouseUpHandler); 
    } 

    $(document).on('touchmove', mouseMoveHandler) 
     .on('touchend touchleave touchcancel', mouseUpHandler); 
}); 

Tôi biết đây là một chút cấp thấp so với phần còn lại của mã của bạn, nhưng điều đó có thể hữu ích. Những sự kiện này sẽ chỉ hoạt động trên điện thoại di động và có thể bạn sẽ có thể đạt được hành vi mong muốn. Xin lỗi không có thời gian để thử phương pháp này bản thân mình, có lẽ tôi sẽ cố gắng sau này trên jsFiddle.

+0

Tôi sẽ thử điều này nếu nó hoạt động :) –

+0

Tôi đã thử nhưng không hoạt động .. Xin bạn có thể cho tôi biết khi đặt mã này hoặc fiddle –

0

Chỉ cần thêm cho câu hỏi cũ này ...

Một giải pháp mà không liên lạc đấm:

Tôi đã đích thân thực hiện các fullcalendar cho mobilie và đã gặp rắc rối với việc xử lý touchmove của multiselect vì vậy tôi quyết định làm tất cả chỉ dựa trên các đối tượng ngày html mình.

Tôi chỉ nhận được chiều cao/chiều rộng của những gì được chọn đầu tiên và đếm khoảng cách được di chuyển liên quan đến chiều cao/chiều rộng đó. Nó đòi hỏi một hàm SelectDates (date1, date2) để xử lý bất cứ điều gì bạn muốn làm với daterange lựa chọn của bạn.

Đây là mã của tôi:

 $(document).on('touchmove', '.fc-day', function (e) { 
      var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]; 

      var $startElement = $(this); 
      var moveStartDate = new Date($startElement.data('date')); 
      var timezoneOffset = moveStartDate.getTimezoneOffset() * 60000; 
      moveStartDate.setTime(moveStartDate.getTime() + timezoneOffset); 

      var rect = $startElement[0].getBoundingClientRect(); 

      var DayHeight = $startElement[0].clientHeight; 
      var DayWidth = $startElement[0].clientWidth; 

      var xdif = 0; 
      if (touch.pageX < rect.left) { 
       xdif = touch.pageX - rect.left; 
      } 
      if (touch.pageX > rect.right) { 
       xdif = touch.pageX - rect.right; 
      } 
      var xDaysAwayDecimal = xdif == 0 ? 0 : (xdif/DayWidth); 
      var xDaysAway = xdif >= 0 ? Math.ceil(xDaysAwayDecimal) : Math.floor(xDaysAwayDecimal); 

      var ydif = 0; 
      if (touch.pageY < rect.top) { 
       ydif = touch.pageY - rect.top; 
      } 
      if (touch.pageY > rect.bottom) { 
       ydif = touch.pageY - rect.bottom; 
      } 
      var yDaysAwayDecimal = ydif == 0 ? 0 : (ydif/DayHeight); 
      var yDaysAway = ydif >= 0 ? Math.ceil(yDaysAwayDecimal) : Math.floor(yDaysAwayDecimal); 

      var dayModifier = (yDaysAway * 7) + xDaysAway; 

      var moveEndDate = new Date(moveStartDate); 
      moveEndDate.setDate(moveEndDate.getDate() + dayModifier); 
      if (moveStartDate > moveEndDate) { 
       SelectDates(moveEndDate, moveStartDate); 
      } 
      else { 
       SelectDates(moveStartDate, moveEndDate); 
      } 
     }) 

Cũng .. nếu SelectDates của bạn() không có bất kỳ nâng nặng, bạn có thể muốn chỉ có nó bắn mỗi số tiền x pixel di chuyển hoặc x số lượng phần nghìn giây .. hoặc là chỉ lưu các giá trị sau đó thực hiện quá trình xử lý khi bạn dừng. My SelectDates() đã thêm css vào lịch nên tôi muốn nó liên tục phát ra chuyển động cảm ứng.

+1

Chắc chắn rằng bạn có thể thực hiện cùng một loại giải pháp này thời trang thanh lịch, nhưng tôi nghĩ ý tưởng này có thể hữu ích cho bất kỳ ai gặp vấn đề này. – jumpdart

+0

Cảm ơn bạn đã thêm –

0

Sau nhiều tìm kiếm tôi không tìm thấy câu trả lời đơn giản và rõ ràng, Vì vậy, tôi đã làm cho nó một mình, và ở đây đó là:

var calendar = $('#calendar').fullCalendar({ 
    .. 
    .... 
    .. 
    dayRender: function(date, cell) { 
     $(cell).on("touchend",function(event){ 
      var startDate = date; 
      var x= event.originalEvent.changedTouches[0].clientX; 
      var y = event.originalEvent.changedTouches[0].clientY 
      var endDate = moment($(document.elementFromPoint(x, y)).attr("data-date"),"YYYY-MM-DD"); 
      if(endDate>startDate){ 
       calendar.fullCalendar('select', startDate, endDate.add('days', 1)); 
      }else{ 
       calendar.fullCalendar('select', endDate, startDate.add('days', 1)); 
      } 
     }); 
    }, 
    select: function(start, end, allDay, jsEvent, view) { 
     .. 
     .... 
     .. 
     calendar.fullCalendar('unselect'); 
    } 
}); 
+0

Tôi sẽ kiểm tra. Đánh giá cao nỗ lực của bạn để thử nó, cảm ơn bạn –

Các vấn đề liên quan