jquery.gantt.js
31.6 KB
/**
* @fileOverview gantt插件封装
* @author:Hbomb(zhouqq@yoho.cn)
* @date:2013-05-28
*/
define('lib/ui/jquery.gantt', ["jquery"], function(require)
{
var jQuery = require("jquery");
(function($){"use strict";$.fn.gantt=function(options){var cookieKey="jquery.fn.gantt";var scales=["hours","days","weeks","months"];var settings={source:null,itemsPerPage:7,months:["January","February","March","April","May","June","July","August","September","October","November","December"],dow:["S","M","T","W","T","F","S"],startPos:new Date,navigate:"buttons",scale:"days",useCookie:false,maxScale:"months",minScale:"hours",waitText:"Please wait...",onItemClick:function(a){return},onAddClick:function(a){return},onRender:function(){return},scrollToToday:true};$.extend($.expr[":"],{findday:function(a,b,c){var d=new Date(parseInt(c[3],10));var e=$(a).attr("id");e=e?e:"";var f=e.indexOf("-")+1;var g=new Date(parseInt(e.substring(f,e.length),10));d=new Date(d.getFullYear(),d.getMonth(),d.getDate());g=new Date(g.getFullYear(),g.getMonth(),g.getDate());return d.getTime()===g.getTime()}});$.extend($.expr[":"],{findweek:function(a,b,c){var d=new Date(parseInt(c[3],10));var e=$(a).attr("id");e=e?e:"";var f=e.indexOf("-")+1;d=d.getFullYear()+"-"+d.getDayForWeek().getWeekOfYear();var g=e.substring(f,e.length);return d===g}});$.extend($.expr[":"],{findmonth:function(a,b,c){var d=new Date(parseInt(c[3],10));d=d.getFullYear()+"-"+d.getMonth();var e=$(a).attr("id");e=e?e:"";var f=e.indexOf("-")+1;var g=e.substring(f,e.length);return d===g}});Date.prototype.getWeekId=function(){var a=this.getFullYear();var b=this.getDayForWeek().getWeekOfYear();var c=this.getMonth();if(c===11&&b===1){a++}return"dh-"+a+"-"+b};Date.prototype.genRepDate=function(){switch(settings.scale){case"hours":return this.getTime();case"weeks":return this.getDayForWeek().getTime();case"months":return(new Date(this.getFullYear(),this.getMonth(),1)).getTime();default:return this.getTime()}};Date.prototype.getDayOfYear=function(){var a=new Date(this.getFullYear(),0,0);var b=new Date(this.getFullYear(),this.getMonth(),this.getDate());return Math.ceil((b-a)/864e5)};Date.prototype.getWeekOfYear=function(){var a=new Date(this.getFullYear(),0,1);var b=new Date(this.getFullYear(),this.getMonth(),this.getDate());if(a.getDay()>3){a=new Date(b.getFullYear(),0,7-a.getDay())}var c=b.getDayOfYear()-a.getDayOfYear();return Math.ceil(c/7)};Date.prototype.getDaysInMonth=function(){return 32-(new Date(this.getFullYear(),this.getMonth(),32)).getDate()};Date.prototype.hasWeek=function(){var a=new Date(this.valueOf());a.setDate(a.getDate()-a.getDay());var b=new Date(this.valueOf());b.setDate(b.getDate()+(6-b.getDay()));if(a.getMonth()===b.getMonth()){return true}else{return a.getMonth()===this.getMonth()&&b.getDate()<4||a.getMonth()!==this.getMonth()&&b.getDate()>=4}};Date.prototype.getDayForWeek=function(){var a=new Date(this.valueOf());a.setDate(a.getDate()-a.getDay());var b=new Date(this.valueOf());b.setDate(b.getDate()+(6-b.getDay()));if(a.getMonth()===b.getMonth()||a.getMonth()!==b.getMonth()&&b.getDate()>=4){return new Date(b.setDate(b.getDate()-3))}else{return new Date(a.setDate(a.getDate()+3))}};var core={elementFromPoint:function(a,b){if($.browser.msie){a-=$(document).scrollLeft();b-=$(document).scrollTop()}else{a-=window.pageXOffset;b-=window.pageYOffset}return document.elementFromPoint(a,b)},create:function(a){if(typeof settings.source!=="string"){a.data=settings.source;core.init(a)}else{$.getJSON(settings.source,function(b){a.data=b;core.init(a)})}},init:function(a){a.rowsNum=a.data.length;a.pageCount=Math.ceil(a.rowsNum/settings.itemsPerPage);a.rowsOnLastPage=a.rowsNum-Math.floor(a.rowsNum/settings.itemsPerPage)*settings.itemsPerPage;a.dateStart=tools.getMinDate(a);a.dateEnd=tools.getMaxDate(a);core.waitToggle(a,true,function(){core.render(a)})},render:function(a){var b=$('<div class="fn-content"/>');var c=core.leftPanel(a);b.append(c);var d=core.rightPanel(a,c);var e,f;b.append(d);b.append(core.navigation(a));var g=d.find(".dataPanel");a.gantt=$('<div class="fn-gantt" />').append(b);$(a).html(a.gantt);a.scrollNavigation.panelMargin=parseInt(g.css("margin-left").replace("px",""),10);a.scrollNavigation.panelMaxPos=g.width()-d.width();a.scrollNavigation.canScroll=g.width()>d.width();core.markNow(a);core.fillData(a,g,c);if(settings.useCookie){var h=$.cookie(this.cookieKey+"ScrollPos");if(h){a.hPosition=h}}if(settings.scrollToToday){var i=Math.round((settings.startPos/1e3-a.dateStart/1e3)/86400)-2;if(i>0&&a.hPosition!==0){if(a.scaleOldWidth){e=g.width()-d.width();f=e*a.hPosition/a.scaleOldWidth;f=f>0?0:f;g.css({"margin-left":f+"px"});a.scrollNavigation.panelMargin=f;a.hPosition=f;a.scaleOldWidth=null}else{g.css({"margin-left":a.hPosition+"px"});a.scrollNavigation.panelMargin=a.hPosition}core.repositionLabel(a)}else{core.repositionLabel(a)}}else{if(a.hPosition!==0){if(a.scaleOldWidth){e=g.width()-d.width();f=e*a.hPosition/a.scaleOldWidth;f=f>0?0:f;g.css({"margin-left":f+"px"});a.scrollNavigation.panelMargin=f;a.hPosition=f;a.scaleOldWidth=null}else{g.css({"margin-left":a.hPosition+"px"});a.scrollNavigation.panelMargin=a.hPosition}core.repositionLabel(a)}else{core.repositionLabel(a)}}g.css({height:c.height()});core.waitToggle(a,false);settings.onRender()},leftPanel:function(a){var b=$('<div class="leftPanel"/>').append($('<div class="row spacer"/>').css("height",tools.getCellSize()*a.headerRows+"px").css("width","100%"));var c=[];$.each(a.data,function(b,d){if(b>=a.pageNum*settings.itemsPerPage&&b<a.pageNum*settings.itemsPerPage+settings.itemsPerPage){c.push('<div class="row name row'+b+(d.desc?"":" fn-wide")+'" id="rowheader'+b+'" offset="'+b%settings.itemsPerPage*tools.getCellSize()+'">');c.push('<span class="fn-label'+(d.cssClass?" "+d.cssClass:"")+'">'+d.name+"</span>");c.push("</div>");if(d.desc){c.push('<div class="row desc row'+b+' " id="RowdId_'+b+'" data-id="'+d.id+'">');c.push('<span class="fn-label'+(d.cssClass?" "+d.cssClass:"")+'">'+d.desc+"</span>");c.push("</div>")}}});b.append(c.join(""));return b},dataPanel:function(a,b){var c=$('<div class="dataPanel" style="width: '+b+'px;"/>');var d=/Firefox/i.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel";if(document.attachEvent){a.attachEvent("on"+d,function(b){core.wheelScroll(a,b)})}else if(document.addEventListener){a.addEventListener(d,function(b){core.wheelScroll(a,b)},false)}c.click(function(b){b.stopPropagation();var c,d;var e=$(a).find(".fn-gantt .leftPanel");var f=$(a).find(".fn-gantt .dataPanel");switch(settings.scale){case"weeks":d=tools.getCellSize()*2;break;case"months":d=tools.getCellSize();break;case"hours":d=tools.getCellSize()*4;break;case"days":d=tools.getCellSize()*3;break;default:d=tools.getCellSize()*2;break}var g=core.elementFromPoint(b.pageX,f.offset().top+d);if(g.className==="fn-label"){g=$(g.parentNode)}else{g=$(g)}var h=g.attr("repdate");var i=core.elementFromPoint(e.offset().left+e.width()-10,b.pageY);if(i.className.indexOf("fn-label")===0){i=$(i.parentNode)}else{i=$(i)}var j=i.data().id;settings.onAddClick(h,j)});return c},rightPanel:function(a,b){var c=null;var d=[" sn"," wd"," wd"," wd"," wd"," wd"," sa"];var e=[" sn","","","","",""," sa"];var f=['<div class="row"/>'];var g=0;var h=['<div class="row"/>'];var i=0;var j=[];var k=0;var l=[];var m=[];var n=new Date;n=new Date(n.getFullYear(),n.getMonth(),n.getDate());var o=settings.holidays?settings.holidays.join():"";switch(settings.scale){case"hours":c=tools.parseTimeRange(a.dateStart,a.dateEnd,a.scaleStep);var p=c[0].getFullYear();var q=c[0].getMonth();var r=c[0];for(var s=0;s<c.length;s++){var t=c[s];var u=t.getFullYear();if(u!==p){f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");p=u;g=0}g++;var v=t.getMonth();if(v!==q){h.push('<div class="row header month" style="width: '+tools.getCellSize()*i+'px"><div class="fn-label">'+settings.months[q]+"</div></div>");q=v;i=0}i++;var w=t.getDay();var x=r.getDay();var y=d[w];var z=r.getTime();if(o.indexOf((new Date(t.getFullYear(),t.getMonth(),t.getDate())).getTime())>-1){y="holiday"}if(w!==x){var A=n-r===0?" today":o.indexOf(z)>-1?"holiday":d[x];j.push('<div class="row date '+A+'" '+' style="width: '+tools.getCellSize()*k+'px;"> '+' <div class="fn-label">'+r.getDate()+"</div></div>");l.push('<div class="row day '+A+'" '+' style="width: '+tools.getCellSize()*k+'px;"> '+' <div class="fn-label">'+settings.dow[x]+"</div></div>");r=t;k=0}k++;m.push('<div class="row day '+y+'" id="dh-'+t.getTime()+'" offset="'+s*tools.getCellSize()+'" repdate="'+t.genRepDate()+'"> '+t.getHours()+"</div>")}f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");h.push('<div class="row header month" style="width: '+tools.getCellSize()*i+'px"><div class="fn-label">'+settings.months[q]+"</div></div>");var y=d[r.getDay()];if(o.indexOf((new Date(r.getFullYear(),r.getMonth(),r.getDate())).getTime())>-1){y="holiday"}j.push('<div class="row date '+y+'" '+' style="width: '+tools.getCellSize()*k+'px;"> '+' <div class="fn-label">'+r.getDate()+"</div></div>");l.push('<div class="row day '+y+'" '+' style="width: '+tools.getCellSize()*k+'px;"> '+' <div class="fn-label">'+settings.dow[r.getDay()]+"</div></div>");var B=core.dataPanel(a,c.length*tools.getCellSize());B.append(f.join(""));B.append(h.join(""));B.append($('<div class="row"/>').html(j.join("")));B.append($('<div class="row"/>').html(l.join("")));B.append($('<div class="row"/>').html(m.join("")));break;case"weeks":c=tools.parseWeeksRange(a.dateStart,a.dateEnd);f=['<div class="row"/>'];h=['<div class="row"/>'];var p=c[0].getFullYear();var q=c[0].getMonth();var r=c[0];for(var s=0;s<c.length;s++){var t=c[s];if(t.getFullYear()!==p){f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");p=t.getFullYear();g=0}g++;if(t.getMonth()!==q){h.push('<div class="row header month" style="width:'+tools.getCellSize()*i+'px;"><div class="fn-label">'+settings.months[q]+"</div></div>");q=t.getMonth();i=0}i++;j.push('<div class="row day wd" '+' id="'+t.getWeekId()+'" offset="'+s*tools.getCellSize()+'" repdate="'+t.genRepDate()+'"> '+' <div class="fn-label">'+t.getWeekOfYear()+"</div></div>")}f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");h.push('<div class="row header month" style="width: '+tools.getCellSize()*i+'px"><div class="fn-label">'+settings.months[q]+"</div></div>");var B=core.dataPanel(a,c.length*tools.getCellSize());B.append(f.join("")+h.join("")+j.join("")+l.join(""));break;case"months":c=tools.parseMonthsRange(a.dateStart,a.dateEnd);var p=c[0].getFullYear();var q=c[0].getMonth();var r=c[0];for(var s=0;s<c.length;s++){var t=c[s];if(t.getFullYear()!==p){f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");p=t.getFullYear();g=0}g++;h.push('<div class="row day wd" id="dh-'+tools.genId(t.getTime())+'" offset="'+s*tools.getCellSize()+'" repdate="'+t.genRepDate()+'">'+(1+t.getMonth())+"</div>")}f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");h.push('<div class="row header month" style="width: '+tools.getCellSize()*i+'px">"<div class="fn-label">'+settings.months[q]+"</div></div>");var B=core.dataPanel(a,c.length*tools.getCellSize());B.append(f.join(""));B.append(h.join(""));B.append($('<div class="row"/>').html(j.join("")));B.append($('<div class="row"/>').html(l.join("")));break;default:c=tools.parseDateRange(a.dateStart,a.dateEnd);var p=c[0].getFullYear();var q=c[0].getMonth();var r=c[0];for(var s=0;s<c.length;s++){var t=c[s];if(t.getFullYear()!==p){f.push('<div class="row header year" style="width:'+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");p=t.getFullYear();g=0}g++;if(t.getMonth()!==q){h.push('<div class="row header month" style="width:'+tools.getCellSize()*i+'px;"><div class="fn-label">'+settings.months[q]+"</div></div>");q=t.getMonth();i=0}i++;var x=t.getDay();var y=d[x];if(o.indexOf((new Date(t.getFullYear(),t.getMonth(),t.getDate())).getTime())>-1){y="holiday"}j.push('<div class="row date '+y+'" '+' id="dh-'+tools.genId(t.getTime())+'" offset="'+s*tools.getCellSize()+'" repdate="'+t.genRepDate()+"> "+' <div class="fn-label">'+t.getDate()+"</div></div>");l.push('<div class="row day '+y+'" '+' id="dw-'+tools.genId(t.getTime())+'" repdate="'+t.genRepDate()+'"> '+' <div class="fn-label">'+settings.dow[x]+"</div></div>")}f.push('<div class="row header year" style="width: '+tools.getCellSize()*g+'px;"><div class="fn-label">'+p+"</div></div>");h.push('<div class="row header month" style="width: '+tools.getCellSize()*i+'px"><div class="fn-label">'+settings.months[q]+"</div></div>");var B=core.dataPanel(a,c.length*tools.getCellSize());B.append(f.join(""));B.append(h.join(""));B.append($('<div class="row"/>').html(j.join("")));B.append($('<div class="row"/>').html(l.join("")));break}return $('<div class="rightPanel"></div>').append(B)},navigation:function(a){var b=null;if(settings.navigate==="scroll"){b=$('<div class="navigate" />').append($('<div class="nav-slider" />').append($('<div class="nav-slider-left" />').append($('<span role="button" class="nav-link nav-page-back"/>').html("<").click(function(){core.navigatePage(a,-1)})).append($('<div class="page-number"/>').append($("<span/>").html(a.pageNum+1+" of "+a.pageCount))).append($('<span role="button" class="nav-link nav-page-next"/>').html(">").click(function(){core.navigatePage(a,1)})).append($('<span role="button" class="nav-link nav-now"/>').html("●").click(function(){core.navigateTo(a,"now")})).append($('<span role="button" class="nav-link nav-prev-week"/>').html("<<").click(function(){if(settings.scale==="hours"){core.navigateTo(a,tools.getCellSize()*8)}else if(settings.scale==="days"){core.navigateTo(a,tools.getCellSize()*30)}else if(settings.scale==="weeks"){core.navigateTo(a,tools.getCellSize()*12)}else if(settings.scale==="months"){core.navigateTo(a,tools.getCellSize()*6)}})).append($('<span role="button" class="nav-link nav-prev-day"/>').html("<").click(function(){if(settings.scale==="hours"){core.navigateTo(a,tools.getCellSize()*4)}else if(settings.scale==="days"){core.navigateTo(a,tools.getCellSize()*7)}else if(settings.scale==="weeks"){core.navigateTo(a,tools.getCellSize()*4)}else if(settings.scale==="months"){core.navigateTo(a,tools.getCellSize()*3)}}))).append($('<div class="nav-slider-content" />').append($('<div class="nav-slider-bar" />').append($('<a class="nav-slider-button" />')).mousedown(function(b){if(b.preventDefault){b.preventDefault()}a.scrollNavigation.scrollerMouseDown=true;core.sliderScroll(a,b)}).mousemove(function(b){if(a.scrollNavigation.scrollerMouseDown){core.sliderScroll(a,b)}}))).append($('<div class="nav-slider-right" />').append($('<span role="button" class="nav-link nav-next-day"/>').html(">").click(function(){if(settings.scale==="hours"){core.navigateTo(a,tools.getCellSize()*-4)}else if(settings.scale==="days"){core.navigateTo(a,tools.getCellSize()*-7)}else if(settings.scale==="weeks"){core.navigateTo(a,tools.getCellSize()*-4)}else if(settings.scale==="months"){core.navigateTo(a,tools.getCellSize()*-3)}})).append($('<span role="button" class="nav-link nav-next-week"/>').html(">>").click(function(){if(settings.scale==="hours"){core.navigateTo(a,tools.getCellSize()*-8)}else if(settings.scale==="days"){core.navigateTo(a,tools.getCellSize()*-30)}else if(settings.scale==="weeks"){core.navigateTo(a,tools.getCellSize()*-12)}else if(settings.scale==="months"){core.navigateTo(a,tools.getCellSize()*-6)}})).append($('<span role="button" class="nav-link nav-zoomIn"/>').html("+").click(function(){core.zoomInOut(a,-1)})).append($('<span role="button" class="nav-link nav-zoomOut"/>').html("-").click(function(){core.zoomInOut(a,1)}))));$(document).mouseup(function(){a.scrollNavigation.scrollerMouseDown=false})}else{b=$('<div class="navigate" />').append($('<span role="button" class="nav-link nav-page-back"/>').html("<").click(function(){core.navigatePage(a,-1)})).append($('<div class="page-number"/>').append($("<span/>").html(a.pageNum+1+" of "+a.pageCount))).append($('<span role="button" class="nav-link nav-page-next"/>').html(">").click(function(){core.navigatePage(a,1)})).append($('<span role="button" class="nav-link nav-begin"/>').html("|<").click(function(){core.navigateTo(a,"begin")})).append($('<span role="button" class="nav-link nav-prev-week"/>').html("<<").click(function(){core.navigateTo(a,tools.getCellSize()*7)})).append($('<span role="button" class="nav-link nav-prev-day"/>').html("<").click(function(){core.navigateTo(a,tools.getCellSize())})).append($('<span role="button" class="nav-link nav-now"/>').html("●").click(function(){core.navigateTo(a,"now")})).append($('<span role="button" class="nav-link nav-next-day"/>').html(">").click(function(){core.navigateTo(a,tools.getCellSize()*-1)})).append($('<span role="button" class="nav-link nav-next-week"/>').html(">>").click(function(){core.navigateTo(a,tools.getCellSize()*-7)})).append($('<span role="button" class="nav-link nav-end"/>').html(">|").click(function(){core.navigateTo(a,"end")})).append($('<span role="button" class="nav-link nav-zoomIn"/>').html("+").click(function(){core.zoomInOut(a,-1)})).append($('<span role="button" class="nav-link nav-zoomOut"/>').html("-").click(function(){core.zoomInOut(a,1)}))}return $('<div class="bottom"/>').append(b)},createProgressBar:function(a,b,c,d,e){var f=tools.getCellSize();var g=tools.getProgressBarMargin()||0;var h=$('<div class="bar"><div class="fn-label">'+d+"</div></div>").addClass(b).css({width:f*a-g+5}).data("dataObj",e);if(c){h.mouseover(function(a){var b=$('<div class="fn-gantt-hint" />').html(c);$("body").append(b);b.css("left",a.pageX);b.css("top",a.pageY);b.show()}).mouseout(function(){$(".fn-gantt-hint").remove()}).mousemove(function(a){$(".fn-gantt-hint").css("left",a.pageX);$(".fn-gantt-hint").css("top",a.pageY+15)})}h.click(function(a){a.stopPropagation();settings.onItemClick($(this).data("dataObj"))});return h},markNow:function(a){switch(settings.scale){case"weeks":var b=Date.parse(new Date);b=Math.floor(b/364e5)*364e5;$(a).find(':findweek("'+b+'")').removeClass("wd").addClass("today");break;case"months":$(a).find(':findmonth("'+(new Date).getTime()+'")').removeClass("wd").addClass("today");break;default:var b=Date.parse(new Date);b=Math.floor(b/364e5)*364e5;$(a).find(':findday("'+b+'")').removeClass("wd").addClass("today");break}},fillData:function(a,b,c){var d=function(a){try{a=a.replace("rgb(","").replace(")","");var b=a.split(",");var c=parseInt(b[0],10);var d=parseInt(b[1],10);var e=parseInt(b[2],10);var f=Math.round((255-(.299*c+.587*d+.114*e))*.9,1);return"rgb("+f+", "+f+", "+f+")"}catch(g){return""}};$.each(a.data,function(c,e){if(c>=a.pageNum*settings.itemsPerPage&&c<a.pageNum*settings.itemsPerPage+settings.itemsPerPage){$.each(e.values,function(e,f){var g=null;switch(settings.scale){case"hours":var h=tools.genId(tools.dateDeserialize(f.from).getTime(),a.scaleStep);var j=$(a).find("#dh-"+h);var k=tools.genId(tools.dateDeserialize(f.to).getTime(),a.scaleStep);var l=$(a).find("#dh-"+k);var m=j.attr("offset");var n=l.attr("offset");var o=Math.floor((n-m)/tools.getCellSize())+1;g=core.createProgressBar(o,f.customClass?f.customClass:"",f.desc?f.desc:"",f.label?f.label:"",f.dataObj?f.dataObj:null);var p=$(a).find("#rowheader"+c);var q=tools.getCellSize()*5+2+parseInt(p.attr("offset"),10);g.css({"margin-top":q,"margin-left":Math.floor(m)});b.append(g);break;case"weeks":var r=tools.dateDeserialize(f.from);var s=tools.dateDeserialize(f.to);if(r.getDate()<=3&&r.getMonth()===0){r.setDate(r.getDate()+4)}if(r.getDate()<=3&&r.getMonth()===0){r.setDate(r.getDate()+4)}if(s.getDate()<=3&&s.getMonth()===0){s.setDate(s.getDate()+4)}var j=$(a).find("#"+r.getWeekId());var m=j.attr("offset");var l=$(a).find("#"+s.getWeekId());var n=l.attr("offset");var o=Math.round((n-m)/tools.getCellSize())+1;g=core.createProgressBar(o,f.customClass?f.customClass:"",f.desc?f.desc:"",f.label?f.label:"",f.dataObj?f.dataObj:null);var p=$(a).find("#rowheader"+c);var q=tools.getCellSize()*3+2+parseInt(p.attr("offset"),10);g.css({"margin-top":q,"margin-left":Math.floor(m)});b.append(g);break;case"months":var r=tools.dateDeserialize(f.from);var s=tools.dateDeserialize(f.to);if(r.getDate()<=3&&r.getMonth()===0){r.setDate(r.getDate()+4)}if(r.getDate()<=3&&r.getMonth()===0){r.setDate(r.getDate()+4)}if(s.getDate()<=3&&s.getMonth()===0){s.setDate(s.getDate()+4)}var j=$(a).find("#dh-"+tools.genId(r.getTime()));var m=j.attr("offset");var l=$(a).find("#dh-"+tools.genId(s.getTime()));var n=l.attr("offset");var o=Math.round((n-m)/tools.getCellSize())+1;g=core.createProgressBar(o,f.customClass?f.customClass:"",f.desc?f.desc:"",f.label?f.label:"",f.dataObj?f.dataObj:null);var p=$(a).find("#rowheader"+c);var q=tools.getCellSize()*2+2+parseInt(p.attr("offset"),10);g.css({"margin-top":q,"margin-left":Math.floor(m)});b.append(g);break;default:var h=tools.genId(tools.dateDeserialize(f.from).getTime());var k=tools.genId(tools.dateDeserialize(f.to).getTime());var j=$(a).find("#dh-"+h);var m=j.attr("offset");var o=Math.floor((k/1e3-h/1e3)/86400)+1;g=core.createProgressBar(o,f.customClass?f.customClass:"",f.desc?f.desc:"",f.label?f.label:"",f.dataObj?f.dataObj:null);var p=$(a).find("#rowheader"+c);var q=tools.getCellSize()*4+2+parseInt(p.attr("offset"),10);g.css({"margin-top":q,"margin-left":Math.floor(m)});b.append(g);break}var t=g.find(".fn-label");if(t&&g.length){var u=d(g[0].style.backgroundColor);t.css("color",u)}else if(t){t.css("color","")}})}})},navigateTo:function(a,b){var c=$(a).find(".fn-gantt .rightPanel");var d=c.find(".dataPanel");d.click=function(){alert(arguments.join(""))};var e=c.width();var f=d.width();switch(b){case"begin":d.animate({"margin-left":"0px"},"fast",function(){core.repositionLabel(a)});a.scrollNavigation.panelMargin=0;break;case"end":var g=f-e;a.scrollNavigation.panelMargin=g*-1;d.animate({"margin-left":"-"+g+"px"},"fast",function(){core.repositionLabel(a)});break;case"now":if(!a.scrollNavigation.canScroll||!d.find(".today").length){return false}var h=(f-e)*-1;var i=d.css("margin-left").replace("px","");var b=d.find(".today").offset().left-d.offset().left;b*=-1;if(b>0){b=0}else if(b<h){b=h}d.animate({"margin-left":b+"px"},"fast",core.repositionLabel(a));a.scrollNavigation.panelMargin=b;break;default:var h=(f-e)*-1;var i=d.css("margin-left").replace("px","");var b=parseInt(i,10)+b;if(b<=0&&b>=h){d.animate({"margin-left":b+"px"},"fast",core.repositionLabel(a))}a.scrollNavigation.panelMargin=b;break}},navigatePage:function(a,b){if(a.pageNum+b>=0&&a.pageNum+b<Math.ceil(a.rowsNum/settings.itemsPerPage)){core.waitToggle(a,true,function(){a.pageNum+=b;a.hPosition=$(".fn-gantt .dataPanel").css("margin-left").replace("px","");a.scaleOldWidth=false;core.init(a)})}},zoomInOut:function(a,b){core.waitToggle(a,true,function(){var c=b<0;var d=a.scaleStep+b*3;d=d<=1?1:d===4?3:d;var e=settings.scale;var f=a.headerRows;if(settings.scale==="hours"&&d>=13){e="days";f=4;d=13}else if(settings.scale==="days"&&c){e="hours";f=5;d=12}else if(settings.scale==="days"&&!c){e="weeks";f=3;d=13}else if(settings.scale==="weeks"&&!c){e="months";f=2;d=14}else if(settings.scale==="weeks"&&c){e="days";f=4;d=13}else if(settings.scale==="months"&&c){e="weeks";f=3;d=13}if(c&&$.inArray(e,scales)<$.inArray(settings.minScale,scales)||!c&&$.inArray(e,scales)>$.inArray(settings.maxScale,scales)){core.init(a);return}a.scaleStep=d;settings.scale=e;a.headerRows=f;var g=$(a).find(".fn-gantt .rightPanel");var h=g.find(".dataPanel");a.hPosition=h.css("margin-left").replace("px","");a.scaleOldWidth=h.width()-g.width();if(settings.useCookie){$.cookie(this.cookieKey+"CurrentScale",settings.scale);$.cookie(this.cookieKey+"ScrollPos",null)}core.init(a)})},mouseScroll:function(a,b){var c=$(a).find(".fn-gantt .dataPanel");c.css("cursor","move");var d=c.offset();var e=a.scrollNavigation.mouseX===null?b.pageX:a.scrollNavigation.mouseX;var f=b.pageX-e;a.scrollNavigation.mouseX=b.pageX;core.scrollPanel(a,f);clearTimeout(a.scrollNavigation.repositionDelay);a.scrollNavigation.repositionDelay=setTimeout(core.repositionLabel,50,a)},wheelScroll:function(a,b){var c=b.detail?b.detail*-50:b.wheelDelta/120*50;core.scrollPanel(a,c);clearTimeout(a.scrollNavigation.repositionDelay);a.scrollNavigation.repositionDelay=setTimeout(core.repositionLabel,50,a);if(b.preventDefault){b.preventDefault()}else{return false}},sliderScroll:function(a,b){var c=$(a).find(".nav-slider-bar");var d=c.find(".nav-slider-button");var e=$(a).find(".fn-gantt .rightPanel");var f=e.find(".dataPanel");var g=c.offset();var h=c.width();var i=d.width();var j,k;if(b.pageX>=g.left&&b.pageX<=g.left+h){j=b.pageX-g.left;j=j-i/2;d.css("left",j);k=f.width()-e.width();var l=j*k/h*-1;if(l>=0){f.css("margin-left","0px");a.scrollNavigation.panelMargin=0}else if(j>=h-i*1){f.css("margin-left",k*-1+"px");a.scrollNavigation.panelMargin=k*-1}else{f.css("margin-left",l+"px");a.scrollNavigation.panelMargin=l}clearTimeout(a.scrollNavigation.repositionDelay);a.scrollNavigation.repositionDelay=setTimeout(core.repositionLabel,5,a)}},scrollPanel:function(a,b){if(!a.scrollNavigation.canScroll){return false}var c=parseInt(a.scrollNavigation.panelMargin,10)+b;if(c>0){a.scrollNavigation.panelMargin=0;$(a).find(".fn-gantt .dataPanel").css("margin-left",a.scrollNavigation.panelMargin+"px")}else if(c<a.scrollNavigation.panelMaxPos*-1){a.scrollNavigation.panelMargin=a.scrollNavigation.panelMaxPos*-1;$(a).find(".fn-gantt .dataPanel").css("margin-left",a.scrollNavigation.panelMargin+"px")}else{a.scrollNavigation.panelMargin=c;$(a).find(".fn-gantt .dataPanel").css("margin-left",a.scrollNavigation.panelMargin+"px")}core.synchronizeScroller(a)},synchronizeScroller:function(a){if(settings.navigate==="scroll"){var b=$(a).find(".fn-gantt .rightPanel");var c=b.find(".dataPanel");var d=$(a).find(".nav-slider-bar");var e=d.find(".nav-slider-button");var f=d.width();var g=e.width();var h=c.width()-b.width();var i=0;if(c.css("margin-left")){i=c.css("margin-left").replace("px","")}var j=i*f/h-e.width()*.25;j=j>0?0:j*-1>=f-g*.75?(f-g*1.25)*-1:j;e.css("left",j*-1)}},repositionLabel:function(a){setTimeout(function(){var b;if(!a){b=$(".fn-gantt .rightPanel .dataPanel")}else{var c=$(a).find(".fn-gantt .rightPanel");b=c.find(".dataPanel")}if(settings.useCookie){$.cookie(this.cookieKey+"ScrollPos",b.css("margin-left").replace("px",""))}},500)},waitToggle:function(a,b,c){if(b){var d=$(a).offset();var e=$(a).outerWidth();var f=$(a).outerHeight();if(!a.loader){a.loader=$('<div class="fn-gantt-loader" style="position: absolute; top: '+d.top+"px; left: "+d.left+"px; width: "+e+"px; height: "+f+'px;">'+'<div class="fn-gantt-loader-spinner"><span>'+settings.waitText+"</span></div></div>")}$("body").append(a.loader);setTimeout(c,100)}else{if(a.loader){a.loader.remove()}a.loader=null}}};var tools={getMaxDate:function(a){var b=null;$.each(a.data,function(a,c){$.each(c.values,function(a,c){b=b<tools.dateDeserialize(c.to)?tools.dateDeserialize(c.to):b})});switch(settings.scale){case"hours":b.setHours(Math.ceil(b.getHours()/a.scaleStep)*a.scaleStep);b.setHours(b.getHours()+a.scaleStep*3);break;case"weeks":var c=new Date(b.getTime());var c=new Date(c.setDate(c.getDate()+3*7));var d=Math.floor(c.getDate()/7)*7;b=new Date(c.getFullYear(),c.getMonth(),d===0?4:d-3);break;case"months":var c=new Date(b.getFullYear(),b.getMonth(),1);c.setMonth(c.getMonth()+2);b=new Date(c.getFullYear(),c.getMonth(),1);break;default:b.setHours(0);b.setDate(b.getDate()+3);break}return b},getMinDate:function(a){var b=null;$.each(a.data,function(a,c){$.each(c.values,function(a,c){b=b>tools.dateDeserialize(c.from)||b===null?tools.dateDeserialize(c.from):b})});switch(settings.scale){case"hours":b.setHours(Math.floor(b.getHours()/a.scaleStep)*a.scaleStep);b.setHours(b.getHours()-a.scaleStep*3);break;case"weeks":var c=new Date(b.getTime());var c=new Date(c.setDate(c.getDate()-3*7));var d=Math.floor(c.getDate()/7)*7;b=new Date(c.getFullYear(),c.getMonth(),d===0?4:d-3);break;case"months":var c=new Date(b.getFullYear(),b.getMonth(),1);c.setMonth(c.getMonth()-3);b=new Date(c.getFullYear(),c.getMonth(),1);break;default:b.setHours(0);b.setDate(b.getDate()-3);break}return b},parseDateRange:function(a,b){var c=new Date(a.getTime());var d=new Date(b.getTime());var e=[];var f=0;do{e[f++]=new Date(c.getTime());c.setDate(c.getDate()+1)}while(c.getTime()<=b.getTime());return e},parseTimeRange:function(a,b,c){var d=new Date(a);var e=new Date(b);var f=[];var g=0;do{f[g]=new Date(d.getTime());d.setHours(d.getHours()+c);d.setHours(Math.floor(d.getHours()/c)*c);if(d.getDay()!==f[g].getDay()){d.setHours(0)}g++}while(d.getTime()<=b.getTime());return f},parseWeeksRange:function(a,b){var c=new Date(a);var d=new Date(b);var e=[];var f=0;do{if(c.getDay()===0){e[f++]=c.getDayForWeek()}c.setDate(c.getDate()+1)}while(c.getTime()<=b.getTime());return e},parseMonthsRange:function(a,b){var c=new Date(a);var d=new Date(b);var e=[];var f=0;do{e[f++]=new Date(c.getFullYear(),c.getMonth(),1);c.setMonth(c.getMonth()+1)}while(c.getTime()<=b.getTime());return e},dateDeserialize:function(dateStr){var date=eval("new"+dateStr.replace(/\//g," "));return new Date(date.getUTCFullYear(),date.getUTCMonth(),date.getUTCDate(),date.getUTCHours(),date.getUTCMinutes())},genId:function(a){var b=new Date(a);switch(settings.scale){case"hours":var c=b.getHours();if(arguments.length>=2){c=Math.floor(b.getHours()/arguments[1])*arguments[1]}return(new Date(b.getFullYear(),b.getMonth(),b.getDate(),c)).getTime();case"weeks":var d=b.getFullYear();var e=b.getDayForWeek().getWeekOfYear();var f=b.getMonth();if(f===11&&e===1){d++}return d+"-"+e;case"months":return b.getFullYear()+"-"+b.getMonth();default:return(new Date(b.getFullYear(),b.getMonth(),b.getDate())).getTime()}},_getCellSize:null,getCellSize:function(){if(!tools._getCellSize){$("body").append($('<div style="display: none; position: absolute;" class="fn-gantt" id="measureCellWidth"><div class="row"></div></div>'));tools._getCellSize=$("#measureCellWidth .row").height();$("#measureCellWidth").empty().remove()}return tools._getCellSize},getRightPanelSize:function(){$("body").append($('<div style="display: none; position: absolute;" class="fn-gantt" id="measureCellWidth"><div class="rightPanel"></div></div>'));var a=$("#measureCellWidth .rightPanel").height();$("#measureCellWidth").empty().remove();return a},getPageHeight:function(a){return a.pageNum+1===a.pageCount?a.rowsOnLastPage*tools.getCellSize():settings.itemsPerPage*tools.getCellSize()},_getProgressBarMargin:null,getProgressBarMargin:function(){if(!tools._getProgressBarMargin){$("body").append($('<div style="display: none; position: absolute;" id="measureBarWidth" ><div class="fn-gantt"><div class="rightPanel"><div class="dataPanel"><div class="row day"><div class="bar" /></div></div></div></div></div>'));tools._getProgressBarMargin=parseInt($("#measureBarWidth .fn-gantt .rightPanel .day .bar").css("margin-left").replace("px",""),10);tools._getProgressBarMargin+=parseInt($("#measureBarWidth .fn-gantt .rightPanel .day .bar").css("margin-right").replace("px",""),10);$("#measureBarWidth").empty().remove()}return tools._getProgressBarMargin}};this.each(function(){if(options){$.extend(settings,options)}this.data=null;this.pageNum=0;this.pageCount=0;this.rowsOnLastPage=0;this.rowsNum=0;this.hPosition=0;this.dateStart=null;this.dateEnd=null;this.scrollClicked=false;this.scaleOldWidth=null;this.headerRows=null;if(settings.useCookie){var a=$.cookie(this.cookieKey+"CurrentScale");if(a){settings.scale=$.cookie(this.cookieKey+"CurrentScale")}else{$.cookie(this.cookieKey+"CurrentScale",settings.scale)}}switch(settings.scale){case"hours":this.headerRows=5;this.scaleStep=1;break;case"weeks":this.headerRows=3;this.scaleStep=13;break;case"months":this.headerRows=2;this.scaleStep=14;break;default:this.headerRows=4;this.scaleStep=13;break}this.scrollNavigation={panelMouseDown:false,scrollerMouseDown:false,mouseX:null,panelMargin:0,repositionDelay:0,panelMaxPos:0,canScroll:true};this.gantt=null;this.loader=null;core.create(this)})}})(jQuery);
});