Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="calendar">
  
</div>
              
            
!

CSS

              
                #calendar {
  width: 80%;
  
}


/* ------- Agenda View ------- */
#agendaView > table{
    width: 100%;
    min-height: 500px;
    background: #FFF;
    
}

#agendaView .fc-agendaView-event-start,
#agendaView .fc-agendaView-event-end{
    width: 20%;
}

#agendaView .fc-agendaView-event-title{
    width: 60%;
}
#agendaView th{
    height: 30px;
    font-size: 14px;
    vertical-align: text-bottom;
    font-weight: bold;
    padding: 10px 0 0 10px;
}

#agendaView td{
    height: 30px;
    padding: 10px 0 0 10px;
    font-size: 14px;
    vertical-align: text-bottom;    
}

              
            
!

JS

              
                var $calendar = $("#calendar");
$calendar.fullCalendar({
            header: {
                left: ' today,prev,next,  title',
                right: 'month,agendaWeek,agendaDay '
            },
            weekends: true,
            allDaySlot: true,
            droppable: true, /* 允許拖入 */
            eventAfterAllRender:function(view){
                var header =  $calendar.find(".fc-header");
                // trigger current view
                header.find('.fc-header-right').find('.fc-button').off('mouseup').on('mouseup', function(){
                    if(!$(this).hasClass('fc-button-agendaView')){
                        $calendar.data("view", '');
                    }
                });

                //用來辨別是否在agendaView,是則重繪,否則移除
                if( $calendar.data("view") != 'agendaView' ){
                    header.find(".fc-button-agendaView").removeClass('fc-state-active active');
                    $("#agendaView").remove();

                }else{
                    renderAgendaView();
                }

             
 
            },
            eventRender: function(event, e){

                currentView = $('#calendar').fullCalendar('getView').name; /* 用來偵測哪個view進行什麼樣的處理用 */
            },dayClick: function(date, jsEvent, view) { 
              /* 點選日期觸發 */

 
            },
            eventClick: function(calEvent, jsEvent, view) {
                console.log("===== eventClick =====");
                console.log(calEvent);
               

            }
});

    var headerRight = $calendar.find(".fc-header").find(".fc-header-right");

    var agendaBtn = headerRight.find(".fc-corner-right").removeClass('fc-corner-right')
                    .clone().addClass('fc-corner-right fc-button-agendaView').removeClass('fc-button-agendaDay').text("agenda");

    agendaBtn.on('click', function(){
      renderAgendaView();
    });

    headerRight.find(".fc-header-space").before(agendaBtn);
       
// test event data
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

var newEvent = {
  title: 'NEW EVENT',
  start: new Date(y, m, d, 10),
  end: new Date(y, m, d, 15),
  editable: true
};

// add event to calendar
var event = $('#calendar').fullCalendar( 'renderEvent', newEvent , 'stick');



function renderAgendaView(){

  if($calendar.fullCalendar('getView') != 'agendaView'){
    // 複製原本的month為agendaView ,這樣可解決切換為agenda View時 month 無法點之問題
    $calendar.fullCalendar( 'changeView', 'month' );
    var newView = $calendar.fullCalendar('getView');
    newView.name = 'agendaView';

    $calendar.fullCalendar( 'changeView', 'agendaView' );
  }

  // get current events in memory
  var events = $calendar.fullCalendar( 'clientEvents' );

  // get current date
  var currentDate = $calendar.fullCalendar( 'getDate' );

  $calendar.find(".fc-header").find(".fc-button-agendaView").siblings().removeClass('fc-state-active').end().addClass('fc-state-active');
 
  $calendar.data("view", 'agendaView');
  var agendaViewHtml = document.createElement('div');
  agendaViewHtml.setAttribute("id", "agendaView");
  var contents = "<table>" + 
      "<thead><tr>" +
      "<th class='fc-widget-header fc-agendaView-event-start'>DateStart</th>" + 
      "<th class='fc-widget-header fc-agendaView-event-end'>DateEnd</th>" + 
      "<th class='fc-widget-header fc-agendaView-event-title'>Event</th>" +
      "</tr></thead>" + 
      "<tbody>";

  for (key in events) {
    //  detect month range
    var monthRange = moment().range(moment(currentDate).startOf('month'), moment(currentDate).endOf('month'));
    var eventStart = moment(events[key].start).format("YYYY/MM/DD-H:mm:ss");
    var eventEnd = moment(events[key].end).format("YYYY/MM/DD-H:mm:ss");
    if(monthRange.contains(events[key].start) && monthRange.contains(events[key].end)){
      var eventTitle = events[key].title;
      contents += '<tr>' + 
        '<td class="fc-widget-content">' + eventStart + '</td>' + 
        '<td class="fc-widget-content">' + eventEnd + '</td>' + 
        '<td class="fc-widget-content">' + eventTitle + '</td>' + 
        '</tr>';

    }
  }
  contents += "</tbody></table>";
  agendaViewHtml.innerHTML = contents;
  $calendar.find(".fc-content").html(agendaViewHtml);

  // console.log(events);
}
              
            
!
999px

Console