jQuery Version Check: live() Vs. On()

January 31st, 2012

Recently I started work on my own jQuery plugins.  I do love that jQuery.  But, as I was working, I came to see the difference between on() and live().

I’m reading that live() is depreciated, so in order to make my plugin a bit more universal, I wrote a function to detect the jQuery version being used, and act accordingly.  Here it is:

function useOn(){
		var jRequired = '1.7.1'.split('.');
		var jInstalled = jQuery.fn.jquery.split('.');
		var on = true;
		for(x in jInstalled){
			if(parseInt(jInstalled[x]) < parseInt(jRequired[x]) && on==true){
				on = false;	
			}
		}
		return on;
	}

If the jQuery version is 1.7.1 or higher, this function will return true. If lower, it will return false. I call the function when I’m getting ready to set click functions on some of my objects.

I couldn’t find anything like it will poking around Google, so hopefully someone else finds this helpful.

United States JSON state list

February 4th, 2011

In case anyone needs it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var US = {
"AL":{"count":"0","name":"Alabama","abbr":"AL"},
"AK":{"count":"1","name":"Alaska","abbr":"AK"},
"AZ":{"count":"2","name":"Arizona ","abbr":"AZ"},
"AR":{"count":"3","name":"Arkansas","abbr":"AR"},
"CA":{"count":"4","name":"California ","abbr":"CA"},
"CO":{"count":"5","name":"Colorado ","abbr":"CO"},
"CT":{"count":"6","name":"Connecticut","abbr":"CT"},
"DE":{"count":"7","name":"Delaware","abbr":"DE"},
"DC":{"count":"8","name":"District Of Columbia","abbr":"DC"},
"FL":{"count":"9","name":"Florida","abbr":"FL"},
"GA":{"count":"10","name":"Georgia","abbr":"GA"},
"HI":{"count":"11","name":"Hawaii","abbr":"HI"},
"ID":{"count":"12","name":"Idaho","abbr":"ID"},
"IL":{"count":"13","name":"Illinois","abbr":"IL"},
"IN":{"count":"14","name":"Indiana","abbr":"IN"},
"IA":{"count":"15","name":"Iowa","abbr":"IA"},
"KS":{"count":"16","name":"Kansas","abbr":"KS"},
"KY":{"count":"17","name":"Kentucky","abbr":"KY"},
"LA":{"count":"18","name":"Louisiana","abbr":"LA"},
"ME":{"count":"19","name":"Maine","abbr":"ME"},
"MD":{"count":"20","name":"Maryland","abbr":"MD"},
"MA":{"count":"21","name":"Massachusetts","abbr":"MA"},
"MI":{"count":"22","name":"Michigan","abbr":"MI"},
"MN":{"count":"23","name":"Minnesota","abbr":"MN"},
"MS":{"count":"24","name":"Mississippi","abbr":"MS"},
"MO":{"count":"25","name":"Missouri","abbr":"MO"},
"MT":{"count":"26","name":"Montana","abbr":"MT"},
"NE":{"count":"27","name":"Nebraska","abbr":"NE"},
"NV":{"count":"28","name":"Nevada","abbr":"NV"},
"NH":{"count":"29","name":"New Hampshire","abbr":"NH"},
"NJ":{"count":"30","name":"New Jersey","abbr":"NJ"},
"NM":{"count":"31","name":"New Mexico","abbr":"NM"},
"NY":{"count":"32","name":"New York","abbr":"NY"},
"NC":{"count":"33","name":"North Carolina","abbr":"NC"},
"ND":{"count":"34","name":"North Dakota","abbr":"ND"},
"OH":{"count":"35","name":"Ohio","abbr":"OH"},
"OK":{"count":"36","name":"Oklahoma","abbr":"OK"},
"OR":{"count":"37","name":"Oregon","abbr":"OR"},
"PA":{"count":"38","name":"Pennsylvania","abbr":"PA"},
"RI":{"count":"39","name":"Rhode Island","abbr":"RI"},
"SC":{"count":"40","name":"South Carolina","abbr":"SC"},
"SD":{"count":"41","name":"South Dakota","abbr":"SD"},
"TN":{"count":"42","name":"Tennessee","abbr":"TN"},
"TX":{"count":"43","name":"Texas","abbr":"TX"},
"UT":{"count":"44","name":"Utah","abbr":"UT"},
"VT":{"count":"45","name":"Vermont","abbr":"VT"},
"VA":{"count":"46","name":"Virginia ","abbr":"VA"},
"WA":{"count":"47","name":"Washington","abbr":"WA"},
"WV":{"count":"48","name":"West Virginia","abbr":"WV"},
"WI":{"count":"49","name":"Wisconsin","abbr":"WI"},
"WY":{"count":"50","name":"Wyoming","abbr":"WY"}
};

[Generated using jQuery and the US Postal Service. ;) ]

Cleinman Performance Partners has a new website

January 29th, 2011

Since my last post, which I know was some time ago, I’ve started a new position with a consulting firm in Upstate New York, near where I was born and raised.  When I left Upstate at the age of 18 for college, I knew I was going to be gone for a long time, but I also knew I was always going to come home.  Last year, the stars aligned, and I found a job very close to my hometown, where I could move home with my wife and 1 year old son, and give him the same life in the woods that I had growing up.

This was no mean feat.  Finding a position as a developer away from an urban area is tricking, but I found Cleinman Performance Partners.  An optometrist consulting company, CPP helps medical professionals of that certain bend be more successful, and in fulfilling that task they decided to invest in me to give them an edge most companies don’t have in house.  Their unique needs and drive led them to the conclusion that a mere webmaster, or web design company, wasn’t enough.

I’ve been here since September, and the challenges have been thrilling.  I have complete latitude to make all the technical determinations necessary to make this website a success, and I have been able to put out some of my finest work to date.  I hope this is a trend that continues for a long while.

Cleinman Performance Partners

Cleinman Performance Partners

The design is derived from what existed when I began working there. I cleaned up the layout, added some subtle effects, and replaced all flash elements with jQuery derived scripts. The company that designed and built the site initially… well, they did a very bad job technically. There was a Coldfusion based proprietary CMS in place to manage the site… It was broken. It was also duplicated so many times from client to client that it was a giant security hazard, whose database still contained active user credentials for dozens of other websites… The initial charge for that site was astronomical, and took 6 months to deliver a broken and insecure system.

My replacement was Open Source, took 2 weeks, and has vastly improved security.

There are many facets to the site, so many at this point to cover them all I will wait for other posts, but this has been my real jump into JavaScript as a powerful weapon in my arsenal. I’ve been getting deeper into client-side scripting over the past few years, but now I derive true joy and achieve excellent results. I have also gotten much deeper into jQuery and a little bit into MooTools. I am at the point where I can’t think of the next time I will need to use Flash again in the foreseeable future. And good riddance. (I kid… kinda.)

Better CSV Export from MicroSoft Excel for MySQL

August 25th, 2010

I had a problem getting a CSV from Excel in a format that would easily import into a MySQL database.  So I looked around, and found this macro. (I don’t recall the source, or I’d post that too…)

Sub CSVFile()
Dim SrcRg As Range
Dim CurrRow As Range
Dim CurrCell As Range
Dim CurrTextStr As String
Dim ListSep As String
Dim FName As Variant
FName = Application.GetSaveAsFilename(“”, “CSV File (*.csv), *.csv”)
If FName <> False Then
ListSep = Application.International(xlListSeparator)
If Selection.Cells.Count > 1 Then
Set SrcRg = Selection
Else
Set SrcRg = ActiveSheet.UsedRange
End If
Open FName For Output As #1
For Each CurrRow In SrcRg.Rows
CurrTextStr = “”
For Each CurrCell In CurrRow.Cells
CurrTextStr = CurrTextStr & “”"” & CurrCell.Value & “”"” & ListSep
Next
While Right(CurrTextStr, 1) = ListSep
CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) – 1)
Wend
Print #1, CurrTextStr
Next
Close #1
End If
End Sub

Sub CSVFile()

Dim SrcRg As Range

Dim CurrRow As Range

Dim CurrCell As Range

Dim CurrTextStr As String

Dim ListSep As String

Dim FName As Variant

FName = Application.GetSaveAsFilename(“”, “CSV File (*.csv), *.csv”)

If FName <> False Then

ListSep = Application.International(xlListSeparator)

If Selection.Cells.Count > 1 Then

Set SrcRg = Selection

Else

Set SrcRg = ActiveSheet.UsedRange

End If

Open FName For Output As #1

For Each CurrRow In SrcRg.Rows

CurrTextStr = “”

For Each CurrCell In CurrRow.Cells

CurrTextStr = CurrTextStr & “”"” & CurrCell.Value & “”"” & ListSep

Next

While Right(CurrTextStr, 1) = ListSep

CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) – 1)

Wend

Print #1, CurrTextStr

Next

Close #1

End If

End Sub

HTML5: So much potential

July 20th, 2010

I’ve recently been tasked with researching HTML5 for my company.  The point of this is to generate very specific search pages for mobile devices, starting with the iPhone, iPod and iPad.  So far, thanks to the compliance level of the iOS version of Safari, its been great fun.

Due to this, we now how CS5 in the office, because the new Dreamweaver has some nice improvements to make this a little easier.  As and aside, kudos to Adobe for their fine works on this version.

Fortunatly for me, using HTML5 techniques on this project is going to turn out an excellent mobile search when I’m all done.  However, unfortunatly, it will be a while before I can carry ovr some of the things I’m learning here into other areas.

HTML5 support in web browsers is currently spotty at best.  My best experience thus far testing new tags and attributes has been on Chrome, Safari and Opera.  I’m seeing among the daily user I encounter increasing usage of Chrome, but I know very few people who use Safari, and no one who uses Opera for general web surfing. (I’m not saying Opera is a bad browser by any means, just that its adoption rate is negligible in my personal observations.)

The big browsers right now are Firefox and Internet Explorer.  Firefox is planning more support in the near future, which i guess is fine, but its IE that will be the bigger problem. Versions 7 and 8 are now widely being used by general users, and this is only because of the ‘Facebook Effect’ I believe.  Popular sites like Youtube and Facebook quit IE6 support a while ago, and finally its seems to have pushed IE6 use off a cliff, with only 5% of users on that browser last time I check.

Unfortunately, IE7 and IE8 aren’t going to be going anywhere any time soon.  Additionally, Microsoft isn’t planning wider HTML5 support until IE9… the real problem here is that, from what I’m hearing, IE9 will only be available for Windows Vista and Windows 7+ users. XP users? You are out of luck.

Now, my name is Thomas, and I’m a PC.  I’m running Windows 7 64bit, and very happy with it.  But due to the very bad press surrounding the Vista release, many people have clung to XP and are unwilling to let go.  Which means a big section of the internet population will be unable to use the forthcoming version of IE that will allow the deployment of the more advance, and useful, HTML5 coding techniques.

What a shame, is all I can say.  I’m not terribly surprised however.  I’m planing, in general development, to continue to use more widely supported HTML4, with the current CSS and AJAX techniques, to get by until, oh say… 2012… 2015… maybe longer?  It took so long for IE6 to fall off the map, that I can’t expect 7 and 8 to go in any kind of reasonable time frame now.

However, on my current project, an HTML5 mobile search for the iProducts, things should go pretty well.  So long as I can avoid years and years of writing individual exceptions for user-agents, I’ll be just fine.

General Update

April 21st, 2010

As busy as I am with work and fatherhood, I have a moment today where I thought I would give an update on my recent activities.

Lately I’ve been doing more JavaScript, which has really broadened my mind.  My most recent work is this new contact page for Smarter Agent’s MLS inquiries. Using JS and PHP, I built a dynamic form to send mail without loading a new window.

Smarter Agent MLS Contact Form

Smarter Agent MLS Contact Form

JavasScript is used to validate  all of the form fields, with some form validation by PHP after the submit button is checked.  It took a good afternoon, and was lots of fun.

I’ve been using JS to build new downloaders for Smarter Agent’s Homes for Sale mobile application.  Recently I’ve been doing more downloaders for mobile devices, which require a broad set of considerations.  Given the variety of phones, and their differing capabilities, you can’t  rely on one way of doing things.  The iPhone is a very capable device to design for, but obviously Flash is out of the question.  Android is also quite nice, but seems to lack JavaScript in application browser windows (meaning a browser window opened by an Android application.  The Android browser by itself is very capable.).  Palm is excellent as well, but older model Blackberry devices and not-so-smartphones require the most basic of codes.

This week has been dedicated to more mobile oriented work than I normally do, but its been fun.  Hopefully in a few weeks time I will have every mobile solution I need.  Thats what I love about my job.  There is no end of problems to solve, and I can learn something new everyday.

Enabling PHP Error messages

January 29th, 2010

I have a server at work which has error messages turned off in the PHP INI file, which I do not have access to (kind of irritating given this is the server I have to test on daily…).  To get around this, and to find places where a PHP file is failing, I add the following lines to the top of a give script if I want to see the errors on this box:

error_reporting(E_ALL);
ini_set(“display_errors”, 1);
error_reporting(E_ALL);
ini_set("display_errors", 1);

Smarter Agent has a new website

October 22nd, 2009

This past Saturday we launched the new Smarter Agent website. Designed by Alison Hinch, with Flash by Nick ‘the best damn intern’ Mazzetti, constructed and implemented by me, it came online October 17th in all its glory. This is the second time I’ve rebuilt the site for Smarter Agent, and the first major redesign implementation. It was a good technological leap too, bringing several new functions for customers that should help us serve them better, and platform changes for further improvements in the near future.

Its built with a new CMS system, with many custom sections for unique database requirements. I’ve been doing ‘bolt tightening’ on it all week, and am excited about the new work this is going to come next.

The new Smarrter Agent site.  Click to visit.

The new Smarter Agent site. Click to visit.

Credits:
Alison Hinch
Nick ‘the best damn intern’ Mazzetti

JavaScript function for blacklisting characters in Unicode

August 18th, 2009

This is a handy little function I wrote today to help me out with a special text field. This field needs to accept number and letters only, no spaces and no other characters.  There is a var for each character I don’t want the field to accept, and there is an array that holds all those vars for the checking loop at the end.

Depending on how this field works out, I may need to restore a couple of characters, like ‘-’ and ‘_’, for which all I have to do is remove them from the array. My short hand for the characters may be a little vague, but you can find the Unicode for any character by using the Character Mapper in Windows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function noChars(e)
{
var keynum;
var keychar;
 
if(window.event) // IE
	{
	keynum = e.keyCode;
	}
else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which;
	}
keychar = String.fromCharCode(keynum);
 
var space = /\u0020/;
var hash = /\u0023/;
var exc = /\u0021/;
var at = /\u0040/;
var dollar = /\u0024/;
var perc = /\u0025/;
var amp = /\u0026/;
var lper = /\u0028/;
var rper = /\u0029/;
var ast = /\u002a/;
var apos = /\u0027/;
var lbra = /\u007b/;
var pipe = /\u007c/;
var rbra = /\u007d/;
var cir = /\u005e/;
var hm = /\u002d/;
var us = /\u005f/;
var plus = /\u002b/;
var equal = /\u003d/;
var sqrl = /\u005b/;
var sqrr = /\u005d/;
var bakslash = /\u005c/;
var forslash = /\u002f/;
var dq = /\u0022/;
var colon = /\u003a/;
var semi = /\u003b/;
var ques = /\u003f/;
var per = /\u002e/;
var com = /\u002c/;
var ltag = /\u003c/;
var rtag = /\u003e/;
var tld = /\u007e/;
var acc = /\u0060/;
 
var charChecks = new Array(space,hash,exc,at,dollar,perc,amp,lper, rper,ast,apos,lbra,pipe,rbra,cir,hm,us,plus,equal,sqrl,sqrr,bakslash, forslash,dq,colon,semi,ques,per,com,ltag,rtag,tld,acc);
 
		var i;
		for (i=0; i &lt; charChecks.length; i++) {
			if (charChecks[i].test(keychar)) {
			return !charChecks[i].test(keychar);
			}
 
	};
 
}

Use it like this:

1
<input id="fieldid" onkeypress="return noChars(event)" maxlength="30" name="fieldname" type="text" />

Knowing you made the right descision… Priceless

July 26th, 2009

Before this site came online yesterday, I used to use another site, hosted at Godaddy. The service with them was fine for a long time, up until about the beginning of this year.  At a certain point, I couldn’t load files half of the time.  I would get these random disconnects.  I’m not even sure they would qualify as timeouts, its like the line would just go dead, with no reason why from the server.  I thought it was my computer, or my ISP, but when it began to happen in the office as well as home, I knew the problem was on their end.

I wrote a letter detailing the problem, and said to the effect ‘don’t tell me its my computer, because its not just my computer, but also my work machine, and don’t tell me its my ISP, because I don’t have the same ISP at work, don’t tell me its the program, because I have tried in multiple programs, and don’t tell me its my firewall, cause again, I’ve tried from behind different firewalls.’

The letter I got back from them was along the lines of  ’please check your setting in Dreamweaver and your firewall’…

So… NEW HOST!  I’m on Host Monster now, and one day in, I’m very happy.  I can load files and not get kicked off for no reason.  This is especially important for all the PHP i write these days.  I need this stuff on a server, and don’t have time to wait.  The funny part was, when i went to load a modified index.php file to redirect my oldsite over here from godaddy (i’m not disconnecting them just yet)… it disconnected on me again!  I am feeling pretty good about this move already.

As i go, I’ll let you all know how these guys do.  I don’t recommend Godaddy shared hosting for anything.  Their dedicated servers are fine… if you can afford them.  But if you have to share a box with 10,000 other sites, its not worth it to go with them anymore.