MSU English Department Film series, ICS file

The English Department at Michigan State University is promoting a film series over the next few months that looks interesting. It is called Cinema under Siege: Imperiled Visions from Beirut to Baghdad. The screenings will be held on campus in C20 Snyder-Phillips Hall and are free and open to the public.

Here’s a PDF of Cinema under Siege program from the MSU English Dept. website.

And here is the ICS calendar download, for anyone interested: ENGDeptFilmSeries.ics You can download this and double-click the file icon to load it into many modern calendar programs, like Outlook 2007, Apple iCal, Mozilla’s calendar, and you can also import it into Google Calendar. Feel free.

Using Javascript to add instructive text for input and textarea form fields

UPDATE 2008-04-13: This code has been refactored. Please view the updated posting.

Over the last year or so, I’ve worked on a number of websites where I wanted to add instructive text to form fields, but didn’t want that text to get in the way when a person actually tries to fill out the form. So, behavior-wise, the page would load with instructive (or suggested) text in the fields. It should have a class attribute that can be used to style it so it doesn’t look like a real value (grey and italic, for instance). When someone clicks on the field, the instructive text should go away and the class should go away so the default styling kicks in. When someone clicks off, the suggested text and class should pop back in, so long as the field is empty. The instructive text should come from the title attribute on the field (that made the most sense to me, given all the options).

So, here are a couple Javascript functions to do so.


function setSuggestedFormText(mode, field) {
/*
mode values must be one of: set, clear, or reset
set is to check the value on page load
clear is to clear the default value when someone clicks on the field
reset is to fill in the default value when someone clicks off the field
field is the value of the ID attribute of the input or textarea element
Use .blurred and .sharpened selectors in your CSS file
*/
var key = document.getElementById(field);
var defaultText = key.title;
switch(mode) {
case 'set':
if(key.value == '') {
key.value = defaultText;
key.setAttribute('class', 'blurred');
}
break;

case 'clear':
if(key.value == defaultText) {
key.value = '';
key.setAttribute('class', 'sharpened');
}
break;

case 'reset':
if(key.value == '') {
key.value = defaultText;
key.setAttribute('class', 'blurred');
}
break;

default:
break;
}

}
function setUpSuggestedFormText(field){
setSuggestedFormText('set', field);
var node = document.getElementById(field);
node.onblur = function(){
setSuggestedFormText('reset', field);
}
node.onfocus = function(){
setSuggestedFormText('clear', field);
}
}

To use these functions, add them to your site’s Javascript library, and then call the following functions when the document is loaded. Google for adddomloadevent or you could probably use jQuery’s document.ready function.

Ok, usage. Let’s say you have an input field for an email address, like so:


<input type="text" name="email"
id="email" title="Your e-mail address" />

You would add the following javascript code to trigger the functions.


// Once the DOM is loaded, call this function
setUpSuggestedFormText('email');

Feel free to use it. If you make an improvement, please let me know.

To see it in use, try the search form on this page. For now, the Javascript source is at http://davingranroth.com/blog/custom.js

Nephtali

Oh! Nephtali!

Alright, so if you look up “Nephtali” on thinkbabynames.com, you see it listed as a variant of “Naftali.”

The boy’s name Naftali \n(a)-fta-li, naf-tali\ is of Hebrew origin, and its meaning is “struggling”. Biblical: a son of Jacob and one of the ancestors of the 12 tribes of Israel.

“Struggling.” Apt.

How many phone calls from Adam have I received in the last year that began, “With Nephtali, if you were to do [blah blah blah], which of these approaches would you like the best?”

Countless. Every other day is a conservative estimate, considering that many days, there were many phone calls.

The man has been obsessively working on this “Nephtali.” Yesterday, in our ritual Nephtali conversation, he said, “So old man, it’s time to post this to your blog.”

After so many versions and so much work on Adam’s part, it’s time to break the silence.

What is Nephtali?

Well, I’ll give you my take on it, but for the practical details (and a download), go to nephtaliproject.com.

Nephtali is a framework for the development of data-driven websites. It uses PHP 5 and is object-oriented. It’s flexible, extensible, and plays nicely with other frameworks, like the Pear and Zend frameworks. Because of how it handles data, developers will tend to write more secure Web apps. It separates the presentation from the programming logic well, so that it is easy to use a tool such as Dreamweaver without worrying about messing up the behind-the-scenes programming. And, the API was written with a continual drive to make it user-friendly for programmers, while maintaining a value on security.

My experience with Nephtali, thus far

I’ve played with a couple iterations of Nephtali, and once getting oriented, I found I like it. (Granted, I’m biased having had so many discussions with Adam about it.)

Compared to CakePHP, Nephtali is easier to use. For instance, in CakePHP, or other Model-View-Controller frameworks (e.g., Ruby on Rails), database models are abstracted and then calls in the app rely on those abstractions. While there is a great benefit to this, I’ve found the abstractions themselves to be problematic. Nephtali can provide abstraction to fairly simple database actions (standard CRUD operations), but, gosh darn it, I like being able to jump in and write SQL. The reality for me as a developer is that database model abstraction causes me more grief than they are worth. Abstraction can slow me down, especially when the queries and relationships get tricky. Now, one of the big benefits to abstraction is that it can promote the DRY principle. Nephtali provides well for that, through implementing sub-classes, and I still have the direct, easy line to thinking about and working with the data in SQL.

The future of Nephtali

I could go on, but the proof for Nephtali will be in how many sites it is eventually used on, and how many other developers get their heads into it.

So, developers, check out Nephtali. And if you have questions or suggestions, do not hesitate to dialogue with Adam about it. And tell him to post a screen-cast of building a basic app with Nephtali.

For now, I’m going to see if I can get Adam to smash a bottle of champagne over his development box in honor of this release. Congrats, Adam!