Skip to content

Web nourishment by John Ford and crew

Archive for September, 2006

Using Mouse Wheel to Control script.aculo.us Slider

John Ford Sep 30, 2006

You may have noticed that Google Maps will zoom in and out when you use your mouse wheel (or trackpad scrolling). If you want to do the same thing using the script.aculo.us JavaScript Slider here is an example to get you started.

The example uses a slightly modified version of Adomas Paltanavicius’ mouse wheel event code. Firefox 1.5 seems to work fine but not Safari 1.3. Please let me know how it handles in other browsers.

Example: Using Mouse Wheel to Control Slider

Update: I’ve created a more extensive set of Slider demos which includes the mouse wheel demo. (Nov. 12, 2006)

Boys & Girls Club Is Getting Viral With It

John Ford Sep 27, 2006

Today, I was fortunate enough to give a presentation on HTML to the Salvation Army Boys & Girls Club of Greensboro. A number of directors from the local units came to Central Unit’s computer lab where they built their first web page by hand.

Organized by Ndesanjo Macha (not only is Ndesanjo Unit Director at Central Unit but he’s is the editor for Sub-Saharan Africa for Global Voices Online, “single-handedly built the largest blogosphere in [Swahili],” maintains a Swahili blogging guide, and a board member of The People, Yes among other things), this was step one to get everyones’ feet wet. Steps 2 through 10 will be getting a blog running for each unit, teaching the kids how to maintain it, and for those kids interested, giving them the tools to build their own.

Like Central Unit’s blog, where they share their “fun, art, and learning,” the goal is to get all of the units joining in on the blogosphere conversation. Not only do they teach the kids how to blog at Central Unit but they record and produce their own films, mix their own music, record podcasts, and are currently putting together a sound booth.

They don’t call this Blogsboro for nothing… even the kids share their voice.

Earthlink’s Nonexistent World Domination

John Ford Sep 26, 2006

As an Earthlink subscriber I noticed something odd about a month ago. Instead of my normal browser error when I entered a website that doesn’t exist I got redirected to this:

Earthlink's Nonexistent World Domination

You’ve got to see the page to believe it - advertisements and all. Isn’t this too close to adware or spam? I didn’t ask for this information and I have no way to opt-out of this service but they’d like me to “try the related content suggestions and paid advertisements below.” How kind of them…

This has stirred up quite a bit of controversy.

Update: There is a way to manually configure your computer to use different DNS servers. However, this really isn’t for the common user and sure would add hassle for me as I’d have to change the settings every time I use my laptop somewhere else.

Execute Rails Code Before the View is Rendered

John Ford Sep 25, 2006

At one time, I was looking for a way to execute code for every action in my controller before the view was rendered. I saw this come up again yesterday in the #rubyonrails IRC channel so I looked at it a bit more. Currently, Rails provides a before_filter method which will “run before actions on this controller are performed” or an after_filter which will “run after actions on this controller are performed.” What I wanted was a before_render filter which would run right at the end of the action but before render/view was executed.

Here is one idea how to do this. Since you want the code to run right before render is executed just override the render method that’s in ActionController. You can put the following code inside any of your individual controllers or add it to your ApplicationController and it will run in all of your controllers.

protected
  def render(options = nil, deprecated_status = nil, &block)
    # your code goes here
    @rockon = "rock and roll!"

    # call the ActionController::Base render to show the page
    super
  end

This is just an example, and maybe someone will take this a step further and actually create a before_render filter plugin. It would be nice to have the same flexibility as before_filter and after_filter which allows you to include “:only” or “:exclude” certain actions.

Don’t Submit Your Site to 300+ Search Engines

John Ford Sep 20, 2006

If you ever see a product or website that offers a service to submit your website to hundreds of search engines, here are some reasons not to do it.

  1. Link farms
    As search engines continue to become smarter they often times penalize for having your website listed on link farms or similar sites. It is possible that a submission tool may submit your site to a link farm.
  2. Automatic submission
    Some search engines penalize or ban websites for being automatically entered by software robots. It only takes a moment to submit your website to a search engine so take the time to do it by hand.
  3. Google, Yahoo!, MSN
    A December 2004 report by Nielsen//NetRatings showed the audience reach of US home and work Internet users. The estimates shown below are users who searched on each site at least once during the month.
    • Google - 44.9%
    • Yahoo - 32.0%
    • MSN - 25.2%

Another thing to note is that the search results of the next most popular search sites were usually driven by Google, Overture (Yahoo), or MSN. For example, if you search at AOL then your results are from Google.

AOL Enhanced by Google

Since the very large majority of users search these major search engines then why waste your time with the little guys? It is more cost effective and better for your search engine ranking to spend the extra time submitting your website url to the major search engines listed above and to good Internet directories such as DMOZ.

What should you really be doing?
Blogging! I’ll touch more on the details in future posts but you need to start getting your voice out there. The viral aspects of self publishing and communicating with others has formed a wonderful marriage with Google and the like.

Writing a Custom FormBuilder in Rails

John Ford Sep 19, 2006

I’m currently working on a Ruby on Rails application where I need lots of text fields that have the same properties. I decided to override text_field and have it output all of the extra attribues automatically. This helps keep the view code cleaner, lets me change all of these text fields in one place, and also helps me avoid typing mistakes (at least in this section of the code). Thanks to Ruby on Rails core team member Rick Olson (aka technoweenie) for pointing me to his LabeledFormHelper plugin, which taught me this technique.

Before the custom FormBuilder my initial view code looked something like:

<% form_for(:spreadsheet, @spreadsheet, :url => { :action => 'create' }) do |s| %>

    <% fields_for :numbers, @spreadsheet.numbers do |f| %>

      <%= f.text_field :field1, :onkeypress => 'return isNumberKey(event);', :maxlength => 3 %>
      <%= f.text_field :field2, :onkeypress => 'return isNumberKey(event);', :maxlength => 3 %>

      ... and so on

    <% end %>
<% end %>

So I created a custom FormBuilder in my helper to do the extra text_field work for me:

module SpeadsheetsHelper

  # tell all of these methods to use my custom FormBuilder
  [:form_for, :fields_for, :form_remote_for, :remote_form_for].each do |meth|
    src = <<-end_src
      def speadsheets_#{meth}(object_name, *args, &proc)
        options = args.last.is_a?(Hash) ? args.pop : {}
        options.update(:builder => SpeadsheetsFormBuilder)
        #{meth}(object_name, *(args << options), &proc)
      end
    end_src
    module_eval src, __FILE__, __LINE__
  end

  # the custom FormBuilder
  class SpeadsheetsFormBuilder < ActionView::Helpers::FormBuilder    

    # add onkeypress and set maxlength of field to 3 to all text fields
    def text_field(method, options={})
      super(method, options.merge(:onkeypress => ‘return isNumberKey(event);’, :maxlength => 3))
    end

  end
end

Now my view code is much simpler and helps avoid goofups:

<% spreadsheets_form_for(:spreadsheet, @spreadsheet, :url => { :action => 'create' }) do |s| %>

    <% spreadsheets_fields_for :numbers, @spreadsheet.numbers do |f| %>

      <%= f.text_field :field1 %>
      <%= f.text_field :field2 %>

      ... and so on

    <% end %>
<% end %>

Notice in the view that instead of using form_for and fields_for you need to use the custom methods spreadsheets_form_for and spreadsheets_fields_for which were created in SpeadsheetsHelper.

Meetup: Blogsboro on Wed, Sept 20

John Ford Sep 18, 2006

Weblogger Meetups If you’re around the Greensboro Triad area, and interested in blogging, make sure you join local bloggers at the next Meetup on Wednesday. It’s headed by Blogsboro’s very own ‘Billy The Blogging Poet‘ and free for all to attend. Come meet with other creative minds in the area and get blogging!

Plugin: Bookmark A Page In Your PDF

John Ford Sep 15, 2006

With the long, yet wonderful, books in PDF format these days (Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson with Leon Breedt, Mike Clark, Thomas Fuchs, and Andreas Schwarz [570 pages]; Programming Ruby by Dave Thomas, with Chad Fowler and Andy Hunt [864 pages]) there needs to be a better way to digitally bookmark where you left off. For some reason Adobe Reader (Acrobat Reader) doesn’t have this capability built in. I found a plugin for Acrobat Reader to do multiple bookmarks per document from PDF Hacks. However, I really just want it to be simple like a physical book - you bookmark the page you’re on when you stop and go to that page when you pick back up. So here is my plugin to bookmark your page in Adobe Reader.

Download:

PDF Bookmark 1.1

Change Log:

  • 1.1 - Dec 20, 2007 - Update to work with Adobe Reader 8 due to security changes (app.trustedFunction)
  • 1.0 - Sep 15, 2006 - Initial release

Installation:

Adobe Reader 8 - copy pdf_bookmark.js to:

  • Mac: ~/Library/Acrobat User Data/8.0_x86/JavaScripts (or similar)
  • Windows: C:\Documents and Settings\[User Name]\Application Data\Adobe\Acrobat\8.0\JavaScripts (or similar)

Adobe Reader 7 - copy pdf_bookmark.js to:

  • Mac: ~/Library/Acrobat User Data/7.0/JavaScripts (or similar)
  • Windows: C:\Documents and Settings\[User Name]\Application Data\Adobe\Acrobat\7.0\JavaScripts (or similar)

Note: you may have to create the JavaScripts folder

Usage:

Open your document in Adobe Reader. Then choose Tools -> Bookmark from the menu. “Bookmark This Page” adds the bookmark. “Go To Bookmark” sends you to the bookmark you created. It remembers which PDF document you bookmarked so it works on all of your PDFs simultaneously. (Tested with Acrobat Reader 7 and Adobe Reader 8 (thanks Michael) on Mac OS X and Windows)

PDF Bookmark Plugin Screenshot (8.0)

Back In Blog-ness

John Ford Sep 15, 2006

It’s been almost a year since I had my “business” blog up and I’ve had the shakes ever since. The juices are flowing and I’m ready to get my fix. I hope you enjoy, absorb, and share the information.