jquery日期读出日历插件

时间:2013-12-15 15:57:28

标签: javascript jquery

原始插件click here to see demo and code on github

我无法弄清楚我需要更改代码才能使插件正常工作。 我有一个txt文件,可以通过此代码读出。 现在这是读出的txt文件的一部分

<div data-role='day' data-day='201411'>
  <div data-role='event' data-name='
    <h1>Title</h1>eventtext' data-start='00:30u ' data-end='01:30u' data-location='januari'>
  </div>
</div>

如您所见,数据日读出如下数据-day = 201411 =&gt; 2014年=第1年= 1月(与数据位置相关联)和1 =日

所以我希望日期是20140101所以年份是2014年,01月份是1月份,日子是01

这几个月和几天。第1个月,直到9应该变成01直到09,并且第1天到第9天应该变成01直到09,但是我已经尝试更改下面的代码但我无法弄清楚如何读取它的日期,例如20140101 抱歉我的英文不好,我希望我的问题很明确。 所有的帮助非常感谢!

var yy;
var calendarArray =[];
var monthOffset = [6,7,8,9,10,11,0,1,2,3,4,5];
var monthArray = [["JAN","January"],["FEB","February"],["MAR","March"],["APR","April"],["MAY","May"],["JUN","June"],["JUL","July"],["AUG","August"],["SEP","September"],["OCT","October"],["NOV","November"],["DEC","December"]];
var dayArray = ["7","1","2","3","4","5","6"];
$(document).ready(function() {
    $(document).on('click','.calendar-day.have-events',activateDay);
    $(document).on('click','.specific-day',activatecalendar);
    $(document).on('click','.calendar-month-view-arrow',offsetcalendar);
    $(window).resize(calendarScale);
    calendarSet();
    calendarScale();
});

    function calendarScale() {
        $(".calendar").each(function() {
            if($(this).width() < 400 && !$(this).hasClass('small')) {
                $(this).addClass('small');
            } else if($(this).width() > 400 && $(this).hasClass('small')) {
                $(this).removeClass('small');
            }
        })
    }

    function offsetcalendar() {
        var cm = parseInt($(".calendar").attr('offset'));
        if($(this).data('dir') == "left") {
            calendarSetMonth(cm-1);
        } else if($(this).data('dir') == "right") {
            calendarSetMonth(cm+1);
        }

    }

    function orderBy(deli,array) {
        var p = array.slice();
        var o = p.length;
        var y,t;
        var temparray = [];
        for(var u=0; u<o;u++) {
            for(var uu=0;uu<p.length;uu++) {
                if(uu==0) {
                    t = uu;
                    y = p[uu];
                }
                else if(parseInt(p[uu][deli].replace('.','')) < parseInt(y[deli].replace('.',''))) {
                    y = p[uu];
                    t = uu;
                }
            }
            temparray.push(y);
            p.splice(t,1);
        }
        return temparray;
    }

    function calendarSet() {
        $(".calendar").append('<div class="calendar-month-view"><div class="calendar-month-view-arrow" data-dir="left">‹</div><p></p><div class="calendar-month-view-arrow" data-dir="right">›</div></div><div class="calendar-holder"><div class="calendar-grid"></div><div class="calendar-specific"><div class="specific-day"><div class="specific-day-info" i="day"></div><div class="specific-day-info" i="month"></div></div><div class="specific-day-scheme"></div></div></div>');
        $(".calendar").each(function() {
            if($(this).data("color") == undefined) {
                $(this).data("color","red");
            }
            $(this).find('[data-role=day]').each(function() {
                var tempdayarray = [];
                $(this).find('[data-role=event]').each(function() {
                    var tempeventarray = [];
                    tempeventarray["name"] = $(this).data("name");
                    tempeventarray["start"] = $(this).data("start");
                    tempeventarray["end"] = $(this).data("end");
                    tempeventarray["location"] = $(this).data("location");
                    tempdayarray.push(tempeventarray);
                });
                calendarArray[$(this).data('day')] = tempdayarray;
            });
        });
        $(".calendar [data-role=day]").remove();
        calendarSetMonth();
    }
    function activateDay() {
        $(this).parents('.calendar').addClass('spec-day');
        var di = new Date(parseInt($(this).attr('time')));
        var strtime = $(this).attr('strtime');
        var d = new Object();
        d.day = di.getDate();
        d.month = di.getMonth();
        d.events = calendarArray[strtime];
        d.tocalendar = tocalendar;
        d.tocalendar();
    }
    var tocalendar = function() {
        $(".specific-day-info[i=day]").html(this.day);
        $(".specific-day-info[i=month]").html(monthArray[this.month][0]);
        if(this.events !== undefined) {
        var ev = orderBy('start',this.events);
        for(var o = 0; o<ev.length;o++) {
            $(".specific-day-scheme").append('<div class="specific-day-scheme-event"><p>'+ev[o]['name']+'</p><p data-role="dur">'+ev[o]['start']+' - '+ev[o]['end']+'</p><p data-role="loc">'+ev[o]['location']+'</p></div>');
        }
        }
    }
    function activatecalendar() {
        $(this).parents('.calendar').removeClass('spec-day');
        $(".specific-day-scheme").html('');
    }
    function calendarSetMonth(offset) {
        $(".calendar-grid").html('');
        var d = new Date();
        var c = new Date();
        var e = new Date();
        if(offset !== undefined) {
            d.setMonth(d.getMonth()+offset);
            e.setMonth(e.getMonth()+offset);
            $(".calendar").attr('offset', offset);
        } else {
            $(".calendar").attr('offset', 0);
        }
        $(".calendar .calendar-month-view p").text(monthArray[d.getMonth()][1]+' '+d.getFullYear());
            d.setDate(1);
            if(dayArray[d.getDay()] == 1) {
                d.setDate(d.getDate()-7);
            } else {
                d.setDate(d.getDate()-dayArray[d.getDay()]+1);
            }
            for(var i=0;i<42;i++) {
                d.setDate(d.getDate()+i);
                var cal_day = $('<div class="calendar-day"><div class="date-holder">'+d.getDate()+'</div></div>');
                if(d.getMonth() !== e.getMonth()) {
                    cal_day.addClass('other-month');
                }
                if(d.getTime() == c.getTime()) {
                    cal_day.addClass('this-day');
                }
                var strtime = d.getFullYear()+''+(d.getMonth()+1)+''+d.getDate();
                if(calendarArray[strtime] !== undefined) {
                    cal_day.addClass('have-events');
                }
                var cal_day_eventholder = $('<div class="event-notif-holder"></div>');
                if(calendarArray[strtime] != undefined) {
                    for(var u=0;u<3 && u<calendarArray[strtime].length;u++) {
                        cal_day_eventholder.append('<div class="event-notif"></div>')
                    }
                }
                cal_day.attr('strtime',strtime);
                cal_day.attr('time',d.getTime());
                cal_day.prepend(cal_day_eventholder);

                $(".calendar-grid").append(cal_day);
                d.setDate(d.getDate()-i);
            }
    }

0 个答案:

没有答案