Otaqui.Com

Pete Otaqui’s blog about web development and everything else

Archive for the ‘javascript’ tag

BBC Fisheye Greasemonkey Script

leave a comment

Greasemonkey script to reformat “Author” select elements on the BBC’s Fisheye repository browser, which are ridiculously long (because they contain a considerable chunk of certificate data) which messes with the whole page layout. Shrinking the selects to a more reasonable width fixes this and makes the site more usable.

http://otaqui.com/code/bbc-fisheye/bbc-fisheye.user.js

// ==UserScript==
// @name           BBC FishEye
// @namespace      http://otaqui.com/code/bbc-fisheye
// @description    Make BBC's Fisheye look more like it should
// @include        https://fisheye.dev.bbc.co.uk/*
// ==/UserScript==
var elems = document.evaluate(
    '//select[@name="wbauthor"]',
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null
);
var i=0;
var sel;
while ( sel = elems.snapshotItem(i++) ) sel.style.width = '200px';

Written by pete

April 12th, 2010 at 5:15 pm

Posted in Professional

Tagged with , ,

Fix The “For Attribute Resets Focus on Select Tag” Bug In Internet Explorer using Prototype

one comment

Browser sniffing is bad, or so the logic goes.

There are occasions though where it makes perfect sense – for example where you are fixing a known bug in a specific version of a browser. A good example is the bug in IE 6 that resets the selected index of a Select tag that has a label and the for attribute. This bug doesn’t affect IE 7 or 8, or any other browser, but does make for a bad user experience if you are doing the right thing and including labels for your select tags.

Microsoft has published some javascript to fix this and I adapted their code to work with with the Prototype Javascript Library.

This fix will look for all select tags on the page (you could adapt it to only look for those with the “for” attribute but I have a sneaking suspicion that if anything that would in fact be a bit slower) and observe the onfocusin and onfocus events as suggested in the knowledge base article.

// Select with 'for' attribute fix for IE
Event.observe(window,'load',function() {
	if ( !Prototype.Browser.IE || !(parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6) ) return;
	$$('select').each(function(eSelect) {
		eSelect.observe('focusin',function(e) {
			try {
				var eSrc = window.event.srcElement;
				if ( eSrc ) eSrc.tmpIndex = eSrc.selectedIndex;
			} catch(e) {}
		});
		eSelect.observe('focus',function(e) {
			try {
				var eSrc = window.event.srcElement;
				if ( eSrc ) eSrc.selectedIndex = eSrc.tmpIndex;
			} catch(e) {}
		})
	});
});

Written by pete

February 17th, 2009 at 6:20 pm

Posted in Professional

Tagged with ,