Saturday, March 20, 2010

Blogger title and description with header image

I prefer to set my Blogger header image to "Replace title and description" rather than as a background because it's clickable. However, when images are turned off, the visitor sees only the blog title as the header image's "alt text" and no description. When CSS and images are both off, screenreader users hear no emphasized h1 header, and the missing description provides no additional information.

Wouldn't it be more accessible if the h1 and description were visible when images and/or CSS are turned off?

My first approach to preserving the h1 header and description was to use the "off-left" technique. "Off-left" uses CSS to push a header or other element off the screen with a negative margin. For example:

h1{position: absolute; margin-left: -9999px;}

Off-left works great when CSS is off, but with images off and CSS on, the visitor sees NOTHING. Not good!

After some experimenting, I found a solution that worked with my old Minima blogger template and with my new "Blogger in Draft" template. The result looks like this:

Screenshot of header with images off

The basic steps are to give the header-inner "position", style the title and description, and then position the text behind the header image:

  • Make sure the header-inner div is relatively positioned because we are going to position a new "titlewrapper" div inside of it. The positioning of header-inner creates a reference point for the titlewrapper's absolute position:

    <div id='header-inner' style='position: relative;'>
     
  • Style the title and description inside the header-inner div, so that it looks good when images are off. The styles below are fine for my page, but style the header to suit yourself. My styles are appended just above the end of the blogger skin (]]></b:skin>) for easier maintenance:

    .Header h1 {
    margin: 0;
    padding: 0 0 .3em;
    letter-spacing: .2em;
    }
    .Header .description {
    margin: 0;
    padding: 0;
    max-width: 700px;
    letter-spacing: .2em;
    }

     
  • Add code to the template to include both title and description when a header image is used. I simply copied the titlewrapper div from the 'Show image as background to text' section and pasted it into the 'Show just the image, no text section', and then hid it UNDER the image using absolute positioning. Make sure the header image has a higher z-index than the titlewrapper:

    <b:if cond='data:useImage'>
    <b:if cond='data:imagePlacement == "REPLACE"'>
    <!--Show just the image, no text-->
    <div id='header-inner' style='position: relative;'>
    <a expr:href='data:blog.homepageUrl' style='display: block'>
    <img expr:alt='data:title' expr:height='data:height' expr:id='data:widget.instanceId + "_headerimg"' expr:src='data:sourceUrl' expr:width='data:width' style='display: block; position: relative; z-index: 2;'/> </a>
    <div class='titlewrapper' style='background: transparent; position: absolute; top: 70px; left: 230px; z-index: 1;'>
    <h1 class='title' style='background: transparent; border-width: 0px'>
    <b:include name='title'/>
    </h1>
    <b:include name='description'/>
    </div>

    </div>
    <b:else/>
    <!--
    Show image as background to text. ...
    -->
    <div expr:style='...' id='header-inner'>
    <div class='titlewrapper' style='background: transparent'>
    <h1 class='title' style='background: transparent; border-width: 0px'>
    <b:include name='title'/>
    </h1>
    </div>
    <b:include name='description'/>
    </div>
    </b:if>

     

Gotchas

This method works perfectly as long as the image is opaque, since the h1 and description are still there, but hidden underneath it. I didn't use PNG-24 for transparent corners because the filesize is too big. Perfectly-blended Photoshop corners also look fine, except in IE, which does not honor border-radius, so everything else has square corners and the banner looks wrong.

Another problem is that Firefox 3.6 rounded the image's container, but not the image, so everything but the banner was rounded. I solved this problem by using the image as a background for the home page anchor <a> tag, which is a block element the size of the header. Background images do not display alt text, but the entire banner area is a clickable link, so I don't see that as a problem. I left in the header widget, but commented it out for the time being.

The new Blogger templates are a lot more complex than the old ones, and if you add any code it doesn't like, it will be deleted. So, be patient when editing and remember where you can safely edit the code and where you cannot.

Enjoy the new accessibility!

Friday, March 19, 2010

New template!

I just switched from a 3-column Minima template to "Picture Window", one of the spiffy new templates available from Blogger in Draft. I'm still tweaking it, and working on integrating my banner, so if something looks weird for a while, I'm just trying this and that.

If you want to play with the new templates yourself, you can do so with live, non-destructive, previews. For information on the templates and how to use them go to Blogger in Draft. Then go to http://draft.blogger.com/ and log in as usual. The Template Designer will show up in your Layout tab.

Thanks to the Google Blogger Team for making these new templates available!

Tuesday, March 9, 2010

Amazon carousel in a blogger post

To add a carousel widget to a blogger post, make sure your content column is wide enough for the carousel, and paste the code in the Edit HTML tab. My Post Options are set to: Use "<br /> tags" and "Show HTML literally". Note that you cannot change the white background to another color. However, you can choose to hide the widget's black border and enclose it in a div with a border matching your layout, as shown below:

Tuesday, March 2, 2010

Link to product pages in your Amazon aStore iframe

Quite a few Amazon associates have "aStores" on Blogger. Recently, there have been several questions on the Associates Discussion Board about creating product links in posts that go to product detail pages in the aStore instead of (the same pages on) amazon.com. You can't use the target attribute in these links to load detail pages in the iframe because they are not on the same page as the aStore. The src attribute of the iframe has to be changed, and the only way to do that is with a script. Depending on your site's requirements, the script can be written using jQuery, traditional JavaScript, PHP, or ASP.Net.

Earlier today, I posted an article on my Greene Tea blog about how to accomplish product deep links in a WordPress blog with PHP, and on a non-blog website with jQuery. The jQuery solution also works with Blogger, so I'm posting abbreviated instructions here.

Get jQuery and the getUrlParam jQuery plugin

jQuery: Novice to Ninja

The jQuery library greatly simplifies using JavaScript with web pages. Google hosts the jQuery library and allows developers to link to it. If you already use the jQuery library on another website that you own, you could link to your copy of it. On this blog I've included the jQuery library by adding a script tag for the Google-hosted file in the template's <head> tag:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'/>

I also added a script tag for the getUrlParam.js jQuery plugin file on my web server. The plugin script is short, and could simply be placed on the aStore page, since that is where it will be used. The important thing is that the plugin loads after the jQuery library.

Add a script that modifies the aStore iframe

A short jQuery script on the web page containing the aStore iframe checks each HTTP request for a URL parameter in the query string appended to the basic link. The script runs immediately after the page loads.

In a URL with a query string (always written as one word in code), a question mark designates the end of the link's destination and the beginning of one or more parameters (pieces of information) passed to a script. If there are several parameters, an ampersand (&) is placed between each one as a separator. A query string is often used in searches to facilitate bookmarking, but should never be used to pass sensitive information because it is visible in the link.

What we want the script to do is change the source of the iframe from the aStore's default home page to the detail page for a product that you previously added to the store. The source link follows this simple pattern:

http://astore.amazon.com/yourAffiliateID-20/detail/ASIN

You would replace "yourAffiliateID-20" with your own Amazon affiliate ID or a different tracking ID for the store, and ASIN with the 10-digit product number (usually the ISBN-10 for books).

The script will change the src of the iframe (which must have an id) ONLY IF a query string with a parameter named "azdp" exists in the URL. The parameter name can be anything you want, as long as it is unique, to prevent conflict with any other Blogger parameters. The value of the "azdp" param is Amazon’s product ID number, or ASIN.

<script type="text/javascript">
$(document).ready(function(){
var newSrc = $(document).getUrlParam("azdp")
if (newSrc !== null) {
$('#astore').attr('src','http://astore.amazon.com/affiliateID-20/detail/'+newSrc);
} })
</script>

Create links that work with the script

Links that go to your web page with the aStore follow this pattern:

<a href='http://yourblog.blogspot.com/p/amazon-store-page.html?azdp=ASIN>Good Book</a>

Replace "affiliateID-20" with your own affiliateID and ASIN with the 10-digit product ID. Here's an example link that goes to the Real Tea aStore on this blog:
<a href="http://www.greeneteapot.com/p/real-tea.html?azdp=B0032A8P2K">Japanese Izu Matcha<\a> Japanese IzuMatcha

I hope this information is helpful to some of you!