Forcing Flowplayer videos in an overlay to stop when they are closed

by Mike Badgley on January 19, 2012

This is an issue that primarily affects Internet Explorer – as far up as IE9 and has to do with the way videos (powered by Flowplayer) are handled within an overlay ‘window’.

All other browsers are smart enough to disabled the Flash object when the parent element (overlay) they are embedded in is closed (hidden via CSS), but with IE a bit more grunt work is required.

Depending on what you are using to create your overlays (in my case I am using jQuery Tools), you’ll need to use (or create) a callback function that fires when the overlay is closed. With jQuery Tools the functions you can use are onBeforeClose or onClose.

onClose: function() {
	var video_state = $f("player1").getState();

	if(video_state === 2 || video_state === 3) {
		var t = setInterval(function() {
			if($f("player1").getState() === 3) {
				$f("player1").pause();
				$f("player1").unload();
				clearInterval(t);
			}
		}, 100);
	}
}

Within the callback function defined above, the state of the instance of the Flowplayer object is returned:

var video_state = $f("player1").getState();

This will return one of seven possible values, with only a couple being values we are interested in – 2 (video is buffering) and 3 (video is playing). If the state of the video is  3 (playing), then we can use the Flowplayer methods available to stop or pause the video, but if the video is still buffering (state 2), then those methods are unavailable and will have no effect, which is why I am using setInterval to check for the current video state.

This solution appears to do the trick, but I would appreciate your feedback once you’ve had a chance to test it out in your own environment.

Forcing the figcaption element to wrap to the width of an image using CSS only

by Mike Badgley on September 30, 2011

This article describes a CSS-based solution for creating a floated <figure> element that allows for a caption (<figcaption>) to be displayed beneath – constrained to the width of the image.

An example of a photo and captionThe example on the left is a fairly common design element, yet one that can be a bit of a pain to style if you want to keep things as fluid and flexible as possible.

There are many solutions out there, or course, but I’ve yet to see one that is non-restrictive and/or easy to implement. To often they rely on a JavaScript plugin or an inline style that forces the width of the container to match the width of the image contained within. On a small site this is fine, but when its a site that is going to be managed by a number of people with varying degrees of HTML/CSS skills, I think its important to keep things as simple as possible.

The solution I came up with is based on a Stack Overflow posting I read that has been modified to work on a wider range of browsers – including IE8 and IE9. As mentioned in the introduction, this is a CSS-only based solution.

For the markup, I utilize the new HTML5 <figure> and <figcaption> elements, which are perfectly suited for this type of UI element:

<figure>
	<img height="215" width="215" src="660799.jpg" />
	<figcaption>
		This is a sample caption that should not exceed the width of the image.
	</figcaption>
</figure>

Pretty simple stuff – with the only real item of note being the height and width attributes on the <img> tag. These are required – and really – should be used regardless so that the browser can ‘smartly’ load the image with the proper dimensions.

Taking this markup and floating it to the left or right as you would normally do with an image, it’s easy to see the problem your going to run into. The caption text is going to keep flowing irregardless of the width of the image. To correct this, we simple do the following:

figure {
	float: left;
	display: table;
	width: 87px;
}

Forcing the <figure> element to display as a table means that the content within will flow to the constraints (width) that is placed upon it. Remember back in the bad old days where you would often see a sidebar column sized at 1% so that it would only take up as much horizontal room as was required by the content within? This is the same sort of idea here.

The ‘table’ is being forced to a width of 87 pixels (a completely arbitrary number – I just happen to be a Penguins fan), but because the image inside of it has a width attribute set (in this case 215 pixels), it grows to accommodate the width of the content and as a result the caption ‘grows’ along with it.

A pretty nifty solution that works very well across all modern browsers I tested on – including IE8. Basically this will work on any browser that supports the display: table CSS property.

Fixed: IE7 Button Text Redraw Bug

by Mike Badgley on May 5, 2011

In a recent article by Zoe Mickley Gillenwater, a text redraw bug was brought to light.

Internet Explorer 7 has a bug where, when it redraws the text of buttons after scrolling them out and then back into the viewport, lines of pixels are missing from the text. I can’t figure out a fix and need some help.

There was some pretty good discussion and solutions offered on how to overcome this annoying glitch that appeared to only occur in IE6 and IE7.

In the end, after spending more time than I’d want to admit on figuring out a way around this, I ended up finding a workable, albeit hacky, solution.

Note: Before reading further, I’d encourage you to check out Zoe’s article so you get the full background on the situation.

Yah, you probably ignored that note above, so here’s my Cole’s Notes version. ;)

The <button> element in IE7 will act a bit wonky when padding is applied to it. Instead of their being the amount that was defined in the CSS, IE7 will typically add a whole bunch of extra space. Not exactly a showstopper, but it’s just one of those annoying things … you know?

Anyhow, the solution to this is to add overflow: visible; to the button, and it will respond like all the other browsers. However, once the button is styled further – primarily with font, padding and background type styles – things start acting up in IE7. Basically, when you being to scroll the Web page, the text on the button will often become distorted and sometimes will disappear completely.

After a number of tests, it became apparent that the main culprit to this text redraw issue was the overflow: visible; declaration. Obviously this was required to fix the other padding bug that I mentioned earlier.

Rather than repeat the conversation in the blog post, I’ll bring a long story short and describe what the final fix was.

The key was to wrap the text within the <button> tag with another element (in this case a <span> tag) and then apply all the formatting to the <span> tag.

<button>
	<span>This is my example button</span>
</button>
.button {
	overflow: visible;
	background: #f00;
	display: inline-block;
	width: auto;
	height: auto;
	margin: 0 10px 10px 0;
	border: none;
	text-align: center;
	cursor: pointer;
	*font-size: 0;
}
	.button span {
		padding: 11px 20px;
		font-size: 20px;
	}

In addition to applying the formatting to the <span> tag, the other important step that had to be taken was forcing the font size to be 0 pixels. Setting a font size on the <button> itself was still causing the same redraw issue, and it wasn’t until I set it to 0px (and then re-initialized it on the <span> tag) that the problem went away for good.

View a demo to see the example above in more detail.

How to absolute position images in IE8

by Mike Badgley on May 5, 2011

I came across an strange display bug (?) in IE8 with how it renders inline imagery that is wrapped with an element that has a position of absolute.

Here’s a quick example to give you  an idea of what I’m talking about. Typically – and  depending on the design – I use absolute positioning to fix the corporate logo of the site to the page, and this is always setup as a hyperlink to the Home page.

<a class="logo" href="/">
	<img alt="ACME Inc" src="logo.png" width="100" height="50">
</a>

I then style the <a> tag to be something like this:

.logo {
	left: 20px;
	position: absolute;
	top: 20px;
}

This will work in every browser with the exception of IE8. For some reason, IE8 does not like it when an image’s parent element is absolutely positioned. When this is the case, IE8 will not render the image at all – only the styling that has been applied to the <img> will be displayed (i.e. padding, borders, background color, etc.).

The quick workaround to this is to instead style the <img> tag directly:

.logo img {
	left: 20px;
	position: absolute;
	top: 20px;
}

This sort of bug also seems to happen in other circumstances as well, even when the image is not being absolutely positioned, so its something to keep your eye on as it can be easy to assume that “it will just work” if perhaps a thorough browser check is not being done to the HTML templates and/or Web site. ;)

A Simple and Accessible Star Rating Widget

by Mike Badgley on April 28, 2011

If you’ve been a front end developer for any length of time you’ve no doubt come across a design that calls for a star rating widget. Depending on the solution, these can be rather complicated to implement, and that’s not taking into account how accessible it is … or isn’t to the end user.

In the fall of last year, Thierry Koblentz published an interesting article on the Yahoo! User Interface Blog called Developing an Accessible Star Ratings Widget which took a close look at the star rating widget. In that article, Thierry did a great job breaking down the widget and showing in  step-by-step fashion how to create a truly accessible star rating solution.

I used this solution on a couple of projects, but found it to be a bit to complicated and ‘wordy’. I wanted something that would be quick and easy to use, while maintaining the same level of accessibility. Whether or not the solution I have created meets that mark is for you to determine.

The solution that I ended up going with is by no means perfect, but I believe that it does the job. Where there may be a few minor (?) flaws with it in terms of accessibility, I believe the simple nature of its implementation more than makes up for that.

So with that being said, lets take a look at how this all works.

The Markup

My goal here was to keep things as simple and clean as possible, while still maintaining a level of accessibility to non-sighted and/or keyboard-only users.

<form class="rating" action="#" method="get">
	<fieldset>
		<legend>Rating:</legend>

		<p>
			<button name="rating" type="submit" value="5" tabindex="5" title="5 out of 5 stars">5/5</button>
			<button name="rating" type="submit" value="4" tabindex="4" title="4 out of 5 stars">4/5</button>
			<button name="rating" type="submit" value="3" tabindex="3" title="3 out of 5 stars" data-checked="checked">3/5</button>
			<button name="rating" type="submit" value="2" tabindex="2" title="2 out of 5 stars">2/5</button>
			<button name="rating" type="submit" value="1" tabindex="1" title="1 out of 5 stars">1/5</button>
		</p>
	</fieldset>
</form>

 

Where this solution differs from Thierry’s is in the way each star is implemented. With the former method, an inline image along with a radio field were used for each ‘star’ in the rating. I’ve bypassed that and instead just used a <button> element.

A few things to note with the <button> element are:

  • It’s all backwards. Unfortunately, due to the lack of an appropriate CSS sibling selector, there was no way of getting around this. I’ll explain in more detail within the CSS section of this post.
  • Each button is assigned a tabindex attribute to atone for my ‘backwards sins’ that I mentioned above. Assigning a tabindex ensures that a proper tab order will be forced. Note: the values (5 through to 1) are purely arbitrary, but the order within the set must be maintained (from highest to lowest).
  • Lastly, is the data-checked attribute which is assigned to the <button> that contains the current rating of the object it is associated with.

The CSS

This rivals the solution by Thierry in terms of simplicity, although I have to give myself a slight edge because I incorporated the seldom-used  general sibling selector. ;)

.rating {

}
	.rating fieldset {
		overflow: hidden;
		width: 120px;
	}
		.rating button {
			background: url(stars.png) 0 0;
			border: none;
			cursor: pointer;
			display: block;
			float: right;
			height: 22px;
			overflow: hidden;
			padding: 0;
			text-indent: -5000px;
			width: 24px;
		}
			.rating button[data-checked],
			.rating button[data-checked] ~ button {
				background-position: 0 -22px;
			}

			.rating button:hover,
			.rating button:hover ~ button,
			.rating button:focus,
			.rating button:focus ~ button {
				background-position: 0 -22px;
			}

 

The only styled element of interest to us is with the button. Most of this is fairly self-explanatory, but the interesting and fun stuff is with the selected (button[data-checked]), hover and focus states. Remember in the first part of the post where I apologized for forcing all the stars to be floated to the right? Well the reason for this was due to the requirement of the general sibling selector.

The general sibling selector is used to ‘select’ all elements that are siblings of a given element. The catch is that it will not select siblings that come before a given element in the DOM. More details and examples on this selector can be found by visiting the link mentioned in the first sentence.

Since I can only select the elements that come after, you can quickly see why I was forced to float all the stars to the right, as opposed to the left.

Final Notes

Obviously there is room for improvement, and the areas that I feel require the most is with how I handle the tabindex. Forcing a tabindex is never the greatest idea, so I’m hoping for some feedback from some of you on this!

In addition, IE7-8 appear to ignore the :focus styling that is applied. I’m not 100% sure why this is, so I would definitely appreciate and feedback you can provide on this issue.