Create a tabbed search form with YUI

Yahoo! makes it easy to create an accessible, handsome tabbed interface. I used their Tab View library to create the tabbed search form for V3GGIE.com. While Tab View can create the tabbed content dynamically, I’m using it to hide/show hard-coded individual forms.

Update: I’ve removed the tabbed interface from V3GGIE.com. This particular use of the tabbed module seemed to have created some confusion in users. The approach is still valid, just not the way I originally implemented it. See the tabbed search form on V3GGIE.com

Step 1. Create the basic HTML code.

The tabbed code is a simple pattern:

  1. Start with a parent div and give it an id and class=”yui-navset”.

  2. Create an unordered list inside this div with class=”yui-nav”.
  3. Each list includes a deep link to a corresponding div that is also a child of the parent div. The link text in an em tag.

  4. V3GGIE Search
  5. Create a div with class=”yui-content” and create a set of content containing divs. Each div has an id.

    ...
    ...
    ...

  6. Insert the Tabview CSS at the top of the page, the Tab View JS at the bottom of the page, create a small js that instantiates the tab-view module.
  7. For easier styling, use the sam_skin CSS package and add class=”yui-skin-sam” to the body.

Step 2. Use PHP to make it more interesting

Each page calls this chunk of code to insert the tabbed form, it also sets a variable ($selected), determining which tab is selected on page load. I’m also inserting the last search query into the text input to make it easier on the user. This is easily done by grabbing the query from the Request object.

The finished code:




Try "San Francisco Pho", "Paris Fromage", or "92104 tofu"


Try "corn chowder" or "vegan pizza"


Try "Vegetarian Chinese Olympics"


Try a subject: "PETA", "Tempeh", or "Paris -Hilton Vegetarian"

View the source as a text file

The Final Product

We now have a tabbed module that allows the user to find recipes, news, blogs, and local restaurants from any page. This is an easy introduction to the YUI libraries. However, I came across the following surprises:

  • The order of the tabs must match the order of the target divs. I moved my tabs around and discovered they were toggling the wrong forms.
  • The links that generate the tabs need to have em tags surrounding the text
  • You’ll need to download the entire YUI package to gain access to the CSS and sprites needed for the library. The examples on the YUI site assume relative links to files, you will either need to duplicate that file structure or upload the skin’s sprite and change the CSS accordingly.

Create your own Search Engine with Yahoo! BOSS

Yahoo! recently launched BOSS, which opened their search platform to developers around the world. They didn’t just create an API to access data. That has been around for a while. Yahoo! has opened the data to developers with no limits on requests, no restrictions of icon use, results display, or even the need to let people know the search engine is Yahoo! based.

Yahoo BOSS plus your special sauce equals search innovation

This open approach lets anyone build a search engine to their particular skills, mash the data with other sources, re-arrange results, or any other novel idea for the next king of search. You could also use BOSS to add search capabilities to a pre-existing site, limiting the resuts to just its data.

Why is Yahoo! doing this? It’s a brash approach to push search beyond its current status of pages with ordered sets of links You can let your imagine fly with the only cost being your personal development investment. I recently took this challenge and decided to build a search engine for vegetarians.

V3GGIE – A Vegetarian Search Engine

My goals were simple:

  1. Create a simple site that could be copied easily as a proof of concept for other genres. Document the construction for others to explore.
  2. Keep it fast with minimal javascript and images
  3. Use as much Yahoo infrastructure as possible to minimize development time
  4. Most importantly: return information relevant to the niche audience: Vegetarians and Vegans.

I’m not a PHP expert and some of my code is crude. I hope to clean it up and add a number of features to enhance performance and usability. However, the code samples will still be useful to the PHP beginner. More advanced PHP programmers could easily see where they’d take the concepts and improve on them.

Set up the basic structure

V3ggie has a basic workflow, there’s an input and result page. Arguably, this should only be one page which displays the original landing and subsequent results. I have separated them as I hope to create extra content that is appropriate to either the landing or results pages.

Further, there are several search engines built into this site. Each has a specific set of resources to fine tune the results. Currently, these are built with subdirectories (/recipes/, /blogs/, /news/, /local/ ). Each subsection includes index and result pages. This could be changed by utilizing rewrite rules. I’ve kept it simple for now.

Setup the Resources

The BOSS API allows you to create a query param with a list of domains to search through. This is the easiest way to fine tune your results. For instance, the V3ggie recipe search page uses a list of vegetarian cooking sites as well as the vegetarian subdirectories of Epicurious and FoodNetwork.

Technorati is the source for blog buzz. V3ggie searches through blogs tagged with “vegetarian” and/or “vegan”. This helps get the vegetarian viewpoint for any subject.

You have complete freedom to mash the data as much as you like. You could take the search results and mix them with other data, such as the page rank for a result page, the company or product’s appearance on wikipedia, or perhaps data you’ve stored in your own databases. I can imagine creating an internal product search page that cross-references the results with a list of preferred vendors to encourage employees to purchase supplies from the correct vendor.

Setup the Platform

V3ggie is built from PHP. However, Yahoo! has also provided a python platform, the BOSS Mashup Framework, for building sites very quickly. You can combine this with the Google App Engine to create a custom search engine in a short time. Four Hour Search, formally known as Yuil, is such an example. It got its name from the length of time it required to research a domain name, setup Google Apps, and build the final search web site. Personally, I spent more than 4 hours trying to get Google Apps set up and I really didn’t want to learn yet another language (python).

YUI on the frontend

The Yahoo! User Interface library handles the tedious, basic formatting of a page. The CSS libraries allow you to create a wide variety of page grids, standardize the fonts, reset browser inconsistencies and establish a common look and feel.

I started the project by using the CSS Grid Builder. This easy to use tool sets up the page with the desired columns and includes the base css files. I then added the YUI Base CSS file. This takes the plain page and re-establishes the margins and font-styles for a basic site. These two CSS files will remove 75% of the CSS you would normally have to write for a site. Now you can concentrate on what makes your site special.

I also wanted to offer different seach options from a single interface. Once again, I used the YUI TabView package. This combination of CSS and JS allows you to create a semantic set of links and corresponding series of div wrapped objects. YUI Tab View will turn this into the tabbed interface that even has built in ARIA support for screen readers.

I had some trouble getting the tabs to look correct. The documentation does not make it very clear that tab links must have an em within the links to get the proper look and feel. I also downloaded the preferred sprite and used fireworks to change the tab color gradients from blue to green.

Yahoo also provides a design pattern library. This helped me configure my pagination links. Yahoo has spent a lot of time with user testing to make sure things are easy to use.

Create your own search engine

So, what are you wating for? Visit the Yahoo Developer Network and start by signing up and getting a application key. I will write separate posts that describe how to build various components of the page. I’m looking forward to hearing from better PHP programmers on how to improve the code.

ARIA support with the YUI library

AJAX and DHTML have made web sites more interactive and easier to use. At least for visitors who are not using a screen reader. Screen reader users have to struggle with pages that lose focus, change without prompting the user of new data, and much more. However, there are many developers working on solutions to this problem.

Todd Kloots, of the Yahoo User Interface group was one of the first to develop accessible javascript libraries with the YUI menu package. He just published a blog post on the YUI web site about adding ARIA support to the YUI tab package. This information could also help you add this functionality to your existing YUI-based applications.

Here’s how Todd describes the goal

The YUI TabView Control is built on a strong
foundation of semantic markup that provides users with some basic accessibility. But while TabView looks like a desktop tab control, screen readers don’t present it as an atomic
widget, leaving users to figure out how the various HTML elements that compose a TabView relate to each other. However, through the application of the WAI-ARIA Roles and States, it is possible to enhance TabView’s accessibility such that users of screen readers perceive it as a desktop tab control.

Enhancing TabView Accessibility with WAI-ARIA Roles and States – Todd Kloots

The following video shows how this approach works with Firefox and a screen reader.

Related articles

Yahoo Search Monkey in Paris

The Yahoo! Developer Network recently held an event in Paris to introduce SearchMonkey to local developers. I was on hand to help discuss microformats. I’ve got a brief write up of the event on the YDN blog: SearchMonkey in Paris.

SearchMonkey

SearchMonkey
SearchMonkey allows developers to create enhanced search result presentations for a web site. These appear when a user installs the easy to create application and then does a search query that provides the module as part of the normal search result.

Yahoo provides microformatted data to the SearchMonkey application at run time. This allows the developer to add great content while still building a very quick application. I’ll write more on this later as I think it is a great usage of Microformats at the user level instead of the developer level.

Beyond SearchMonkey, it’s great to know that search engines really are paying attention to this data. You’ll learn a lot about your site and its microformats as you build your first SearchMonkey application. Give it a try, it shouldn’t take you more than an hour to put together your first application.

La Cantine and the Paris Developer Scene

The event was held at a great space: La Cantine. This is a cross between a cafe and cooperative space for startups to use as an office, meeting space, and development center. It was a pleasure to meet the large crowd that turned out for the night.

Captioning Sucks and Needs a Jump Start

Captioning Sucks - No shit Sherlock, lets fix it
The internet is awash in video. YouTube, Yahoo Video, and other video sites host millions of videos with little attention to close captioning. For many sites, the text translations exist, they simply are not used. This sucks.

Television shows have featured captioning for many years. It’s sometimes the only way to figure out what they are saying on South Park. However, captioning standards are all over the place, the quality of text is questionable, and the industry is not supporting new innovations. This sucks.

Joe Clark is working on a new standard to fix these issues. He probably knows more about captioning than any other breathing creature in the world CaptioningSucks.com is the new home to the future of captioning. Perhaps it is time to buy the domain: CaptioningRules.com, for hopefully it won’t suck much longer.

Related articles