Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsgantt-improved

Package Overview
Dependencies
Maintainers
1
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsgantt-improved - npm Package Compare versions

Comparing version 2.4.3 to 2.4.4

446

dist/src/utils/general_utils.js

@@ -24,2 +24,98 @@ "use strict";

};
exports.getMinDate = function (pList, pFormat, pMinDate) {
var vDate = new Date();
if (pList.length <= 0)
return pMinDate || vDate;
vDate.setTime((pMinDate && pMinDate.getTime()) || pList[0].getStart().getTime());
// Parse all Task Start dates to find min
for (var i = 0; i < pList.length; i++) {
if (pList[i].getStart().getTime() < vDate.getTime())
vDate.setTime(pList[i].getStart().getTime());
}
// Adjust min date to specific format boundaries (first of week or first of month)
if (pFormat == 'day') {
vDate.setDate(vDate.getDate() - 1);
while (vDate.getDay() % 7 != 1)
vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'week') {
vDate.setDate(vDate.getDate() - 1);
while (vDate.getDay() % 7 != 1)
vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'month') {
vDate.setDate(vDate.getDate() - 15);
while (vDate.getDate() > 1)
vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'quarter') {
vDate.setDate(vDate.getDate() - 31);
if (vDate.getMonth() == 0 || vDate.getMonth() == 1 || vDate.getMonth() == 2)
vDate.setFullYear(vDate.getFullYear(), 0, 1);
else if (vDate.getMonth() == 3 || vDate.getMonth() == 4 || vDate.getMonth() == 5)
vDate.setFullYear(vDate.getFullYear(), 3, 1);
else if (vDate.getMonth() == 6 || vDate.getMonth() == 7 || vDate.getMonth() == 8)
vDate.setFullYear(vDate.getFullYear(), 6, 1);
else if (vDate.getMonth() == 9 || vDate.getMonth() == 10 || vDate.getMonth() == 11)
vDate.setFullYear(vDate.getFullYear(), 9, 1);
}
else if (pFormat == 'hour') {
vDate.setHours(vDate.getHours() - 1);
while (vDate.getHours() % 6 != 0)
vDate.setHours(vDate.getHours() - 1);
}
if (pFormat == 'hour')
vDate.setMinutes(0, 0);
else
vDate.setHours(0, 0, 0);
return (vDate);
};
exports.getMaxDate = function (pList, pFormat, pMaxDate) {
var vDate = new Date();
if (pList.length <= 0)
return pMaxDate || vDate;
vDate.setTime((pMaxDate && pMaxDate.getTime()) || pList[0].getEnd().getTime());
// Parse all Task End dates to find max
for (var i = 0; i < pList.length; i++) {
if (pList[i].getEnd().getTime() > vDate.getTime())
vDate.setTime(pList[i].getEnd().getTime());
}
// Adjust max date to specific format boundaries (end of week or end of month)
if (pFormat == 'day') {
vDate.setDate(vDate.getDate() + 1);
while (vDate.getDay() % 7 != 0)
vDate.setDate(vDate.getDate() + 1);
}
else if (pFormat == 'week') {
//For weeks, what is the last logical boundary?
vDate.setDate(vDate.getDate() + 1);
while (vDate.getDay() % 7 != 0)
vDate.setDate(vDate.getDate() + 1);
}
else if (pFormat == 'month') {
// Set to last day of current Month
while (vDate.getDate() > 1)
vDate.setDate(vDate.getDate() + 1);
vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'quarter') {
// Set to last day of current Quarter
if (vDate.getMonth() == 0 || vDate.getMonth() == 1 || vDate.getMonth() == 2)
vDate.setFullYear(vDate.getFullYear(), 2, 31);
else if (vDate.getMonth() == 3 || vDate.getMonth() == 4 || vDate.getMonth() == 5)
vDate.setFullYear(vDate.getFullYear(), 5, 30);
else if (vDate.getMonth() == 6 || vDate.getMonth() == 7 || vDate.getMonth() == 8)
vDate.setFullYear(vDate.getFullYear(), 8, 30);
else if (vDate.getMonth() == 9 || vDate.getMonth() == 10 || vDate.getMonth() == 11)
vDate.setFullYear(vDate.getFullYear(), 11, 31);
}
else if (pFormat == 'hour') {
if (vDate.getHours() == 0)
vDate.setDate(vDate.getDate() + 1);
vDate.setHours(vDate.getHours() + 1);
while (vDate.getHours() % 6 != 5)
vDate.setHours(vDate.getHours() + 1);
}
return (vDate);
};
exports.findObj = function (theObj, theDoc) {

@@ -40,2 +136,154 @@ if (theDoc === void 0) { theDoc = null; }

};
exports.coerceDate = function (date) {
if (date instanceof Date) {
return date;
}
else {
var temp = new Date(date);
if (temp instanceof Date && !isNaN(temp.valueOf())) {
return temp;
}
}
};
exports.parseDateStr = function (pDateStr, pFormatStr) {
var vDate = new Date();
var vDateParts = pDateStr.split(/[^0-9]/);
if (pDateStr.length >= 10 && vDateParts.length >= 3) {
while (vDateParts.length < 5)
vDateParts.push(0);
switch (pFormatStr) {
case 'mm/dd/yyyy':
vDate = new Date(vDateParts[2], vDateParts[0] - 1, vDateParts[1], vDateParts[3], vDateParts[4]);
break;
case 'dd/mm/yyyy':
vDate = new Date(vDateParts[2], vDateParts[1] - 1, vDateParts[0], vDateParts[3], vDateParts[4]);
break;
case 'yyyy-mm-dd':
vDate = new Date(vDateParts[0], vDateParts[1] - 1, vDateParts[2], vDateParts[3], vDateParts[4]);
break;
}
}
return (vDate);
};
exports.formatDateStr = function (pDate, pDateFormatArr, pL) {
var vDateStr = '';
var vYear2Str = pDate.getFullYear().toString().substring(2, 4);
var vMonthStr = (pDate.getMonth() + 1) + '';
var vMonthArr = new Array(pL['january'], pL['february'], pL['march'], pL['april'], pL['maylong'], pL['june'], pL['july'], pL['august'], pL['september'], pL['october'], pL['november'], pL['december']);
var vDayArr = new Array(pL['sunday'], pL['monday'], pL['tuesday'], pL['wednesday'], pL['thursday'], pL['friday'], pL['saturday']);
var vMthArr = new Array(pL['jan'], pL['feb'], pL['mar'], pL['apr'], pL['may'], pL['jun'], pL['jul'], pL['aug'], pL['sep'], pL['oct'], pL['nov'], pL['dec']);
var vDyArr = new Array(pL['sun'], pL['mon'], pL['tue'], pL['wed'], pL['thu'], pL['fri'], pL['sat']);
for (var i = 0; i < pDateFormatArr.length; i++) {
switch (pDateFormatArr[i]) {
case 'dd':
if (pDate.getDate() < 10)
vDateStr += '0'; // now fall through
case 'd':
vDateStr += pDate.getDate();
break;
case 'day':
vDateStr += vDyArr[pDate.getDay()];
break;
case 'DAY':
vDateStr += vDayArr[pDate.getDay()];
break;
case 'mm':
if (parseInt(vMonthStr, 10) < 10)
vDateStr += '0'; // now fall through
case 'm':
vDateStr += vMonthStr;
break;
case 'mon':
vDateStr += vMthArr[pDate.getMonth()];
break;
case 'month':
vDateStr += vMonthArr[pDate.getMonth()];
break;
case 'yyyy':
vDateStr += pDate.getFullYear();
break;
case 'yy':
vDateStr += vYear2Str;
break;
case 'qq':
vDateStr += pL['qtr']; // now fall through
case 'q':
vDateStr += Math.floor(pDate.getMonth() / 3) + 1;
break;
case 'hh':
if ((((pDate.getHours() % 12) == 0) ? 12 : pDate.getHours() % 12) < 10)
vDateStr += '0'; // now fall through
case 'h':
vDateStr += ((pDate.getHours() % 12) == 0) ? 12 : pDate.getHours() % 12;
break;
case 'HH':
if ((pDate.getHours()) < 10)
vDateStr += '0'; // now fall through
case 'H':
vDateStr += (pDate.getHours());
break;
case 'MI':
if (pDate.getMinutes() < 10)
vDateStr += '0'; // now fall through
case 'mi':
vDateStr += pDate.getMinutes();
break;
case 'pm':
vDateStr += ((pDate.getHours()) < 12) ? 'am' : 'pm';
break;
case 'PM':
vDateStr += ((pDate.getHours()) < 12) ? 'AM' : 'PM';
break;
case 'ww':
if (exports.getIsoWeek(pDate) < 10)
vDateStr += '0'; // now fall through
case 'w':
vDateStr += exports.getIsoWeek(pDate);
break;
case 'week':
var vWeekNum = exports.getIsoWeek(pDate);
var vYear = pDate.getFullYear();
var vDayOfWeek = (pDate.getDay() == 0) ? 7 : pDate.getDay();
if (vWeekNum >= 52 && parseInt(vMonthStr, 10) === 1)
vYear--;
if (vWeekNum == 1 && parseInt(vMonthStr, 10) === 12)
vYear++;
if (vWeekNum < 10)
vWeekNum = parseInt('0' + vWeekNum, 10);
vDateStr += vYear + '-W' + vWeekNum + '-' + vDayOfWeek;
break;
default:
if (pL[pDateFormatArr[i].toLowerCase()])
vDateStr += pL[pDateFormatArr[i].toLowerCase()];
else
vDateStr += pDateFormatArr[i];
break;
}
}
return vDateStr;
};
exports.parseDateFormatStr = function (pFormatStr) {
var vComponantStr = '';
var vCurrChar = '';
var vSeparators = new RegExp('[\/\\ -.,\'":]');
var vDateFormatArray = new Array();
for (var i = 0; i < pFormatStr.length; i++) {
vCurrChar = pFormatStr.charAt(i);
if ((vCurrChar.match(vSeparators)) || (i + 1 == pFormatStr.length)) // separator or end of string
{
if ((i + 1 == pFormatStr.length) && (!(vCurrChar.match(vSeparators)))) // at end of string add any non-separator chars to the current component
{
vComponantStr += vCurrChar;
}
vDateFormatArray.push(vComponantStr);
if (vCurrChar.match(vSeparators))
vDateFormatArray.push(vCurrChar);
vComponantStr = '';
}
else {
vComponantStr += vCurrChar;
}
}
return vDateFormatArray;
};
exports.stripIds = function (pNode) {

@@ -82,90 +330,22 @@ for (var i = 0; i < pNode.childNodes.length; i++) {

};
exports.updateFlyingObj = function (e, pGanttChartObj, pTimer) {
var vCurTopBuf = 3;
var vCurLeftBuf = 5;
var vCurBotBuf = 3;
var vCurRightBuf = 15;
var vMouseX = (e) ? e.clientX : window.event.clientX;
var vMouseY = (e) ? e.clientY : window.event.clientY;
var vViewportX = document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
var vViewportY = document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
var vNewX = vMouseX;
var vNewY = vMouseY;
if (navigator.appName.toLowerCase() == 'microsoft internet explorer') {
// the clientX and clientY properties include the left and top borders of the client area
vMouseX -= document.documentElement.clientLeft;
vMouseY -= document.documentElement.clientTop;
var vZoomFactor = exports.getZoomFactor();
if (vZoomFactor != 1) { // IE 7 at non-default zoom level
vMouseX = Math.round(vMouseX / vZoomFactor);
vMouseY = Math.round(vMouseY / vZoomFactor);
}
}
var vScrollPos = exports.getScrollPositions();
/* Code for positioned right of the mouse by default*/
/*
if (vMouseX+vCurRightBuf+pGanttChartObj.vTool.offsetWidth>vViewportX)
{
if (vMouseX-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth<0) vNewX=vScrollPos.x;
else vNewX=vMouseX+vScrollPos.x-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth;
}
else vNewX=vMouseX+vScrollPos.x+vCurRightBuf;
*/
/* Code for positioned left of the mouse by default */
if (vMouseX - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth < 0) {
if (vMouseX + vCurRightBuf + pGanttChartObj.vTool.offsetWidth > vViewportX)
vNewX = vScrollPos.x;
else
vNewX = vMouseX + vScrollPos.x + vCurRightBuf;
}
else
vNewX = vMouseX + vScrollPos.x - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth;
/* Code for positioned below the mouse by default */
if (vMouseY + vCurBotBuf + pGanttChartObj.vTool.offsetHeight > vViewportY) {
if (vMouseY - vCurTopBuf - pGanttChartObj.vTool.offsetHeight < 0)
vNewY = vScrollPos.y;
else
vNewY = vMouseY + vScrollPos.y - vCurTopBuf - pGanttChartObj.vTool.offsetHeight;
}
else
vNewY = vMouseY + vScrollPos.y + vCurBotBuf;
/* Code for positioned above the mouse by default */
/*
if (vMouseY-vCurTopBuf-pGanttChartObj.vTool.offsetHeight<0)
{
if (vMouseY+vCurBotBuf+pGanttChartObj.vTool.offsetHeight>vViewportY) vNewY=vScrollPos.y;
else vNewY=vMouseY+vScrollPos.y+vCurBotBuf;
}
else vNewY=vMouseY+vScrollPos.y-vCurTopBuf-pGanttChartObj.vTool.offsetHeight;
*/
if (pGanttChartObj.getUseMove()) {
clearInterval(pGanttChartObj.vTool.moveInterval);
pGanttChartObj.vTool.moveInterval = setInterval(function () { exports.moveToolTip(vNewX, vNewY, pGanttChartObj.vTool, pTimer); }, pTimer);
}
else {
pGanttChartObj.vTool.style.left = vNewX + 'px';
pGanttChartObj.vTool.style.top = vNewY + 'px';
}
exports.getIsoWeek = function (pDate) {
// We have to compare against the monday of the first week of the year containing 04 jan *not* 01/01
// 60*60*24*1000=86400000
var dayMiliseconds = 86400000;
var keyDay = new Date(pDate.getFullYear(), 0, 4, 0, 0, 0);
var keyDayOfWeek = (keyDay.getDay() == 0) ? 6 : keyDay.getDay() - 1; // define monday as 0
var firstMondayYearTime = keyDay.getTime() - (keyDayOfWeek * dayMiliseconds);
var thisDate = new Date(pDate.getFullYear(), pDate.getMonth(), pDate.getDate(), 0, 0, 0); // This at 00:00:00
var thisTime = thisDate.getTime();
var daysFromFirstMonday = Math.round(((thisTime - firstMondayYearTime) / dayMiliseconds));
var lastWeek = 99;
var thisWeek = 99;
var firstMondayYear = new Date(firstMondayYearTime);
thisWeek = Math.ceil((daysFromFirstMonday + 1) / 7);
if (thisWeek <= 0)
thisWeek = exports.getIsoWeek(new Date(pDate.getFullYear() - 1, 11, 31, 0, 0, 0));
else if (thisWeek == 53 && (new Date(pDate.getFullYear(), 0, 1, 0, 0, 0)).getDay() != 4 && (new Date(pDate.getFullYear(), 11, 31, 0, 0, 0)).getDay() != 4)
thisWeek = 1;
return thisWeek;
};
exports.moveToolTip = function (pNewX, pNewY, pTool, timer) {
var vSpeed = parseInt(pTool.getAttribute('moveSpeed'));
var vOldX = parseInt(pTool.style.left);
var vOldY = parseInt(pTool.style.top);
if (pTool.style.visibility != 'visible') {
pTool.style.left = pNewX + 'px';
pTool.style.top = pNewY + 'px';
clearInterval(pTool.moveInterval);
}
else {
if (pNewX != vOldX && pNewY != vOldY) {
vOldX += Math.ceil((pNewX - vOldX) / vSpeed);
vOldY += Math.ceil((pNewY - vOldY) / vSpeed);
pTool.style.left = vOldX + 'px';
pTool.style.top = vOldY + 'px';
}
else {
clearInterval(pTool.moveInterval);
}
}
};
exports.getScrollPositions = function () {

@@ -187,5 +367,3 @@ var vScrollLeft = window.pageXOffset;

var outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll'; // forcing scrollbar to appear
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
outer.className = 'gscrollbar-calculation-container';
document.body.appendChild(outer);

@@ -386,2 +564,90 @@ // Creating inner element and placing it in the container

exports.isParentElementOrSelf = isParentElementOrSelf;
exports.updateFlyingObj = function (e, pGanttChartObj, pTimer) {
var vCurTopBuf = 3;
var vCurLeftBuf = 5;
var vCurBotBuf = 3;
var vCurRightBuf = 15;
var vMouseX = (e) ? e.clientX : window.event.clientX;
var vMouseY = (e) ? e.clientY : window.event.clientY;
var vViewportX = document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
var vViewportY = document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
var vNewX = vMouseX;
var vNewY = vMouseY;
if (navigator.appName.toLowerCase() == 'microsoft internet explorer') {
// the clientX and clientY properties include the left and top borders of the client area
vMouseX -= document.documentElement.clientLeft;
vMouseY -= document.documentElement.clientTop;
var vZoomFactor = exports.getZoomFactor();
if (vZoomFactor != 1) { // IE 7 at non-default zoom level
vMouseX = Math.round(vMouseX / vZoomFactor);
vMouseY = Math.round(vMouseY / vZoomFactor);
}
}
var vScrollPos = exports.getScrollPositions();
/* Code for positioned right of the mouse by default*/
/*
if (vMouseX+vCurRightBuf+pGanttChartObj.vTool.offsetWidth>vViewportX)
{
if (vMouseX-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth<0) vNewX=vScrollPos.x;
else vNewX=vMouseX+vScrollPos.x-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth;
}
else vNewX=vMouseX+vScrollPos.x+vCurRightBuf;
*/
/* Code for positioned left of the mouse by default */
if (vMouseX - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth < 0) {
if (vMouseX + vCurRightBuf + pGanttChartObj.vTool.offsetWidth > vViewportX)
vNewX = vScrollPos.x;
else
vNewX = vMouseX + vScrollPos.x + vCurRightBuf;
}
else
vNewX = vMouseX + vScrollPos.x - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth;
/* Code for positioned below the mouse by default */
if (vMouseY + vCurBotBuf + pGanttChartObj.vTool.offsetHeight > vViewportY) {
if (vMouseY - vCurTopBuf - pGanttChartObj.vTool.offsetHeight < 0)
vNewY = vScrollPos.y;
else
vNewY = vMouseY + vScrollPos.y - vCurTopBuf - pGanttChartObj.vTool.offsetHeight;
}
else
vNewY = vMouseY + vScrollPos.y + vCurBotBuf;
/* Code for positioned above the mouse by default */
/*
if (vMouseY-vCurTopBuf-pGanttChartObj.vTool.offsetHeight<0)
{
if (vMouseY+vCurBotBuf+pGanttChartObj.vTool.offsetHeight>vViewportY) vNewY=vScrollPos.y;
else vNewY=vMouseY+vScrollPos.y+vCurBotBuf;
}
else vNewY=vMouseY+vScrollPos.y-vCurTopBuf-pGanttChartObj.vTool.offsetHeight;
*/
if (pGanttChartObj.getUseMove()) {
clearInterval(pGanttChartObj.vTool.moveInterval);
pGanttChartObj.vTool.moveInterval = setInterval(function () { exports.moveToolTip(vNewX, vNewY, pGanttChartObj.vTool, pTimer); }, pTimer);
}
else {
pGanttChartObj.vTool.style.left = vNewX + 'px';
pGanttChartObj.vTool.style.top = vNewY + 'px';
}
};
exports.moveToolTip = function (pNewX, pNewY, pTool, timer) {
var vSpeed = parseInt(pTool.getAttribute('moveSpeed'));
var vOldX = parseInt(pTool.style.left);
var vOldY = parseInt(pTool.style.top);
if (pTool.style.visibility != 'visible') {
pTool.style.left = pNewX + 'px';
pTool.style.top = pNewY + 'px';
clearInterval(pTool.moveInterval);
}
else {
if (pNewX != vOldX && pNewY != vOldY) {
vOldX += Math.ceil((pNewX - vOldX) / vSpeed);
vOldY += Math.ceil((pNewY - vOldY) / vSpeed);
pTool.style.left = vOldX + 'px';
pTool.style.top = vOldY + 'px';
}
else {
clearInterval(pTool.moveInterval);
}
}
};
//# sourceMappingURL=general_utils.js.map
{
"name": "jsgantt-improved",
"version": "2.4.3",
"version": "2.4.4",
"description": "jsgantt-improved",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -39,3 +39,3 @@ /*

stripIds, stripUnwanted, delayedHide, getOffset,
getScrollPositions, isIE, benchMark, getZoomFactor, hideToolTip, fadeToolTip, criticalPath, updateFlyingObj, moveToolTip
getScrollPositions, isIE, benchMark, getZoomFactor, hideToolTip, fadeToolTip, criticalPath, updateFlyingObj, moveToolTip,
} from "./utils/general_utils";

@@ -42,0 +42,0 @@ import { parseXML, parseXMLString, findXMLNode, getXMLNodeValue, AddXMLTask } from './xml';

@@ -25,2 +25,98 @@

export const getMinDate = function (pList, pFormat, pMinDate) {
let vDate = new Date();
if (pList.length <= 0) return pMinDate || vDate;
vDate.setTime((pMinDate && pMinDate.getTime()) || pList[0].getStart().getTime());
// Parse all Task Start dates to find min
for (let i = 0; i < pList.length; i++) {
if (pList[i].getStart().getTime() < vDate.getTime()) vDate.setTime(pList[i].getStart().getTime());
}
// Adjust min date to specific format boundaries (first of week or first of month)
if (pFormat == 'day') {
vDate.setDate(vDate.getDate() - 1);
while (vDate.getDay() % 7 != 1) vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'week') {
vDate.setDate(vDate.getDate() - 1);
while (vDate.getDay() % 7 != 1) vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'month') {
vDate.setDate(vDate.getDate() - 15);
while (vDate.getDate() > 1) vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'quarter') {
vDate.setDate(vDate.getDate() - 31);
if (vDate.getMonth() == 0 || vDate.getMonth() == 1 || vDate.getMonth() == 2)
vDate.setFullYear(vDate.getFullYear(), 0, 1);
else if (vDate.getMonth() == 3 || vDate.getMonth() == 4 || vDate.getMonth() == 5)
vDate.setFullYear(vDate.getFullYear(), 3, 1);
else if (vDate.getMonth() == 6 || vDate.getMonth() == 7 || vDate.getMonth() == 8)
vDate.setFullYear(vDate.getFullYear(), 6, 1);
else if (vDate.getMonth() == 9 || vDate.getMonth() == 10 || vDate.getMonth() == 11)
vDate.setFullYear(vDate.getFullYear(), 9, 1);
}
else if (pFormat == 'hour') {
vDate.setHours(vDate.getHours() - 1);
while (vDate.getHours() % 6 != 0) vDate.setHours(vDate.getHours() - 1);
}
if (pFormat == 'hour') vDate.setMinutes(0, 0);
else vDate.setHours(0, 0, 0);
return (vDate);
};
export const getMaxDate = function (pList, pFormat, pMaxDate) {
let vDate = new Date();
if (pList.length <= 0) return pMaxDate || vDate;
vDate.setTime((pMaxDate && pMaxDate.getTime()) || pList[0].getEnd().getTime());
// Parse all Task End dates to find max
for (let i = 0; i < pList.length; i++) {
if (pList[i].getEnd().getTime() > vDate.getTime()) vDate.setTime(pList[i].getEnd().getTime());
}
// Adjust max date to specific format boundaries (end of week or end of month)
if (pFormat == 'day') {
vDate.setDate(vDate.getDate() + 1);
while (vDate.getDay() % 7 != 0) vDate.setDate(vDate.getDate() + 1);
}
else if (pFormat == 'week') {
//For weeks, what is the last logical boundary?
vDate.setDate(vDate.getDate() + 1);
while (vDate.getDay() % 7 != 0) vDate.setDate(vDate.getDate() + 1);
}
else if (pFormat == 'month') {
// Set to last day of current Month
while (vDate.getDate() > 1) vDate.setDate(vDate.getDate() + 1);
vDate.setDate(vDate.getDate() - 1);
}
else if (pFormat == 'quarter') {
// Set to last day of current Quarter
if (vDate.getMonth() == 0 || vDate.getMonth() == 1 || vDate.getMonth() == 2)
vDate.setFullYear(vDate.getFullYear(), 2, 31);
else if (vDate.getMonth() == 3 || vDate.getMonth() == 4 || vDate.getMonth() == 5)
vDate.setFullYear(vDate.getFullYear(), 5, 30);
else if (vDate.getMonth() == 6 || vDate.getMonth() == 7 || vDate.getMonth() == 8)
vDate.setFullYear(vDate.getFullYear(), 8, 30);
else if (vDate.getMonth() == 9 || vDate.getMonth() == 10 || vDate.getMonth() == 11)
vDate.setFullYear(vDate.getFullYear(), 11, 31);
}
else if (pFormat == 'hour') {
if (vDate.getHours() == 0) vDate.setDate(vDate.getDate() + 1);
vDate.setHours(vDate.getHours() + 1);
while (vDate.getHours() % 6 != 5) vDate.setHours(vDate.getHours() + 1);
}
return (vDate);
};
export const findObj = function (theObj, theDoc = null) {

@@ -38,2 +134,151 @@ let p, i, foundObj;

export const coerceDate = function (date) {
if (date instanceof Date) {
return date;
} else {
const temp = new Date(date);
if (temp instanceof Date && !isNaN(temp.valueOf())) {
return temp;
}
}
}
export const parseDateStr = function (pDateStr, pFormatStr) {
let vDate = new Date();
let vDateParts = pDateStr.split(/[^0-9]/);
if (pDateStr.length >= 10 && vDateParts.length >= 3) {
while (vDateParts.length < 5) vDateParts.push(0);
switch (pFormatStr) {
case 'mm/dd/yyyy':
vDate = new Date(vDateParts[2], vDateParts[0] - 1, vDateParts[1], vDateParts[3], vDateParts[4]);
break;
case 'dd/mm/yyyy':
vDate = new Date(vDateParts[2], vDateParts[1] - 1, vDateParts[0], vDateParts[3], vDateParts[4]);
break;
case 'yyyy-mm-dd':
vDate = new Date(vDateParts[0], vDateParts[1] - 1, vDateParts[2], vDateParts[3], vDateParts[4]);
break;
}
}
return (vDate);
};
export const formatDateStr = function (pDate, pDateFormatArr, pL) {
let vDateStr = '';
let vYear2Str = pDate.getFullYear().toString().substring(2, 4);
let vMonthStr = (pDate.getMonth() + 1) + '';
let vMonthArr = new Array(pL['january'], pL['february'], pL['march'], pL['april'], pL['maylong'], pL['june'], pL['july'], pL['august'], pL['september'], pL['october'], pL['november'], pL['december']);
let vDayArr = new Array(pL['sunday'], pL['monday'], pL['tuesday'], pL['wednesday'], pL['thursday'], pL['friday'], pL['saturday']);
let vMthArr = new Array(pL['jan'], pL['feb'], pL['mar'], pL['apr'], pL['may'], pL['jun'], pL['jul'], pL['aug'], pL['sep'], pL['oct'], pL['nov'], pL['dec']);
let vDyArr = new Array(pL['sun'], pL['mon'], pL['tue'], pL['wed'], pL['thu'], pL['fri'], pL['sat']);
for (let i = 0; i < pDateFormatArr.length; i++) {
switch (pDateFormatArr[i]) {
case 'dd':
if (pDate.getDate() < 10) vDateStr += '0'; // now fall through
case 'd':
vDateStr += pDate.getDate();
break;
case 'day':
vDateStr += vDyArr[pDate.getDay()];
break;
case 'DAY':
vDateStr += vDayArr[pDate.getDay()];
break;
case 'mm':
if (parseInt(vMonthStr, 10) < 10) vDateStr += '0'; // now fall through
case 'm':
vDateStr += vMonthStr;
break;
case 'mon':
vDateStr += vMthArr[pDate.getMonth()];
break;
case 'month':
vDateStr += vMonthArr[pDate.getMonth()];
break;
case 'yyyy':
vDateStr += pDate.getFullYear();
break;
case 'yy':
vDateStr += vYear2Str;
break;
case 'qq':
vDateStr += pL['qtr']; // now fall through
case 'q':
vDateStr += Math.floor(pDate.getMonth() / 3) + 1;
break;
case 'hh':
if ((((pDate.getHours() % 12) == 0) ? 12 : pDate.getHours() % 12) < 10) vDateStr += '0'; // now fall through
case 'h':
vDateStr += ((pDate.getHours() % 12) == 0) ? 12 : pDate.getHours() % 12;
break;
case 'HH':
if ((pDate.getHours()) < 10) vDateStr += '0'; // now fall through
case 'H':
vDateStr += (pDate.getHours());
break;
case 'MI':
if (pDate.getMinutes() < 10) vDateStr += '0'; // now fall through
case 'mi':
vDateStr += pDate.getMinutes();
break;
case 'pm':
vDateStr += ((pDate.getHours()) < 12) ? 'am' : 'pm';
break;
case 'PM':
vDateStr += ((pDate.getHours()) < 12) ? 'AM' : 'PM';
break;
case 'ww':
if (getIsoWeek(pDate) < 10) vDateStr += '0'; // now fall through
case 'w':
vDateStr += getIsoWeek(pDate);
break;
case 'week':
let vWeekNum = getIsoWeek(pDate);
let vYear = pDate.getFullYear();
let vDayOfWeek = (pDate.getDay() == 0) ? 7 : pDate.getDay();
if (vWeekNum >= 52 && parseInt(vMonthStr, 10) === 1) vYear--;
if (vWeekNum == 1 && parseInt(vMonthStr, 10) === 12) vYear++;
if (vWeekNum < 10) vWeekNum = parseInt('0' + vWeekNum, 10);
vDateStr += vYear + '-W' + vWeekNum + '-' + vDayOfWeek;
break;
default:
if (pL[pDateFormatArr[i].toLowerCase()]) vDateStr += pL[pDateFormatArr[i].toLowerCase()];
else vDateStr += pDateFormatArr[i];
break;
}
}
return vDateStr;
};
export const parseDateFormatStr = function (pFormatStr) {
let vComponantStr = '';
let vCurrChar = '';
let vSeparators = new RegExp('[\/\\ -.,\'":]');
let vDateFormatArray = new Array();
for (let i = 0; i < pFormatStr.length; i++) {
vCurrChar = pFormatStr.charAt(i);
if ((vCurrChar.match(vSeparators)) || (i + 1 == pFormatStr.length)) // separator or end of string
{
if ((i + 1 == pFormatStr.length) && (!(vCurrChar.match(vSeparators)))) // at end of string add any non-separator chars to the current component
{
vComponantStr += vCurrChar;
}
vDateFormatArray.push(vComponantStr);
if (vCurrChar.match(vSeparators)) vDateFormatArray.push(vCurrChar);
vComponantStr = '';
}
else {
vComponantStr += vCurrChar;
}
}
return vDateFormatArray;
};
export const stripIds = function (pNode) {

@@ -83,97 +328,24 @@ for (let i = 0; i < pNode.childNodes.length; i++) {

export const getIsoWeek = function (pDate) {
// We have to compare against the monday of the first week of the year containing 04 jan *not* 01/01
// 60*60*24*1000=86400000
let dayMiliseconds = 86400000;
let keyDay = new Date(pDate.getFullYear(), 0, 4, 0, 0, 0);
let keyDayOfWeek = (keyDay.getDay() == 0) ? 6 : keyDay.getDay() - 1; // define monday as 0
let firstMondayYearTime = keyDay.getTime() - (keyDayOfWeek * dayMiliseconds);
let thisDate = new Date(pDate.getFullYear(), pDate.getMonth(), pDate.getDate(), 0, 0, 0); // This at 00:00:00
let thisTime = thisDate.getTime();
let daysFromFirstMonday = Math.round(((thisTime - firstMondayYearTime) / dayMiliseconds));
let lastWeek = 99;
let thisWeek = 99;
export const updateFlyingObj = function (e, pGanttChartObj, pTimer) {
let vCurTopBuf = 3;
let vCurLeftBuf = 5;
let vCurBotBuf = 3;
let vCurRightBuf = 15;
let vMouseX = (e) ? e.clientX : (<MouseEvent>window.event).clientX;
let vMouseY = (e) ? e.clientY : (<MouseEvent>window.event).clientY;
let vViewportX = document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
let vViewportY = document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
let vNewX = vMouseX;
let vNewY = vMouseY;
let firstMondayYear = new Date(firstMondayYearTime);
if (navigator.appName.toLowerCase() == 'microsoft internet explorer') {
// the clientX and clientY properties include the left and top borders of the client area
vMouseX -= document.documentElement.clientLeft;
vMouseY -= document.documentElement.clientTop;
thisWeek = Math.ceil((daysFromFirstMonday + 1) / 7);
let vZoomFactor = getZoomFactor();
if (vZoomFactor != 1) {// IE 7 at non-default zoom level
vMouseX = Math.round(vMouseX / vZoomFactor);
vMouseY = Math.round(vMouseY / vZoomFactor);
}
}
let vScrollPos = getScrollPositions();
/* Code for positioned right of the mouse by default*/
/*
if (vMouseX+vCurRightBuf+pGanttChartObj.vTool.offsetWidth>vViewportX)
{
if (vMouseX-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth<0) vNewX=vScrollPos.x;
else vNewX=vMouseX+vScrollPos.x-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth;
}
else vNewX=vMouseX+vScrollPos.x+vCurRightBuf;
*/
/* Code for positioned left of the mouse by default */
if (vMouseX - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth < 0) {
if (vMouseX + vCurRightBuf + pGanttChartObj.vTool.offsetWidth > vViewportX) vNewX = vScrollPos.x;
else vNewX = vMouseX + vScrollPos.x + vCurRightBuf;
}
else vNewX = vMouseX + vScrollPos.x - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth;
/* Code for positioned below the mouse by default */
if (vMouseY + vCurBotBuf + pGanttChartObj.vTool.offsetHeight > vViewportY) {
if (vMouseY - vCurTopBuf - pGanttChartObj.vTool.offsetHeight < 0) vNewY = vScrollPos.y;
else vNewY = vMouseY + vScrollPos.y - vCurTopBuf - pGanttChartObj.vTool.offsetHeight;
}
else vNewY = vMouseY + vScrollPos.y + vCurBotBuf;
/* Code for positioned above the mouse by default */
/*
if (vMouseY-vCurTopBuf-pGanttChartObj.vTool.offsetHeight<0)
{
if (vMouseY+vCurBotBuf+pGanttChartObj.vTool.offsetHeight>vViewportY) vNewY=vScrollPos.y;
else vNewY=vMouseY+vScrollPos.y+vCurBotBuf;
}
else vNewY=vMouseY+vScrollPos.y-vCurTopBuf-pGanttChartObj.vTool.offsetHeight;
*/
if (pGanttChartObj.getUseMove()) {
clearInterval(pGanttChartObj.vTool.moveInterval);
pGanttChartObj.vTool.moveInterval = setInterval(function () { moveToolTip(vNewX, vNewY, pGanttChartObj.vTool, pTimer); }, pTimer);
}
else {
pGanttChartObj.vTool.style.left = vNewX + 'px';
pGanttChartObj.vTool.style.top = vNewY + 'px';
}
if (thisWeek <= 0) thisWeek = getIsoWeek(new Date(pDate.getFullYear() - 1, 11, 31, 0, 0, 0));
else if (thisWeek == 53 && (new Date(pDate.getFullYear(), 0, 1, 0, 0, 0)).getDay() != 4 && (new Date(pDate.getFullYear(), 11, 31, 0, 0, 0)).getDay() != 4) thisWeek = 1;
return thisWeek;
};
export const moveToolTip = function (pNewX, pNewY, pTool, timer) {
let vSpeed = parseInt(pTool.getAttribute('moveSpeed'));
let vOldX = parseInt(pTool.style.left);
let vOldY = parseInt(pTool.style.top);
if (pTool.style.visibility != 'visible') {
pTool.style.left = pNewX + 'px';
pTool.style.top = pNewY + 'px';
clearInterval(pTool.moveInterval);
}
else {
if (pNewX != vOldX && pNewY != vOldY) {
vOldX += Math.ceil((pNewX - vOldX) / vSpeed);
vOldY += Math.ceil((pNewY - vOldY) / vSpeed);
pTool.style.left = vOldX + 'px';
pTool.style.top = vOldY + 'px';
}
else {
clearInterval(pTool.moveInterval);
}
}
};
export const getScrollPositions = function () {

@@ -196,5 +368,3 @@ let vScrollLeft = window.pageXOffset;

const outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll'; // forcing scrollbar to appear
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
outer.className = 'gscrollbar-calculation-container';
document.body.appendChild(outer);

@@ -405,2 +575,98 @@

}
}
}
export const updateFlyingObj = function (e, pGanttChartObj, pTimer) {
let vCurTopBuf = 3;
let vCurLeftBuf = 5;
let vCurBotBuf = 3;
let vCurRightBuf = 15;
let vMouseX = (e) ? e.clientX : (<MouseEvent>window.event).clientX;
let vMouseY = (e) ? e.clientY : (<MouseEvent>window.event).clientY;
let vViewportX = document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
let vViewportY = document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
let vNewX = vMouseX;
let vNewY = vMouseY;
if (navigator.appName.toLowerCase() == 'microsoft internet explorer') {
// the clientX and clientY properties include the left and top borders of the client area
vMouseX -= document.documentElement.clientLeft;
vMouseY -= document.documentElement.clientTop;
let vZoomFactor = getZoomFactor();
if (vZoomFactor != 1) {// IE 7 at non-default zoom level
vMouseX = Math.round(vMouseX / vZoomFactor);
vMouseY = Math.round(vMouseY / vZoomFactor);
}
}
let vScrollPos = getScrollPositions();
/* Code for positioned right of the mouse by default*/
/*
if (vMouseX+vCurRightBuf+pGanttChartObj.vTool.offsetWidth>vViewportX)
{
if (vMouseX-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth<0) vNewX=vScrollPos.x;
else vNewX=vMouseX+vScrollPos.x-vCurLeftBuf-pGanttChartObj.vTool.offsetWidth;
}
else vNewX=vMouseX+vScrollPos.x+vCurRightBuf;
*/
/* Code for positioned left of the mouse by default */
if (vMouseX - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth < 0) {
if (vMouseX + vCurRightBuf + pGanttChartObj.vTool.offsetWidth > vViewportX) vNewX = vScrollPos.x;
else vNewX = vMouseX + vScrollPos.x + vCurRightBuf;
}
else vNewX = vMouseX + vScrollPos.x - vCurLeftBuf - pGanttChartObj.vTool.offsetWidth;
/* Code for positioned below the mouse by default */
if (vMouseY + vCurBotBuf + pGanttChartObj.vTool.offsetHeight > vViewportY) {
if (vMouseY - vCurTopBuf - pGanttChartObj.vTool.offsetHeight < 0) vNewY = vScrollPos.y;
else vNewY = vMouseY + vScrollPos.y - vCurTopBuf - pGanttChartObj.vTool.offsetHeight;
}
else vNewY = vMouseY + vScrollPos.y + vCurBotBuf;
/* Code for positioned above the mouse by default */
/*
if (vMouseY-vCurTopBuf-pGanttChartObj.vTool.offsetHeight<0)
{
if (vMouseY+vCurBotBuf+pGanttChartObj.vTool.offsetHeight>vViewportY) vNewY=vScrollPos.y;
else vNewY=vMouseY+vScrollPos.y+vCurBotBuf;
}
else vNewY=vMouseY+vScrollPos.y-vCurTopBuf-pGanttChartObj.vTool.offsetHeight;
*/
if (pGanttChartObj.getUseMove()) {
clearInterval(pGanttChartObj.vTool.moveInterval);
pGanttChartObj.vTool.moveInterval = setInterval(function () { moveToolTip(vNewX, vNewY, pGanttChartObj.vTool, pTimer); }, pTimer);
}
else {
pGanttChartObj.vTool.style.left = vNewX + 'px';
pGanttChartObj.vTool.style.top = vNewY + 'px';
}
};
export const moveToolTip = function (pNewX, pNewY, pTool, timer) {
let vSpeed = parseInt(pTool.getAttribute('moveSpeed'));
let vOldX = parseInt(pTool.style.left);
let vOldY = parseInt(pTool.style.top);
if (pTool.style.visibility != 'visible') {
pTool.style.left = pNewX + 'px';
pTool.style.top = pNewY + 'px';
clearInterval(pTool.moveInterval);
}
else {
if (pNewX != vOldX && pNewY != vOldY) {
vOldX += Math.ceil((pNewX - vOldX) / vSpeed);
vOldY += Math.ceil((pNewY - vOldY) / vSpeed);
pTool.style.left = vOldX + 'px';
pTool.style.top = vOldY + 'px';
}
else {
clearInterval(pTool.moveInterval);
}
}
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc