BLOG: Mitch Wilson, Austin TX Web & Multimedia Developer – Austin, TX

3Aug/0925

New jQuery plugin: maxChar

Easily add a max character limit on any HTML input or textarea form field. Also dynamically updates status message countdown to user, eg, "10 remaining" as they type. Has several options. Message is customizable. Correctly handles user events, even paste via right click menu.

Update: version 0.3.0 is out

This post is about the 0.1.0 version. The newest version is now 0.3.0. To see the new version and keep up with future updates, see the main maxChar page.

Features for version 0.1.0 (deprecated, see Update above)

  • No JavaScript in HTML tags
  • Drop dead simple with sensible defaults or completely customizable with overrides
  • Have plural and singular forms of message
  • Easily work with multiple target fields, as many as I want
  • Properly handle user pasting text via right click menu
  • Be able to properly handle updating message

Basic example .. doesn't get any easier than this

The most common use case is to add the maxChar functionality to a textarea, eg, in a comment form. Just load jquery, load the plugin, and initialize it on the target form element while passing the character limit you want to enforce.

Instructions

  1. Add links to jQuery and the maxChar plugin in your HTML head section.



  2. In your HTML head section, initialize the plugin in your jQuery ready block.


  3. In your HTML, just make sure your input or textarea element has the id you passed to maxChar above.


    NOTE: although below the only element you create is the textarea element, the maxChar plugin dynamically creates and adds a span element after the textarea element. This dynamically created span element is the container for the updated status message, eg, "N remaining."

Advanced Examples: You want options, you got options

I added the options that made sense to me. Check 'em out.

Option: indicator

The indicator is the HTML element that displays the status message, such as "10 remaining." By default, maxChar dynamically creates a span element with an id="indicator", then adds it in the DOM after the target element, in our previous example, after the textarea.

Sometimes, though, you will want to override the default indicator HTML element and specify your own. Just pass the indicator id as a parameter and maxChar will not dynamicaly create and insert a span element; it will instead update your specified HTML element with the status message.



And in your HTML, add the custom element wherever you want it in your design.




Setting up multiple instances

Using the indicator option is usually mandatory when using maxChar with multiple form fields, since you normally want each field will need it's own indicator. (If you do not specify multiple indicators, all targeted fields with share the single indicator; this would be an interesting design but probably a little confusing.)



And in your HTML, specify your HTML input and textarea and the matching span elements for their indicators.



Options: singularMessage and pluralMessage

You can also change the indicator's status message. By default it says "N remaining" but you can change the text after the number (N) to whatever you want. You can also create singular and plural versions, eg, "2 characters remaining" and "1 character remaining."



Option: spaceBeforeMessage

In addition to changing the status message itself, you can also specify the spacing in front of the message. This option is handy if the status message should, or should not, have a space between it and the textarea or input element. The default is one space character. In the following example I remove any space by setting to an empty string.



Option: rate

The interval at which maxChar runs is configurable. The default is 200 milliseconds. Sometimes you might want to tweak this rate for your own reasons. I found myself setting to different values to get the exact rate I felt was user-friendly. Since you might have your own preference, I made it an option.



25Jul/090

Dog licks glass



IMG_1266, originally uploaded by Mitch Wilson.

We had two stray dogs show up in our backyard (a months ago). I found this pic on flickr again and had to post here.

2Jul/091

undefined method `install_gem_spec_stubs’

If you know what the title of this post means, I'm sorry you are having trouble running rake in your rails project. If you have no idea what I'm saying, consider yourself lucky and move on.

Not a big deal, in the end, but just another pain in the butt that needs fixing. While updating my project from rails 2.0 to 2.3.2 I was greeted, right on cue, with exactly what I expected: an error. Rails is great but it can be love-hate sometimes.

Turns out that when running rake rails:update, to update to rails version 2.3.2, the new boot.rb file is not copied into your project's config directory.

To fix, simple copy  vendor/rails/railties/environments/boot.rb to config/boot.rb, overwriting your existing config file.

I also found that I was completely missing the initializers directory in my project's config directory. So I got those files as well by creating a new rails project and copying the whole config/initializers directory into my config directory.

14Jun/090

Nick’s first birthday party

Nick turns one year old on June 16th. The kids had a great time in the backyard water park we setup. What a great time with some great people.

Nick loves the backyard and we spent a lot of time outside today. What else does Nick love? Water! So we setup the kiddie pool with a slide, and this other ring-shaped sprinkler, and of course the garden house. All the kids had a blast while the adults drank beer and had cake. Then we finished off the party with a pinata. Why? Why not?

See all the photos on flickr.

16May/090

List of states as PHP array

Here are two PHP arrays: states and states_short. Use either of these to populate a select element drop down list used to select the state in an HTML form.

Copy, paste and enjoy!


$states_short = array(
'AL'=>'AL',
'AK'=>'AK',
'AZ'=>'AZ',
'AR'=>'AR',
'CA'=>'CA',
'CO'=>'CO',
'CT'=>'CT',
'DE'=>'DE',
'DC'=>'DC',
'FL'=>'FL',
'GA'=>'GA',
'HI'=>'HI',
'ID'=>'ID',
'IL'=>'IL',
'IN'=>'IN',
'IA'=>'IA',
'KS'=>'KS',
'KY'=>'KY',
'LA'=>'LA',
'ME'=>'ME',
'MD'=>'MD',
'MA'=>'MA',
'MI'=>'MI',
'MN'=>'MN',
'MS'=>'MS',
'MO'=>'MO',
'MT'=>'MT',
'NE'=>'NE',
'NV'=>'NV',
'NH'=>'NH',
'NJ'=>'NJ',
'NM'=>'NM',
'NY'=>'NY',
'NC'=>'NC',
'ND'=>'ND',
'OH'=>'OH',
'OK'=>'OK',
'OR'=>'OR',
'PA'=>'PA',
'RI'=>'RI',
'SC'=>'SC',
'SD'=>'SD',
'TN'=>'TN',
'TX'=>'TX',
'UT'=>'UT',
'VT'=>'VT',
'VA'=>'VA',
'WA'=>'WA',
'WV'=>'WV',
'WI'=>'WI',
'WY'=>'WY'
);


$states = array(
'AL'=>'Alabama',
'AK'=>'Alaska',
'AZ'=>'Arizona',
'AR'=>'Arkansas',
'CA'=>'California',
'CO'=>'Colorado',
'CT'=>'Connecticut',
'DE'=>'Delaware',
'DC'=>'District Of Columbia',
'FL'=>'Florida',
'GA'=>'Georgia',
'HI'=>'Hawaii',
'ID'=>'Idaho',
'IL'=>'Illinois',
'IN'=>'Indiana',
'IA'=>'Iowa',
'KS'=>'Kansas',
'KY'=>'Kentucky',
'LA'=>'Louisiana',
'ME'=>'Maine',
'MD'=>'Maryland',
'MA'=>'Massachusetts',
'MI'=>'Michigan',
'MN'=>'Minnesota',
'MS'=>'Mississippi',
'MO'=>'Missouri',
'MT'=>'Montana',
'NE'=>'Nebraska',
'NV'=>'Nevada',
'NH'=>'New Hampshire',
'NJ'=>'New Jersey',
'NM'=>'New Mexico',
'NY'=>'New York',
'NC'=>'North Carolina',
'ND'=>'North Dakota',
'OH'=>'Ohio',
'OK'=>'Oklahoma',
'OR'=>'Oregon',
'PA'=>'Pennsylvania',
'RI'=>'Rhode Island',
'SC'=>'South Carolina',
'SD'=>'South Dakota',
'TN'=>'Tennessee',
'TX'=>'Texas',
'UT'=>'Utah',
'VT'=>'Vermont',
'VA'=>'Virginia',
'WA'=>'Washington',
'WV'=>'West Virginia',
'WI'=>'Wisconsin',
'WY'=>'Wyoming'
);

Filed under: Geek Out No Comments
13May/090

Let’s dance – David Bowie

Let's dance put on your red shoes and dance the blues

Let's dance to the song
they're playin' on the radio

Let's sway
while color lights up your face
Let's sway
sway through the crowd to an empty space

If you say run, I'll run with you
If you say hide, we'll hide
Because my love for you
Would break my heart in two
If you should fall
Into my arms
And tremble like a flower

Let's dance for fear
your grace should fall
Let's dance for fear tonight is all

Let's sway you could look into my eyes
Let's sway under the moonlight,
this serious moonlight

If you say run, I'll run with you
If you say hide, we'll hide
Because my love for you
Would break my heart in two
If you should fall
Into my arms
And tremble like a flower

Let's dance put on your red shoes
and dance the blues

Let's dance to the song
they're playin' on the radio

Let's sway you could look into my eyes
Let's sway under the moonlight,
this serious moonlight

[youtube:http://www.youtube.com/watch?v=30AVhf-ZLwM&feature=related]


How to Play Bass Lines to Let's Dance
Filed under: Songs No Comments
12May/090

You’ve never gone this far before

I can almost hear the stillness
As it yields to the sound of your heart beating bum bum bum
And I can almost hear the echo
Of the thoughts that I know you must be thinking bum bum bum
And I can feel your body tremble
As you wonder what this moment holds in store bum bum bum
And as I put my arms around you
I can tell you've never been this far before bum bum bum

I don't know what I'm saying
As my trembling fingers touch forbidden places bum bum bum
I only know I've waited
For so long for the chance that we are taking bum bum bum
I don't know and I don't care
What made you tell him you don't love him anymore bum bum bum
And as I taste your tender kisses
I can tell you've never been this far before bum bum bum

And as I take the love you're giving
I can feel the tension building in your mind uh huh huh
And you're wondering if tomorrow
I'll still love you like I'm loving you tonight uh huh huh
You have no way of knowing but tonight will only make me love you more
And I hope that you'll believe me
Cause I know you've never been this far before bum bum bum bum bum

[youtube:http://www.youtube.com/watch?v=9V1fX-FvKW8]

Filed under: Songs No Comments
10May/090

You all everybody – Drive Shaft

You all, everybody
You all, everybody
Acting like you're stupid people
Wearing expensive clothes
You all everybody
You all, everybody

[youtube:http://www.youtube.com/watch?v=kuQba4inleQ]

Filed under: Songs No Comments
10May/090

Billie Jean – Michael Jackson

Chords and lyrics

Example video

[youtube:http://www.youtube.com/watch?v=aSALDAQfsSA&feature=related]

Filed under: Songs No Comments
7May/090

Crying – Roy Orbison

This video was embedded using the YouTuber plugin by Roy Tanck. Adobe Flash Player is required to view the video.

D I was all right D For a while
D I could smile D For a while

D But I saw you last night D You held my hand so tight as you
G Stopped to say Gm "Hello" oh you
D Wished me well, you A7 You couldn't tell
A7 That I'd been

D Crying F#m over you
D Crying F#m over you

G When you, so A "So long"
G Left me standing A All alone, alone and

D Crying D Crying
G Crying Gm Crying

D It's hard to understand A7 But the touch of your hand
D Can start me crying

D I thought that I D Was over you
D But it's true, so true

D I love you even more than I did before
G But, darling Gm What can I do?
D For you don't love me
A7 And I'll always be
D Crying F#m over you
D Crying F#m over you

G Yes, now A you're gone and
G From this moment A on
D I'll be crying, D crying
G Crying, Gm crying, yeah
D Crying, Bm crying
G A7Over D you

D A7 D G D

Filed under: Songs No Comments