GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/nginx/html/Scheduler/js/ |
Upload File : |
'use strict'; /*jslint node: true */ /*jshint esversion: 6 */ /*jshint unused:false*/ // let PC,CH,CG; function ttPosition(){} function Validate(){} // site.js // _Initialize() ............................................ Initialize the page. // _Initialize_Tooltip() .................................... Initialize the tooltip dialog. // _Resized() ............................................... Perform js needed if the page is resized. // _Scrolled() .............................................. Perform js needed if the page is scrolled. // Date_Set_BothDates(sDateId,eDateId,sDateValue,eDateValue) .. Fill in the start and end dates. // DateUSA(date) ............................................ Return the date in USA format. // ElementBounds(eId) ....................................... Return left, top, right, bottom, width, height, border, margin, and padding of an element. // formSubmit(e, formTask, formAction) ...................... Submits the form and additionally creates or sets hidden element values or the form action. // getForm(e) ............................................... Returns the form element. // ScrollLeftTop() .......................................... Returns the scroll position { left:left, top:top }. // PositionSidenav() ........................................ Reposition the side nav. Called by other js. // today(textFieldId) ....................................... Put today's date in text field. // uuid() ................................................... Generate a uuid for form control (used to prevent reload problems). let DEBUG_ON = true; let DEBUG_OFF = false; // Site global js variables. var dialogContainerLeft = 0; var dialogContainerTop = 0; var dialogContainerZindex = 500; var dragElement; var textboxContainerLeft = 0; var textboxContainerTop = 0; var textboxContainerZindex = 500; // BEGIN Custom tooltip settings. var DEBUG_hPosition = false; var DEBUG_vPosition = false; var ttDiv = 'tooltipDiv'; var ttOffsetX = 25; // Customize x offset of the tooltip from the mouse position. var ttOffsetY = -25; // Customize y offset of the tooltip from the mouse position. var ie = document.all; var ns6 = document.getElementById && !document.all; var ttEnable = false; // Hide the tooltip. var ttDebugMessage = ''; var ttinnerHTML = ''; var ttObj; var ttClasses = []; var mvDiv = 'movementDiv'; // div that is to follow the mouse. var mvOffsetX = 5; // x offset from mouse position. var ttMoveOffsetX = 5; var mvOffsetY = 20; // y offset from mouse position. var ttMoveOffsetY = 20; // END Custom tooltip settings. //window.onresize = _Resized; //window.onscroll = _Scrolled; /** / let Booga = true; function Ooga() { var DEBUG = DEBUG_ON; if ( DEBUG ) { console.group(`${PC}Ooga[site]`,CG); }//Collapsed if ( DEBUG ) { console.groupEnd(); } } function Ooga() { var DEBUG = DEBUG_ON; if ( DEBUG ) { console.group(`${PC}Ooga[site] the second`,CG); }//Collapsed if ( DEBUG ) { console.groupEnd(); } } /**/ // _Initialize() // Initialize the page. var _Initialize = function() { console.warn('_Initialize[]'); PositionSidenav(); //Ooga(); }; // END _Initialize. // _Initialize_Tooltip() // Initialize the tooltip dialog. function _Initialize_Tooltip() { console.log(PC+'_Initialize_Tooltip[]',CH); ttObj = document.all ? document.all[ttDiv] : document.getElementById ? document.getElementById(ttDiv) : ""; document.addEventListener('mousemove',ttPosition); } // END _Initialize_Tooltip. // _Resized() // Perform js needed if the page is resized. var _Resized = function() { console.warn('_Resized[]'); PositionSidenav(); }; // END _Resized. // _Scrolled() // Perform js needed if the page is scrolled. var _Scrolled = function() { console.warn('_Scrolled[]'); PositionSidenav(); }; // END _Scrolled. // Date_Set_BothDates(StartDateId,eDateId,sDateValue,eDateValue) ***** MOVE TO schedule.js ***** // Fill in the start and end dates. // StartDateId = id of the start date. // EndDateId = id of the end date. // sDateValue = value for the start date. // eDateValue = value for the end date. function Date_Set_BothDates(StartDateId,EndDateId,sDateValue,eDateValue) { var DEBUG_dateStartEnd_Set = true; if ( DEBUG_dateStartEnd_Set ) { console.warn('Date_Set_BothDates[StartDateId='+StartDateId+', EndDateId='+EndDateId+', sDateValue='+sDateValue+', eDateValue='+eDateValue+')'); } if ( document.getElementById(StartDateId) ) { document.getElementById(StartDateId).value = sDateValue; var SDv = document.getElementById(StartDateId).value; if ( DEBUG_dateStartEnd_Set ) { console.log(StartDateId+'.value='+SDv); } var jsReturnFunction = 'Date_Set_EndDate("'+EndDateId+'", "'+eDateValue+'");'; // Setup return call for Date_Set_EndDate function. console.log('jsReturnFunction='+jsReturnFunction); Validate(document.getElementById(StartDateId),jsReturnFunction,'site.js Date_Set_BothDates:114'); } else { console.log(StartDateId+' not found.'); } } // END Date_Set_BothDates. // Date_Set_EndDate(StartDateId,eDateId,sDateValue,eDateValue) ***** MOVE TO schedule.js ***** // Fill in the end date. // sDateValue = value for the start date. // eDateValue = value for the end date. function Date_Set_EndDate(EndDateId, eDateValue) { var DEBUG_dateStartEnd_Set = true; if ( DEBUG_dateStartEnd_Set ) { console.warn('Date_Set_EndDate[EndDateId='+EndDateId+', eDateValue='+eDateValue+')'); } // Call Validate for end date using jsReturnFunction call in Validate above. See Validate function in schedule2.js line 36. if ( document.getElementById(EndDateId) ) { document.getElementById(EndDateId).value = eDateValue; var EDv = document.getElementById(EndDateId).value; if ( DEBUG_dateStartEnd_Set ) { console.log(EndDateId+'.value='+EDv); } Validate(document.getElementById(EndDateId),false,'site.js Date_Set_EndDate 132'); } else { console.log(EndDateId+' not found.'); } //if ( document.getElementById() ) { document.getElementById(EndDateId).value = eDateValue; } else { console.log(EndDateId+' not found.'); } } // END Date_Set_EndDate. // DateUSA(date) // Return the date in USA format. function DateUSA(date) { var dateParts = date.split('-'); return dateParts[1]+'/'+dateParts[2]+'/'+dateParts[0]; } // END DateUSA. // ElementBounds(eId) // Return left, top, right, bottom, width, height, border, margin, and padding of an element. // eId = element.id or element to check. // { left, top, right, bottom, width, height, border{ left, top, right, bottom }, margin{left, top, right, bottom }, padding{ left, top, right, bottom } }. function ElementBounds(eId,by) { var DEBUG = false; if ( DEBUG ) { console.log(`${PC}ElementBounds eId=${eId}`,CT); } let e; // Get element and element.id. if ( typeof eId === 'string' ) { // eId is the element.id. if ( DEBUG ) { console.warn('ElementBounds[eId='+eId+' by='+by+']'); } e = document.getElementById(eId); } else if ( typeof eId === 'object' ) { // eId is the element. if ( eId && (typeof eId.id !== 'undefined') ) { e = eId; eId = e.id; } else { eId = ''; } } else { e = false; } if ( DEBUG ) { console.group(`${PC}ElementBounds[eId=${eId}]`,CG); }//Collapsed var left = 0; var top = 0; var right = 0; var bottom = 0; var width = 0; var height = 0; var border = { left:0, top:0, right:0, bottom:0 }; var margin = { left:0, top:0, right:0, bottom:0 }; var padding = { left:0, top:0, right:0, bottom:0 }; if ( e ) { width = parseFloat(e.offsetWidth); height = parseFloat(e.offsetHeight); var style = e.currentStyle || window.getComputedStyle(e); border.left = parseFloat(style.borderLeftWidth.replace('px','')); border.top = parseFloat(style.borderTopWidth.replace('px','')); border.right = parseFloat(style.borderRightWidth.replace('px','')); border.bottom = parseFloat(style.borderBottomWidth.replace('px','')); margin.left = parseFloat(style.marginLeft.replace('px','')); margin.top = parseFloat(style.marginTop.replace('px','')); margin.right = parseFloat(style.marginRight.replace('px','')); margin.bottom = parseFloat(style.marginBottom.replace('px','')); padding.left = parseFloat(style.paddingLeft.replace('px','')); padding.top = parseFloat(style.paddingTop.replace('px','')); padding.right = parseFloat(style.paddingRight.replace('px','')); padding.bottom = parseFloat(style.paddingBottom.replace('px','')); // Get the left and top by walking up the parent elements. var eWalk = e; while( eWalk && eWalk.tagName && eWalk.tagName !== "BODY" ) { left += parseFloat(eWalk.offsetLeft); top += parseFloat(eWalk.offsetTop); if ( DEBUG ) { console.log("\t"+'eWalk.id='+eWalk.id+' left='+left+' top='+top); } eWalk = eWalk.offsetParent; } right = left + width; bottom = top + height; } else { console.info('No element with id '+eId+' found. by='+by); } if ( DEBUG ) { console.log("\t"+eId+' left='+left+' top='+top+' right='+right+' bottom='+bottom+' width='+width+' height='+height); } if ( DEBUG ) { console.log("\t"+eId+' border='+JSON.stringify(border)); console.log("\t"+eId+' margin='+JSON.stringify(margin)); console.log("\t"+eId+' padding='+JSON.stringify(padding)); } if ( DEBUG ) { console.log(`${PC}END ${PC}ElementBounds`,SE,ST); console.groupEnd(); } return { top:top, right:right, bottom:bottom, left:left, width:width, height:height, border:{ left:border.left, top:border.top, right:border.right, bottom:border.bottom }, margin:{ left:margin.left, top:margin.top, right:margin.right, bottom:margin.bottom }, padding:{ left:padding.left, top:padding.top, right:padding.right, bottom:padding.bottom } }; } // END ElementBounds. /** / // ElementBoundsCorrected(eId) // Return left, top, right, bottom, width, height, border, margin, and padding of an element corrected by the schedulecontainer. // eId = element.id or element to check. // { left, top, right, bottom, width, height, border{ left, top, right, bottom }, margin{left, top, right, bottom }, padding{ left, top, right, bottom } }. function ElementBoundsCorrected(eId,by) { var DEBUG = false; let e; // Get element and element.id. if ( typeof eId === 'string' ) { // eId is the element.id. e = document.getElementById(eId); } else if ( typeof eId === 'object' ) { // eId is the element. if ( eId && (typeof eId.id !== 'undefined') ) { e = eId; eId = e.id; } else { eId = ''; } } else { e = false; } if ( DEBUG ) { console.group(`${PC}ElementBoundsCorrected[eId=${eId}] by=${by}`,CG); }//Collapsed let bounds = ElementBounds(eId,'ElementBoundsCorrected~242'); let schedulecontainerBounds = ElementBounds('schedulecontainer','schedule.js 846'); bounds.top += schedulecontainerBounds.top; bounds.left += schedulecontainerBounds.left; return bounds; } // END ElementBoundsCorrected. /**/ // formSubmit(e, formTask, formAction) // Submits the form and additionally creates or sets hidden element values or the form action. // Any "button" or "submit" element that calls this function will be disabled to help stop multiple form submissions. // A button or disabled submit does not send its value when the form is submitted. This function fixes that problem. // e = The element calling formSubmit, (this). Required. // formTask = The new value of the element. Optional. // formAction = The new form action. If formAction is undefined the form action is unchanged. Optional. // // If the e element has a name then e.name is used for the name of the hidden element. // If the e element does not have a name then 'task' is used for the name of the hidden element. // If the e element does not exist or is disabled then a hidden element with that name is created. // The value of the named element is either the e element value or formTask. // The e element already exists then only the value is set. // Additionally, you can even create many name/value pairs. See examples below. // formTask = The e value or an array of name/value pairs. // If typeof(formTask) == undefined = Create a hidden element with the name and value of the e element. // If the e element has no name then the name of the hidden element is 'task'. // If the e element has no value then the value of the hidden element is an empty string. // If typeof(formTask) == string = Create a hidden element with the name of the e element and the value of formTask. // If the e element has no name then the name of the hidden element is 'task'. // If typeof(formTask) == array = Create hidden elements for each associative array pair. The array index is the element name and the value is the element value. // If e has a name and the array does not contain e.name then a hidden element with the name e.name and the value of e.value is also created. // formAction = The new form action. If formAction is undefined the form action is unchanged. // // 1) i.e. Call w/o formTask or formTask is an empty string. // 1.a) element has a name. // <input type="button" name="myName" value="ClickMe" onClick="formSubmit(this);"> or // <input type="submit" name="myName" value="ClickMe" onClick="formSubmit(this);"> or // <input type="button" name="myName" value="ClickMe" onClick="formSubmit(this,'','/new_form_action/');"> or // <input type="submit" name="myName" value="ClickMe" onClick="formSubmit(this,'','/new_form_action/');"> // Will disable the element and create a hidden element with the name "myName" and the value "ClickMe", then submit the form. // 1.b) element has no name. // <input type="button" value="ClickMe" onClick="formSubmit(this);"> or // <input type="submit" value="ClickMe" onClick="formSubmit(this);"> or // <input type="button" value="ClickMe" onClick="formSubmit(this,'','/new_form_action/');"> or // <input type="submit" value="ClickMe" onClick="formSubmit(this,'','/new_form_action/');"> // Will disable the element and create a hidden element with the name "task" and the value "ClickMe", then submit the form. // // 2) i.e. Call with formTask value. // formSubmit(this,'County select') or formSubmit(this,'County select','/new_form_action/') // <input type="radio" name="county" value="McLeod" onChange="formSubmit(this,'County select');">McLeod // Will create a hidden element with the name "task" and the value "County select" then submit the form. // // 3) i.e. Call with formTask as an array of name/value pairs. // formSubmit(this,{'name1':'value1','name2':'value2'}) or formSubmit(this,{'name1':'value1','name2':'value2'},'/new_form_action/') // <input type="submit" name="task" value="ClickMe" onClick="formSubmit(this,{'name1':'value1','name2':'value2'});"> // Will disable submit element and create 3 hidden elements with the names "name1", "name2", and "task" with the values "value1", "value2", and "ClickMe" then submit the form. function formSubmit(e, formTask, formAction, DEBUG_formSubmit) { console.dir(e); var DEBUG_formSubmit = false; // false = No console debug, true = turn on console debug. if ( typeof DEBUG_formSubmit === 'undefined' ) { DEBUG_formSubmit = false; } var defaultName = 'task'; // Set default form element name. if ( DEBUG_formSubmit ) { console.info('Begin formSubmit()'); } var eForm; if ( e && e.type ) { // Get the e form. eForm = getForm(e); if ( typeof eForm === 'undefined' ) { // The page has no form so create one. if ( DEBUG_formSubmit ) { console.info('The page has no form'); } // Create a form. eForm = document.createElement('form'); eForm.name = 'form_created'; eForm.method = 'POST'; eForm.action = document.URL; document.body.appendChild(eForm); if ( DEBUG_formSubmit ) { console.log('form '+eForm.name+' created'); } /** / // Add form element to the form. var el = document.createElement("input"); // Create the input element. el.type = "hidden"; // Set element type to hidden. el.name = 'form'; // Set element name to form. el.value = 'form_created'; // Set element value to 'form_created'. eForm.appendChild(el); // Add the element to the form. if ( DEBUG_formSubmit ) console.log('Create element type="'+el.type+'" name="'+el.name+'" value="'+el.value+'"'); // Add form element to the form. var el = document.createElement("input"); // Create the input element. el.type = "hidden"; // Set element type to hidden. el.name = 'form'; // Set element name to form. el.value = uuid(); // Set element value to uuid(). eForm.appendChild(el); // Add the element to the form. if ( DEBUG_formSubmit ) console.log('Create element type="'+el.type+'" name="'+el.name+'" value="'+el.value+'"'); /**/ // eForm.submit(); // Test eForm.submit(); } if ( DEBUG_formSubmit ) { console.log('eForm.name = '+eForm.name); } // Set the form action. if ( typeof formAction !== 'undefined' ) { eForm.action = formAction; // If formAction then change the form action. if ( DEBUG_formSubmit ) { console.log('eForm.action set to "'+eForm.action+'"'); } } else { if ( DEBUG_formSubmit ) { console.log('eForm.action unchanged "'+eForm.action+'"'); } } // Get the e name. let eName; if ( e.name ) { eName = e.name; } else { eName = defaultName; console.log('e.name is undefined so use defaultName "'+defaultName+'"'); } // Get the e value. let eValue; if ( e.value ) { eValue = e.value; } else { eValue = undefined; } // If e.type is button or submit disable it. if ( e.type === 'button' || e.type === 'submit' ) { if ( !DEBUG_formSubmit ) { e.disabled = true; } else { if ( eValue ) { console.log('DEBUG_formSubmit == true, '+eValue+' '+e.type+' not disabled'); } else { if ( e.name ) { console.log('DEBUG_formSubmit == true, '+e.name+' '+e.type+' not disabled'); } else { console.log('DEBUG_formSubmit == true, '+'unnamed '+e.type+' not disabled'); } } } } if ( DEBUG_formSubmit ) { console.log('eName = '+eName); console.log('eValue = '+eValue); console.log('typeof(formTask) = '+typeof(formTask)); } var el; let eFound; switch ( typeof(formTask) ) { case 'object': // formTask is an object so create elements for each array item. if ( DEBUG_formSubmit ) { console.info('formTask is an object so create elements for each array item.'); } eFound = false; // Setup for addition of hidden element. for( var index in formTask ) {if (formTask.hasOwnProperty(index)) { el = document.createElement("input"); // Create the input element. el.type = "hidden"; // Set element type to hidden. el.name = index; // Set element name to formTask index. if ( e.name && e.name === el.name ) { eFound = true; } el.value = formTask[index]; // Set element value to formTask[index] value. if ( DEBUG_formSubmit ) { console.log('Create element type="'+el.type+'" name="'+el.name+'" value="'+el.value+'"'); } eForm.appendChild(el); // Add the element to the form. }} if ( e.name && e.value && !eFound && ( e.type === 'button' || e.type === 'submit' || e.type === 'click' ) ) { // The button name was not in the array, add hidden element for button. if ( DEBUG_formSubmit ) { console.log(e.name+' was not in the array, add hidden element'); } el = document.createElement("input"); // Create the input element. el.type = "hidden"; // Set element type to hidden. el.name = e.name; // Set element name to e.name. el.value = e.value; // Set element value to e.value. if ( DEBUG_formSubmit ) { console.log('Create element type="'+el.type+'" name="'+el.name+'" value="'+el.value+'"'); } eForm.appendChild(el); // Add the element to the form. } break; case 'string': case 'undefined': if ( typeof formTask === 'string' ) { if ( formTask === '' ) { formTask = eValue; if ( DEBUG_formSubmit ) { console.log('formTask is an empty string so use eValue "'+eValue+'"'); } } else { if ( DEBUG_formSubmit ) { console.log('formTask is a string so use formTask value \''+formTask+'\'.'); } } } if ( typeof formTask === 'undefined' ) { formTask = eValue; if ( DEBUG_formSubmit ) { console.log('formTask is undefined so use eValue "'+eValue+'"'); } } if ( typeof formTask !== 'undefined' ) { // formTask is a string so create task with formTask value. if ( formTask === '' && eValue ) { formTask = eValue; } el = document.createElement("input"); // Create the input element. el.type = "hidden"; // Set element type to hidden. el.name = eName; // Set element name. el.value = formTask; // Set element value to formTask value. if ( DEBUG_formSubmit ) { console.log('Create element type="'+el.type+'" name="'+el.name+'" value="'+el.value+'"'); } eForm.appendChild(el); // Add the element to the form. } else { if ( DEBUG_formSubmit ) { console.log('formTask is undefined and the form will not be submitted'); } eForm = undefined; } break; default: console.error('formSubmit() is not programmed for typeof(formTask) = '+typeof(formTask)); eForm = undefined; break; } } else { // e or e.type is undefined. if ( DEBUG_formSubmit ) { if ( e ) { console.log('e.type is undefined'); } else { console.log('e is undefined'); } } } if ( DEBUG_formSubmit ) { console.info('End formSubmit()'); } if ( typeof eForm !== 'undefined' ) { if ( DEBUG_formSubmit ) { var fSubmit = confirm('Execute '+eForm.name+'.submit();'); if ( fSubmit === true) { eForm.submit(); } else { console.info(eForm.name+'.submit() aborted'); } } else { eForm.submit(); } } return false; } // END formSubmit. // getForm(e) // Returns the form element. // e = Form element to get the form from. // If e is not a form element return the last form. // If there is no form on the page return undefined. function getForm(e) { var DEBUG_getForm = false; var eForm; if ( DEBUG_getForm ) { console.info('Begin getForm()'); } if ( e.form && e.form.name ) { if ( DEBUG_getForm ) { console.log('getForm(e) returning e form "'+e.form.name+'"'); } eForm = document.forms[e.form.name]; } else { if ( DEBUG_getForm ) { console.log('document.forms.length = '+document.forms.length); } if ( document.forms.length ) { eForm = document.forms[document.forms.length-1]; if ( DEBUG_getForm ) { if ( e.form ) { console.log('getForm(e) e element does not have a form name; returning last form on page "'+eForm.name+'"'); } else { console.log('getForm(e) e element does not have a form; returning last form on page "'+eForm.name+'"'); } } } else { if ( DEBUG_getForm ) { console.log('getForm(e) e element does not have a form name and the page has no forms; returning "undefined"'); } eForm = undefined; } //eForm = eForm; } if ( DEBUG_getForm ) { console.info('End getForm()'); } return eForm; } // END getForm. // ScrollLeftTop() // Returns the scroll position { left:left, top:top }. function ScrollLeftTop() { var doc = document.documentElement; var left = parseInt((window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0)); var top = parseInt((window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0)); return { left:left, top:top }; } // END ScrollLeftTop. // PositionSidenav() // Reposition the side nav. function PositionSidenav() { var DEBUG = false; if ( DEBUG ) { console.warn('PositionSidenav[]'); } var headerHeight = 0; // Get header height. var eHeader = document.getElementsByTagName('header'); if ( eHeader.length > 0) { headerHeight += eHeader[0].offsetHeight; if ( DEBUG ) { console.log('header headerHeight='+headerHeight); } } // Get header position. var headerBounds = ElementBounds('headerPage','site.js 458'); if ( DEBUG ) { console.log('headerBounds left='+headerBounds.left+' top='+headerBounds.top+' right='+headerBounds.right+' bottom='+headerBounds.bottom+' width='+headerBounds.width+' height='+headerBounds.height); } headerHeight += headerBounds.top; if ( DEBUG ) { console.log('headerBounds headerHeight='+headerHeight); } // Get scroll position. var scrollTop = (window.pageYOffset !== 'undefined') ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop; if ( DEBUG ) { console.log('scrollTop='+scrollTop); } let sidenavTop; if ( scrollTop > headerHeight ) { sidenavTop = scrollTop; } else { sidenavTop = headerHeight; } sidenavTop = parseInt(sidenavTop); if ( DEBUG ) { console.log('sidenavTop='+sidenavTop); } document.getElementById('navSidenav').style.top = sidenavTop+'px'; } // END PositionSidenav. // TextareaResizeAll(maxWidth) // Resizes all textareas on the page // maxWidth = The maximum textarea width. // minWidth // minHeight function TextareaResizeAll(maxWidth, minWidth, minHeight) { console.log(`${PC}TextareaResizeAll[maxWidth=${maxWidth}, minWidth=${minWidth}, minHeight=${minHeight}]`,CG); if ( minWidth == undefined ) minWidth = 20; // The textarea's minimum width. if ( minHeight == undefined ) minHeight = 2; // The textarea's minimum height. var textareas = document.getElementsByTagName("textarea"); // Get an array of textareas. console.log('textareas.length = '+textareas.length); for ( let i=0; i<textareas.length; i++ ) { // Loop through the textareas. TextareaResizeById(textareas[i],maxWidth,minWidth,minHeight); // Resize this textarea. } } // END TextareaResizeAll. // TextareaResizeById(eId, maxWidth, minWidth, minHeight) // Called by TextareaResizeAll() to resize this textarea. function TextareaResizeById(eId, maxWidth, minWidth, minHeight) { console.log(`${PC}TextareaResizeById[eId=${eId.name}, maxWidth=${maxWidth}, minWidth=${minWidth}, minHeight=${minHeight}]`, CG); if ( minWidth == undefined ) minWidth = 20; // The textarea's minimum width. if ( minHeight == undefined ) minHeight = 2; // The textarea's minimum height. var width = 0; // Used to calculate the textarea's current width. var height = -1; // Used to calculate the textarea's current height. let lines = eId.value.split('\n'); // Get an array of the textarea's lines. //alert('name='+eId.name+' value='+eId.value); for (var i = 0; i < lines.length; i++) { // Loop through each line. var linelength = lines[i].length; // Get the line length. if ( linelength > width ) width = linelength; // Increase width if needed. height++; // Increment height. } height += 2; console.log('width = '+width+', height = '+height); if ( width > maxWidth ) { width = maxWidth; height++; console.log('width = '+width+', height = '+height); } // If width too large reset it and increment height. if ( width < minWidth ) { width = minWidth; console.log('width = '+width); } // If width too small set to minWidth. if ( height < minHeight ) { height = minHeight; console.log('height = '+height); } // If height too small set to minHeight. if ( width > 0 ) { eId.cols = parseInt(width); console.log('eId.cols = '+eId.cols); } // Set the textarea's width. if ( height > 0 ) { eId.rows = parseInt(height); console.log('eId.rows = '+eId.rows); } // Set the textarea's height. } // END TextareaResizeById. // TextareaResizeOnKeyUp(e) // Resize the textarea to fit its content. function TextareaResizeOnKeyUp(e) { console.log(`${PC}textareaResize[e.id=${e.id}]`,CG); e.style.height = 'auto'; e.style.height = e.scrollHeight+'px'; var eh = Math.max(50,parseInt(e.style.height)); if ( eh > 50 ) e.style.height = eh+10+'px'; } // END TextareaResizeOnKeyUp. // today(textFieldId) // Put today's date in text field. // textFieldId = The id of the text field. function today(textFieldId) { var eId = document.getElementById(textFieldId); var currentTime = new Date(); if ( eId ) { var mm = currentTime.getMonth()+1; mm = (mm < 10) ? '0' + mm : mm; eId.value = mm + '/' + currentTime.getDate() + '/' + currentTime.getFullYear(); } } // END today. // uuid() // Generate a uuid for form control (used to prevent reload problems). function uuid() { var uuidValue = (1+Math.random()).toString(16).substring(2,14)+(1+Math.random()).toString(16).substring(2,12)+(1+Math.random()).toString(16).substring(2,12); //console.log('uuidValue = '+uuidValue+' uuidValue.length = '+uuidValue.length); return uuidValue; } // END uuid.