signed.js 10.1 KB
/*! dili 2016-01-06 */
!function($){function drawCalControl(target,opt){$(target).append('<div class="jCal">'+(0==opt.ind?'<div class="left" />':"")+'<div class="month"><span class="monthYear">'+opt.day.getFullYear()+'</span><span class="monthName">'+opt.ml[opt.day.getMonth()]+"</span></div>"+(opt.ind==opt.showMonths-1?'<div class="right" />':"")+"</div>"),opt.monthSelect&&$(target).find(".jCal .monthName, .jCal .monthYear").bind("mouseover",$.extend({},opt),function(e){$(this).removeClass("monthYearHover").removeClass("monthNameHover"),0==$(".jCalMask",e.data._target).length&&$(this).addClass($(this).attr("class")+"Hover")}).bind("mouseout",function(){$(this).removeClass("monthYearHover").removeClass("monthNameHover")}).bind("click",$.extend({},opt),function(e){$(e.data._target).stop(),$(".jCalMo .monthSelector, .jCalMo .monthSelectorShadow").remove();var monthName=$(this).hasClass("monthName"),pad=Math.max(parseInt($(this).css("padding-left")),parseInt($(this).css("padding-left")))||2,calcTop=$(this).position().top-(monthName?e.data.day.getMonth():2)*($(this).height()+0);calcTop=calcTop>0?calcTop:0;var topDiff=$(this).position().top-calcTop;$('<div class="monthSelectorShadow" style="top:'+$(e.data._target).position().top+"px; left:"+$(e.data._target).position().left+"px; width:"+($(e.data._target).width()+(parseInt($(e.data._target).css("paddingLeft"))||0)+(parseInt($(e.data._target).css("paddingRight"))||0))+"px; height:"+($(e.data._target).height()+(parseInt($(e.data._target).css("paddingTop"))||0)+(parseInt($(e.data._target).css("paddingBottom"))||0))+'px;"></div>').css("opacity",.01).appendTo($(this).parent()),$('<div class="monthSelector" style="top:'+calcTop+"px; left:"+$(this).position().left+"px; width:"+($(this).width()+2*pad)+'px;"></div>').css("opacity",0).appendTo($(this).parent());for(var di=monthName?0:-2,dd=monthName?12:3;dd>di;di++)$(this).clone().removeClass("monthYearHover").removeClass("monthNameHover").addClass("monthSelect").attr("id",monthName?di+1+"_1_"+e.data.day.getFullYear():e.data.day.getMonth()+1+"_1_"+(e.data.day.getFullYear()+di)).html(monthName?e.data.ml[di]:e.data.day.getFullYear()+di).css("top",$(this).height()*di).appendTo($(this).parent().find(".monthSelector"));var moSel=$(this).parent().find(".monthSelector").get(0),diffOff=$(moSel).height()-($(moSel).height()-topDiff);$(moSel).css("clip","rect("+diffOff+"px "+($(this).width()+2*pad)+"px "+diffOff+"px 0px)").animate({opacity:.92,clip:"rect(0px "+($(this).width()+2*pad)+"px "+$(moSel).height()+"px 0px)"},e.data.scrollSpeed,function(){$(this).parent().find(".monthSelectorShadow").bind("mouseover click",function(){$(this).parent().find(".monthSelector").remove(),$(this).remove()})}).parent().find(".monthSelectorShadow").animate({opacity:.1},e.data.scrollSpeed),$(".jCalMo .monthSelect",e.data._target).bind("mouseover mouseout click",$.extend({},e.data),function(e){"click"==e.type?$(e.data._target).jCal($.extend(e.data,{day:new Date($(this).attr("id").replace(/_/g,"/"))})):$(this).toggleClass("monthSelectHover")}),"function"==typeof opt.drawBack&&opt.drawBack()}),$(target).find(".jCal .left").bind("click",$.extend({},opt),function(e){if($(".jCalMask",e.data._target).length>0)return!1;$(e.data._target).stop();var mD={w:0,h:0};$(".jCalMo",e.data._target).each(function(){mD.w+=$(this).width()+parseInt($(this).css("padding-left"))+parseInt($(this).css("padding-right"));var cH=$(this).height()+parseInt($(this).css("padding-top"))+parseInt($(this).css("padding-bottom"));mD.h=cH>mD.h?cH:mD.h}),$(e.data._target).prepend('<div class="jCalMo"></div>'),e.data.day=new Date($("div[id*="+e.data.cID+"d_]:first",e.data._target).attr("id").replace(e.data.cID+"d_","").replace(/_/g,"/")),e.data.day.setDate(1),e.data.day.setMonth(e.data.day.getMonth()-1),drawCalControl($(".jCalMo:first",e.data._target),e.data),drawCal($(".jCalMo:first",e.data._target),e.data),e.data.showMonths>1&&($(".right",e.data._target).clone(!0).appendTo($(".jCalMo:eq(1) .jCal",e.data._target)),$(".left:last, .right:last",e.data._target).remove()),$(e.data._target).append('<div class="jCalSpace" style="width:'+mD.w+"px; height:"+mD.h+'px;"></div>'),$(".jCalMo",e.data._target).wrapAll('<div class="jCalMask" style="clip:rect(0px '+mD.w+"px "+mD.h+"px 0px); width:"+(mD.w+mD.w/e.data.showMonths)+"px; height:"+mD.h+'px;"><div class="jCalMove"></div></div>'),$(".jCalMove",e.data._target).css("margin-left",mD.w/e.data.showMonths*-1+"px").css("opacity",.5).animate({marginLeft:"0px"},e.data.scrollSpeed,function(){$(this).children(".jCalMo:not(:last)").appendTo($(e.data._target)),$(".jCalSpace, .jCalMask",e.data._target).empty().remove(),$(e.data._target).data("day")&&reSelectDates(e.data._target,$(e.data._target).data("day"),$(e.data._target).data("days"),e.data),"function"==typeof opt.drawBack&&opt.drawBack()}),DaySelected(opt.selected)}),$(target).find(".jCal .right").bind("click",$.extend({},opt),function(e){if($(".jCalMask",e.data._target).length>0)return!1;$(e.data._target).stop();var mD={w:0,h:0};$(".jCalMo",e.data._target).each(function(){mD.w+=$(this).width()+parseInt($(this).css("padding-left"))+parseInt($(this).css("padding-right"));var cH=$(this).height()+parseInt($(this).css("padding-top"))+parseInt($(this).css("padding-bottom"));mD.h=cH>mD.h?cH:mD.h}),$(e.data._target).append('<div class="jCalMo"></div>'),e.data.day=new Date($("div[id^="+e.data.cID+"d_]:last",e.data._target).attr("id").replace(e.data.cID+"d_","").replace(/_/g,"/")),e.data.day.setDate(1),e.data.day.setMonth(e.data.day.getMonth()+1),drawCalControl($(".jCalMo:last",e.data._target),e.data),drawCal($(".jCalMo:last",e.data._target),e.data),e.data.showMonths>1&&($(".left",e.data._target).clone(!0).prependTo($(".jCalMo:eq(1) .jCal",e.data._target)),$(".left:first, .right:first",e.data._target).remove()),$(e.data._target).append('<div class="jCalSpace" style="width:'+mD.w+"px; height:"+mD.h+'px;"></div>'),$(".jCalMo",e.data._target).wrapAll('<div class="jCalMask" style="clip:rect(0px '+mD.w+"px "+mD.h+"px 0px); width:"+(mD.w+mD.w/e.data.showMonths)+"px; height:"+mD.h+'px;"><div class="jCalMove"></div></div>'),$(".jCalMove",e.data._target).css("opacity",.5).animate({marginLeft:mD.w/e.data.showMonths*-1+"px"},e.data.scrollSpeed,function(){$(this).children(".jCalMo:not(:first)").appendTo($(e.data._target)),$(".jCalSpace, .jCalMask",e.data._target).empty().remove(),$(e.data._target).data("day")&&reSelectDates(e.data._target,$(e.data._target).data("day"),$(e.data._target).data("days"),e.data),$(this).children(".jCalMo:not(:first)").removeClass(""),"function"==typeof opt.drawBack&&opt.drawBack()}),DaySelected(opt.selected)})}function reSelectDates(target,day,days,opt){for(var sDay=(new Date(day.getTime()),new Date(day.getTime())),fC=!1,di=0,dC=days;dC>di;di++){var dF=$(target).find("div[id*=d_"+(sDay.getMonth()+1)+"_"+sDay.getDate()+"_"+sDay.getFullYear()+"]");dF.length>0&&(dF.stop().addClass("selectedDay"),fC=!0),sDay.setDate(sDay.getDate()+1)}fC&&"function"==typeof opt.callback&&opt.callback(day,days)}function drawCal(target,opt){for(var ds=0,length=opt.dow.length;length>ds;ds++)$(target).append('<div class="dow">'+opt.dow[ds]+"</div>");for(var fd=new Date(new Date(opt.day.getTime()).setDate(1)),ldlm=new Date(new Date(fd.getTime()).setDate(0)),ld=new Date(new Date(new Date(fd.getTime()).setMonth(fd.getMonth()+1)).setDate(0)),copt={fd:fd.getDay(),lld:ldlm.getDate(),ld:ld.getDate()},offsetDayStart=copt.fd<opt.dayOffset?opt.dayOffset-7:1,offsetDayEnd=ld.getDay()<opt.dayOffset?7-ld.getDay():ld.getDay(),d=offsetDayStart,dE=copt.fd+copt.ld+(7-offsetDayEnd);dE>d;d++)$(target).append(d<=copt.fd-opt.dayOffset?'<div id="'+opt.cID+"d"+d+'" class="pday">'+(copt.lld-(copt.fd-opt.dayOffset-d))+"</div>":d>copt.fd-opt.dayOffset+copt.ld?'<div id="'+opt.cID+"d"+d+'" class="aday">'+(d-(copt.fd-opt.dayOffset+copt.ld))+"</div>":'<div id="'+opt.cID+"d_"+(fd.getMonth()+1)+"_"+(d-(copt.fd-opt.dayOffset))+"_"+fd.getFullYear()+'" class="'+(opt.dCheck(new Date(new Date(fd.getTime()).setDate(d-(copt.fd-opt.dayOffset))))||"invday")+'">'+(d-(copt.fd-opt.dayOffset))+"</div>");$(target).find("div[id^="+opt.cID+"d]:first, div[id^="+opt.cID+"d]:nth-child(7n+2)").before('<br style="clear:both;" />')}function DaySelected(selected){if(null==selected)return!1;var arr=[[selected.start.slice(0,4),getNumber(selected.start.slice(4,6)),getNumber(selected.start.slice(6,8))],[selected.end.slice(0,4),getNumber(selected.end.slice(4,6)),getNumber(selected.end.slice(6,8))]];if(arr[0][1]==arr[1][1])for(var i=arr[0][2];i<=arr[1][2];i++)$("#c2d_"+arr[0][1]+"_"+i+"_"+arr[0][0]).addClass("selectedDay");else{for(var i=parseInt(arr[0][2]);32>i;i++)$("#c2d_"+arr[0][1]+"_"+i+"_"+arr[0][0]).addClass("selectedDay");for(var i=1;i<=parseInt(arr[1][2]);i++)$("#c2d_"+arr[1][1]+"_"+i+"_"+arr[1][0]).addClass("selectedDay")}}function getNumber(stringNumber){return parseInt(stringNumber)}$.fn.jCal=function(opt){return $.jCal(this,opt),this},$.jCal=function(target,opt){opt=$.extend({selected:null,day:new Date,days:0,showMonths:2,monthSelect:!1,dCheck:function(day){return"day"},callback:function(day,days){return!0},drawBack:function(){return!0},selectedBG:"rgb(0, 143, 214)",defaultBG:"rgb(255, 255, 255)",dayOffset:0,scrollSpeed:150,forceWeek:!1,dow:["周日","周一","周二","周三","周四","周五","周六"],ml:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],ms:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],_target:target},opt),opt.day=new Date(opt.day.getFullYear(),opt.day.getMonth(),1),$(opt._target).data("days")||$(opt._target).data("days",opt.days),$(target).stop().empty();for(var sm=0;sm<opt.showMonths;sm++)$(target).append('<div class="jCalMo"></div>');opt.cID="c"+$(".jCalMo").length,$(".jCalMo",target).each(function(ind){drawCalControl($(this),$.extend({},opt,{ind:ind,day:new Date(new Date(opt.day.getTime()).setMonth(new Date(opt.day.getTime()).getMonth()+ind))})),drawCal($(this),$.extend({},opt,{ind:ind,day:new Date(new Date(opt.day.getTime()).setMonth(new Date(opt.day.getTime()).getMonth()+ind))}))}),$(opt._target).data("day")&&$(opt._target).data("days")&&reSelectDates(target,$(opt._target).data("day"),$(opt._target).data("days"),opt),"function"==typeof opt.drawBack&&opt.drawBack(),DaySelected(opt.selected)}}(jQuery);