Eloquent Javascript

Written By: Editor - Feb• 23•11

Eloquent JavascriptBefore anyone complains that this is not jQuery (no, I’m sure you wouldn’t do that), let me say that jQuery is Javascript and that you need to write great code everywhere, all of the time if you expect to be of the highest value you can be to your boss, your clients, and to yourself. Am I right? Well, this free, online, interactive book will help you move from a newbie to a decent coder, or from an okay coder to a much better one… but only if you will read it and follow along running the code. Interactive is cool. There are buttons to click and stuff happens. It’s much better than pictures of code in a book. (more…)

MVC and jQuery

Written By: Editor - Feb• 22•11

For my various, larger PHP projects I have used frameworks, most of which have enforced MVC to some degree. Having come to PHP from Java I have been very comfortable in that environment. Frameworks get heavy quickly, though. In recent years I have done less of the big projects and am now down to being mostly a one-man show. If I use a framework at all it is CodeIgniter, which is refreshingly light and solidly MVC.

JavascriptMVC

When it comes to jQuery, I have mostly followed progressive enhancement concepts, building a solid site/app with PHP and then enhancing the user experience with stripy, sortable, refinable tables, accordion menus, client-side form validation, autocomplete/suggest fields, date pickers, and the like. Pretty humdrum, I suppose. I’ve built a couple of web apps with ExtJS, but I’ve never gone that far with jQuery.

Lately I’ve looked at what is being done with MVC for jQuery. I’m disappointed, so far. JMVC is cool, but it is pretty monstrous in view of how light jQuery really is. Maybe I’m wrong, but one of the first things they started talking about was needing Java, installing this and that, and downloading large files.  At the small framework end of the discussion are Ben Nadel’s CorMVC, which is spartan and seemingly orphaned, or Jamal, which seemed to be going somewhere, but has not seen any updates in over two years. At the huge end, SproutCore is cool and PureMVC is spiffy, but they require all-or-nothing buy-in and a major investment of time to start up with, which brings me right back to ExtJS 4 where I’ve already invested myself.

Maybe I’m not ready for an MVC framework with my jQuery, or maybe jQuery is better off outside of that box. Or, perhaps I’m just missing the point somewhere along the line. If I’m going to be building a fairly large application that will be used in an environment where I can control a lot of the variables, perhaps jQuery is the wrong tool for the job. Tell me if I’m all wet. Programming is scheduled to start in late April. All suggestions appreciated.

Auto-grow Text Area

Written By: Editor - Feb• 22•11

Sometimes you have to make compromises when designing forms. I never know how big to make a text area, but I want it to fit in my pretty forms without looking, um… deformed! But that really has little to do with the needs of the user. Scrolling has always been the fallback, even though that can be annoying for the user. But these days, users are getting used to the nifty, self-expanding text boxes used by Facebook and others. Time for me to step it up. Thankfully, the technology is very accessible. There just happens to be a great jQuery plugin. You can set the width with CSS and with one line of jQuery code your design looks great and your visitors get to see all of their text as they type.

Autogrow Text Area

New Ajax Capabilities in jQuery 1.5

Written By: Editor - Feb• 21•11

Rebecca Murphey (@rmurphey) has a very accessible and quick video tutorial on what’s so great about the new ways to call and respond to Ajax data in 1.5+. Once again she boils it down and then delivers a great how-to that leaves you ready to start using the new Ajax right now.

A Refreshed Ajax in jQuery 1.5

Note to self: be more like @rmurphey

Static Code Analysis (linting)

Written By: Editor - Feb• 20•11

There are plenty of ways to debug JavaScript. The first one you ever used was probably just running it in the browser and seeing if it failed. A step up from that is to open a console window and look for errors or warnings. Some IDEs have JS debugging and some even have JSLint available. I’ve tried JSLint, but having never worked with more than one other person on a JS project, I trust my browser add-on tools most often.

This past week there has been a bit of hubbub about a fork of JSLint named JSHint. Since I will be working on an open source project soon, I figured I’d have a look at this fork and see if it was a usable tool. I’m not sure if this is good or bad, but I was able to tweak the rules so that my jQuery got a passing grade. Here are my settings…

  • Allow assignments inside if/for/while/do
  • Require curly braces around all blocks
  • Allow debugger statements
  • Allow logging statements
  • Require ===
  • Require for..in statements to be filtered
  • Apply strict whitespace rules

Notice that I don’t require variables to be declared before usage, nor do I disallow bitwise operators. Plus, I allow assignments inside if/for/while/do blocks. Perhaps I’m just a bad programmer. On the plus side, I am not giving a pass to evals or checking line breaks. I used to put commas at the beginning of the second and subsequent declaration lines, but that’s probably not something I should inflict on other people.

After playing with it for a bit, I really like JSHint. It allows groups to agree on what works for them. Win-win.

Bug Squash Mark I

Written By: Editor - Feb• 19•11

You, like everyone else who is not way out on the bleeding edge, have held back from deploying jQuery 1.5 until at least the first bug-fix release. Looks like that is not far off because the first RC of 1.5.1 is posted and going to press very soon. Have you been testing with deferreds and checking out the speed improvements of 1.5? How soon before you move to 5?