University of Oregon

Drupal 6 – Add css with drupal_add_js

I’ve used this method for years and I wanted to post a complete example as a reference.

I love the css_injector module but I like to keep my views’ css with my view.
So this code example has all my required elements for inserting css into a views php header;

  • CSS is readable during editing thanks to php’s HEREDOC
  • function are not re-declared
  • css is minified (Mostly, I keep the white space…)
  • the Drupal.behaviors syntax that ensures code is only ran on the page load
  • and it leverages drupal_add_js

Here it is with in-line comments: (more…)

Drupal 6, Content Profile default username

I have a content profile set up on a number sites and I noticed when I used User / Node Import recently that I couldn’t assign an import value to the title field of the node profile, which I was using as First Name.
After I did the import. I found out why. The “title” field was defaulted with the Drupal user name.
Which is a very good idea.

So I updated my other content profiles to use this same convention but then I realized that there’s no easy way to default that field value to username.
So I considered a

  • Custom module that overrides the content type Profile and defaults the title with the username. – This is the best option
  • jQuery script in a block that runs on the profile edit pages – This is quick but may miss some pages and relies on javascript and possibly my profile set up (show in tabs)
  • jQuery script in a Views block – This may be slightly better than the static script as it pulls the user name from the database, but it’s is more effort

I settled on the simple jQuery script to make it quick.
I pull the user name from the title of the edit page, which in my configuration is the user name.
I don’t know if this is always the case but it was in this case so it made it easy to use jQuery.

I could potentially use this script in a custom module. But staying server-side and preprocessing the fields would make more sense.
I could also set the script to run anytime the edit page is opened.
The jQuery / Block method relies on known, url configurations that == the profile edit page.
For example: Right now the block is set to
Show on only the listed pages.
With these urls:

user/*/edit/profile
user/*/profile/profile*

I couldn’t remember if this would work with out ‘clean URLs’ enabled but a quick test with

$_SERVER['QUERY_STRING']

showed that the query string is still ?q=user/*/edit/profile. So these listed urls should continue to work.
If I ever include the user profile in a page wizard workflow this block probably wouldn’t show up so that’s another point for the custom module method.
(more…)

Added jQuery browser check for ODT and Skillport eLearning

I noticed a mac user getting frustrated when trying to log in to the eLearning site the other day.
The log in process was hung up on the loading screen for a few minutes:

I pointed out that it said ‘click here’ if it doesn’t load after 40 seconds but I realize that’s not very helpful.
It turns out they were using Firefox, which isn’t one of the supported browsers.

We do have the browser compatibility information on the page but that content is collapsed. So the user would have to look for it.
So I decided to add some browser compatibility tests and display a message to mac / firefox users to save them some trouble.
(more…)

Moved Content Highlight Up Above Links

I moved the content highlight section up above the nav links and administrative content.
I had to do this with javascript/jquery so it’s an enhancement for those with javascript enabled but I think it’s nice to keep the content together. (more…)