Wednesday, December 17, 2008

Developer tools

I have some development tools I've used day-to-day, you might like them too...

Quickly find and replace stuff (commas to line breaks, regular expressions, etc)
http://www.parkapps.com/tools/find_replace.cfm

Other tools can be found at http://www.parkapps.com/tools/

Friday, December 5, 2008

Minify Javascript

We're having some problems with JavaScript not loading entirely for some users... I'm not sure why yet, but I came across this JSMin - JavaScript minifier. Excellent stuff.

http://fmarcia.info/jsmin/test.html

Tuesday, September 23, 2008

Vertical multi-column list

function ge(obj) {
	return document.getElementById(obj);
}
/*
Reorder a list that normally flows horizontally and refactor to flow vertically in the same area. 
Assumes that the li element has a css width and uses the shortcut function ge()
*/
function vertMultiColList(parentObj) {
	var nextColHtml = '
    '; // no quotes b/c IE is weird about rewriting HTML // if this has already run take out any continued lists parentObj.innerHTML = parentObj.innerHTML.replace(/<\/ul>
      /ig,''); // Firefox parentObj.innerHTML = parentObj.innerHTML.replace(/<\/ul>
        /ig,''); // IE var arrUl = document.getElementsByTagName('UL'); for(var j=0;j= 0) { //arrUl[j].style.border='1px solid red'; var arrLi = arrUl[j].getElementsByTagName('LI'); var lenArrLi = arrLi.length; if(lenArrLi==0) { break; } // get outer width of container var padOffset = -30; var container_width = parentObj.clientWidth+padOffset; // gives a little padding if(container_width==padOffset) { //IE6 problem container_width = document.body.clientWidth+padOffset; } // get width of list item var item_width = arrLi[0].clientWidth; if(item_width==0) item_width = arrLi[0].style.width; // calculate the number of columns that can fit in the space var cols = Math.floor(container_width/item_width); // divide the number of list items by the number of columns to // find out how many items should be in a column var li_per_col = Math.ceil(lenArrLi/cols); for(var i=0;i'; } if(i>1000) { cLog('over 1000 LI'); return; break; } } parentObj.innerHTML = parentObj.innerHTML.replace(/<\/li>/ig,nextColHtml); cLog('parentObj.id: ' + parentObj.id); cLog('container_width: ' + container_width); cLog('item_width: ' + item_width); cLog('lenArrLi: ' + lenArrLi); cLog('cols: ' + cols); cLog('li_per_col: ' + li_per_col); //cLog('parentObj.innerHTML: ' + parentObj.innerHTML); } if(j>100) { cLog('over 100 UL'); return; break; } } //window.onresize = vertMultiColList; // IE can't handle this and spikes memory //parentObj.ondblclick = function() { alert(this.innerHTML); } //parentObj.onmouseover = vertMultiColList; } function cLog(s) { //alert(s); if(document.all) { return; } else { //console.log(s); return; } }

Wednesday, August 20, 2008

Auto format a date onblur to mm/dd/yyyy


/*
reformats dates entered as m/d/yyyy to mm/dd/yyyy
*/
function reformatDate(inp) {
var d = inp.value;
if(d.length==0) {
return;
}
d = d.replace(/\/\//gi,'/'); // replace double slashes
var parsedDate = new Date(d);
var month = (parsedDate.getMonth() + 1).toString();
var date = parsedDate.getDate().toString(); //date is the day of the month
var year = parsedDate.getFullYear().toString();
if(month.length == 1)
month = '0' + month;
if(date.length == 1)
date = '0' + date.toString();
parsedDate = month + '/' + date + '/' + year;
inp.value = parsedDate;
}

Wednesday, July 23, 2008

focusing in on a field that's empty with javascript

There seems to be a weirdness when leaving a field that's empty and trying to get the browser to focus back on it. It does it momentarily, but then decides to go back. This script will force the cursor back and focus on the offending field after .1 seconds of leaving it.


<script>
var myInput = '';
function checkMe(obj) {
if(obj.value == '') {
myInput = obj;
myInput.style.background = 'yellow';
myInput.setAttribute('title','This is a required field and blah blah blah');
window.setTimeout('myInput.focus()',100);
}
}
</script>
<input id="foo1" name="foo1" value="init" onchange="checkMe(this);">

<input id="foo2" name="foo2" value="check" onchange="checkMe(this);">

<input id="foo3" name="foo3" value="last" onchange="checkMe(this);">

Friday, July 11, 2008

MS-DOS stuff, tips, notes, etc

Ok, this is really old school to be working in DOS, but just in case I ever need it again...
@echo off 

: PARAMETER PASSING EXERCISES
: TO RUN:
: pass_param.bat "C:\Temp\dos_test.bat"

:http://windowsitpro.com/article/articleid/13443/how-do-i-pass-parameters-to-a-batch-file.html
:When you call a batch file, you can enter data after the command that the batch file 
:refers to as %1, %2, etc. For example, in the batch file hello.bat, the following command

:clear the screen
cls

:http://talk.bmc.com/blogs/blog-gentle/anne-gentle/dos-timestamp-tips/view?searchterm=batch
:create variable to hold yyyymmdd info by using substring function
set yyyymmdd=%date:~10,4%%date:~4,2%%date:~7,2%

:clear current log and start with the following line (single >)
echo %date% %time% Starting script > %log%

:set the file log with the same name as this bat file
set log=%~n0.%yyyymmdd%.log
echo %date% %time% CREATED LOG FILE: %~n0.%yyyymmdd%.log >> %log%

echo.
echo %date% %time% CURRENT FILE RUNNING: %~nx0
echo %date% %time% CURRENT FILE RUNNING: %~nx0 >> %log%
echo.

:All the parameters in action
@echo off
echo %date% %time% passed in parameter %1
echo %date% %time% fully qualified name %~f1
echo %date% %time% drive %~d1
echo %date% %time% path %~p1
echo %date% %time% filename %~n1
echo %date% %time% file extension %~x1
echo %date% %time% short filename %~sn1
echo %date% %time% short file extension %~sx1
echo %date% %time% drive and directory %~dp1
echo %date% %time% filename and extension %~nx1


REM Prompt the user for something...
set /P myvar=Would you like to add something? 

echo.
echo Thanks!
echo.
echo You entered %myvar% 
echo.
echo %date% %time% %myvar% >> %log%