jQuery 1.3: Part of the Big Deal

I know I'm not among the first to hear: jQuery 1.3 . Why is it worth supporting aggressively? Here's one reason:

This creates another paragraph that -- here it is -- you can click on forever to repeat the same behavior.

If that sounds freaky, look at this chart on the performance implications:

PHP5 Reflection And You

Drupal:

The phpdocs put it kind of weirdly:

PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions and methods as well as extensions.

I prefer the notorious c.h.x.'s definition

chx: it's like this insane cool weaponset of PHP which is like totally unknown :)

Reflection is a very powerful too that lets you understand the code running in your enviroment. This is particularly important for drupal development, as so much of drupal is based on functions that call functions (e.g. hooks).

The point of this tutorial is to show you how much ass reflection can kick, in so little code. The following page finds out every menu item that calls a function hidden away in a remote file, and gives you the location of the callback function: filepath, and line number and all. Note that the vast majority of code is merely used to output the test table. Obviously, this example merely scratches the surface of useful things you could do with this api.

hook_views_query_alter : alter views queries with array keys

While building a product comparison website, I ran into a situation that required a view to sort using one of 2 possible price totals depending on a users profile: lets say "red state", "blue state". The goal was to open up the product comparison tables (order, fields, field names, and filtering questions and all), as well as the underlying data to this companies' staff, so a homebrew wasn't an option (which it shouldn't be, almost 99% of the time).

Luckily, there were only two possible prices for those products, so all I had to do was create two CCK *decimal* fields [ this is important, because text, and integer fields don't properly store or sort decimal points for prices ]. Then, on hook_cron, or a node submit, I updated the two totals based on other itemized fields.

However, how would the view know which column to sort products by based on a flag stored in the users session? There's about 5 ways to do that, so I went with the 1 minute solution:

Set up two sorts in a single view, and implement hook_views_query_alter(&$view, &$query)

<?php
function product_compare_views_query_alter(&$view, &$query) {
// fyi, anonymous sessions need a record in the user table of 0 to work at all....
 
if ($_SESSION['pref']['state_color'] == 'red') {
   
// we'll have to do the less popular red query
    // which's key is [1] (weighted second in the views sort order interface)
   
unset($query->orderby[0]);
  }
  else {
 
// otherwise, don't do the hill billy logic at all....
   
unset($query->orderby[1]);
  }
}
?>

Discussion

In theory, you could write a custom algorithm that built its own sort queries based on a criteria using this method. You could also probably alter filters, or fields. However, this isn't the only way to have accomplished this -- but its the easiest for me to stomach. Never use this method when existing views features, or view arguments, or even other views hooks may be the proper hammer for this nail.

If I learned anything, its that views a complex beast; flexible like F-22 -- an amazing piece of technology that offers tremendous freedom -- but often that freedom will cause you to crash in the ground if you don't think about what you are doing carefully.

Blueprint Vs. 960

The starter guide in my last entry practically gives you an intro to the 960 framework as well. The names are different, but the approach is the same. Though 960 is a bit more complex. .container-x, and both "first" and "last" classes (named alpha, omega, pretentiously enough).

I decided to checkup on a drupal groups thread that discussed CSS frameworks AFTER I hit publish. As it turns out, a 960 theme is on its way to drupal core.

Theme Development With Blueprint

Web Development:

During the drupal.org redesign process, I noticed that Mark Boulton was using blueprint. I decided to give it a spin, and used it on a drupal site for a surgeon who specializes in sports medicine. (heavy use of imagecache, nodequeue, views, books, and nicemenus). Since that project, my stance on blueprint is this:you'll take my CSS framework from cold dead hands.

Is there a drupal theme?

Yes, and its very well made. Offers nothing except a basic grid layout that supports1,2,3 columns, a strong typographical foundation, and the conversions of various drupal elements to the blueprint styles. My "starter theme" of choice. In my humble opinion, the revolutionary advances in drupal 6 make big, bulky starter themes unnecessary.

Blueprint crash course

You don't need to know a whole lot to use blueprint. Everything you absolutely need to know is in the below code example. (with notes below)


  • 1. .container sets width to 950px, and centers the content with auto margins on the side. All grid elements must be within ".container".
  • 2. .clearfix - this does the same thing as having br class="clear" below the floating elements. See the oddly named br element that doesn't need to be there.
  • 2. .span-[x] The width of the column in the grid. Numbers range from 1 to 24. A full row must add up to 24, and can also include prepend-[x], or .append-[x], which share the exact same widths, only add margins, either before or after the column. The final column always needs the class "last" so that it doesn't add its 10px right margin.

And that's really all there is too it. Of course, there are many more features, that let you get perfectly centered borders that don't cause the elements to overflow, some nice typography classes, and other useful stuff that nearly any website needs. I found the best way to learn the framework was to just look at what's going on on the example pages, with firebug. Its all quite self-explanatory.

A Hack for Teaching Drupal

Tags:

How Do You Teach Drupal Without Inducing Confusion/Boredom Triggered Comas? Here's a rule that has never let me down:

Never interact with the drupal site in any way during a lesson

The person you teach needs to click on every menu link, fill out every form, and as they learn, its your job to start taking off the training wheels. At first, you'll have to point them to where to go to add a new taxonomy term, but make it a point to later ask them to add a taxonomy term, and see if they remember how to find it.

This "hack" works well for two reasons:

A Web Development Warchest

Here's the programs and frameworks that I use everyday, and couldn't function without. I figured this list might be useful to someone who's just getting started in web development.

Navigate: The Next Generation Drupal Administration

Sometimes a module comes out of nowhere, and blows away everything else. I believe Navigate is one of those modules.

There are lot of factors that make it awesome:

  • It doesn't get in your way... it stays nearly hidden, as a little circle in the top left corner til you click it. Think designs that didn't foresee the need for massive admin functionality.

If you do click the the top left circle (I think its a steering wheel), you see this:

What so proudly we hail'd at the twilight's last gleaming

Tears of joy. Yes we can. Its really a surreal feeling for the progressively minded in America. We're suspended in a state that oscillates between crying and cheering. I can't really communicate the extent of shame that we've felt for our country's attitude both domestically and internationally. I feel like I'm beginning to release a sort of toxic buildup -- I can't figure out why else tears are coming from my eyes tonight.

I was 18 when George W. Bush came to office. As I matured, I felt shame from being an American: I was morally, and spiritually opposed to him and everything he stood for. It wasn't til tonight that I've felt pride in America -- for the first time, I've been able to appreciate the poetry of our national anthem.

Oh, say, can you see,
by the dawn's early light,
What so proudly we hail'd
at the twilight's last gleaming?

Whose broad stripes and bright stars,
thro' the perilous fight,
O'er the ramparts we watch'd,
were so gallantly streaming?

And the rockets' red glare,
the bombs bursting in air,
Gave proof thro' the night
that our flag was still there.

O say, does that star-spangled banner yet wave
O'er the land of the free and the home of the brave?

The best musical version I found was wordless, and arranged by none other than none other than Sergei Rachmaninoff: the great composer, who recorded this on a piano role in 1919 around the time when the United States granted him asylum from the the soviets. Later versions of the marine corp band's rendition were quite similar in their reverent interpretation.

Listen

No, listening to our national anthem is not a regular passtime of mine, but I felt its a microscopic example of how unusual tonight actually was. Today wakes a completely different America.

Obama Wins Ohio?

I'm still traumatized from 2000, but it looks like this is real. I just said "President Obama" to myself, and felt a sudden surge of joy.

Pages

Subscribe to Nick Lewis: The Blog RSS