Skip to a section of this page:

Archive for the ‘DHTML’ Category

Not-so-compact documentation

Monday, March 30th, 2009

I just finished fleshing out the documentation for the compact content widget.

In particular, now each presentation type (tabbed, slideshow and slider) has its own page, that outlines:

  1. How to use that presentation type.
  2. Options that can be set independently for each widget instance.
  3. Configuration that applies globally for all instances of a particular presentation type.
  4. The markup generated when a widget is initialised.

The documentation is fairly detailed, but hopefully this level of detail is useful.

Who started it?

Wednesday, March 25th, 2009

I spent some time this evening thinking about ideas for progressing form validation code.

Specifically, I was trying to solve the conundrum: When the submit event for a form is triggered, how can you tell which user interface element triggered the event?

This problem typically arises when you have multiple submit buttons on a form, when any submit button is activated, the submit event is triggered, but the form element is passed as a property of the event object, not the element (in this case a button) that originally triggered the event.

To complicate matters further, pressing enter while focussed on any input element will also trigger the submit event in many user agents.

Finding a complete robust solution became a bit of an emotional roller-coaster, let me explain…

  1. My initial investigation revealed that jQuery was returning a useful object eventObj.originalEvent.explicitOriginalTarget. :)

    For example:

    $('form').submit(eventObj) {
    	var iStartedIt = eventObj.originalEvent.explicitOriginalTarget;
    };

    Unfortunately, it turned out that explicitOriginalTarget is a Mozilla-specific property, with no cross-browser alternative. :(

  2. My next thought was that the currently focussed element would have to be the element that triggered the submit event! :)

    Unfortunately, jQuery doesn’t have a :focus selector. :(

  3. I found a proposed solution for extending jQuery with a :focus selector. :)

    Unfortunately, it relies on document.activeElement, which is a property only supported in IE, and modern browsers that have implemented parts of the HTML5 draft specification. :(

  4. Luckily, a good fellow proposed a way to support document.activeElement in older browsers that don’t implement it themselves. :)

    And… even better, this seemed to work (well, mostly – see below).

All together now

So put all this together and we get:

// Add document.activeElement support to browsers that don't support it.
if (
	typeof document.activeElement == 'undefined' &&
	document.addEventListener
) {
	document.addEventListener("focus", function(e){
		if (e && e.target) {
			document.activeElement = e.target == document
				? null : e.target;
		}
	}, true);
}

// Extend jQuery to support :focus selector
jQuery.extend(jQuery.expr[':'], {'focus': function(e) {
	return (document.activeElement)
		? e == document.activeElement : false ;
}});

// Now on submit, we can find the element that triggered this event
$('form').submit(function(eventObj) {
	// if a submit button triggered the submit event, find it
	if ((focussedSubmit = $(this).find(':submit:focus')).size() > 0) {
		var iStartedIt = focussedSubmit;
	} else {
		// otherwise find the first submit button
		var iStartedIt = form.find(':submit').eq(0);
	}

	// The iStartedIt variable now contains a reference to the element
	// that triggered the submit event!
};

Tested and working in Firefox 2, Firefox 3, Opera 9.5 but not working correctly in Chrome. IE versions were not tested at this time, but in theory IE6+ should be fine.

Cram it in

Saturday, September 13th, 2008

Update (14/09/2008): The Latest development version uses Ariel Flesler’s scrollTo plugin to achieve some nice transitions. The interaction is coming along, also now supports more than one instance per page. Having problems with browser jumping when URL hash is updated, Chrome copes with this fine, all other browsers fail… hmmm…

Always on the lookout for new ways to cram more information into less space and maintain a good user experience. :)

Here’s a new take on a common (steam-inspired) approach, still under development under development.

I say a new take because I’m putting it together, but I’m sure there are other solutions like it around.

This solution will feature: Semantic markup and content unobtrusively transformed into a compact display with navigation to access each panel.

Obviously, there’s still work to be done, improvements to accessibility and a pausable automatic slideshow function. But the basic functionality is there

Didn’t take very long to put together so far, thank you jQuery.

The idea is to eventually combine this functionality with the existing compact sections script so that any of three display modes can be easily chosen (even switched between) for the compact presentation of sections of content.

Valid updates

Tuesday, July 15th, 2008

XUI Validation has been updated, changes include:

  • Clicking the links in the error summary block now focuses the user on the relevant input (as well as updating the fragment identifier in the URL)
  • A new configuration variable (positionOfInlineAlerts) allows the inline error messages to be displayed either in the input’s label or after the form control itself (after the indicator icon).
  • Tabbing into a control no longer triggers validation.
  • Required fields are only validated after the user leaves the control, so they are not confronted by an error message if they clear the contents of a control to start over.
  • A container element for each form control is updated after validation with the addition of a valid or invalid class so that the elements related to the control can be styled based on the outcome of the validation.
  • The ability to display confirmation messages has been added. This allows the validation functions to confirm with the user how their input is being parsed. This is useful for complex data types like dates.

See the example page for a demonstration of the new features.

Do you validate?

Sunday, July 13th, 2008

I have spent most of my waking moments this weekend coding, refactoring and documenting a framework for easily extensible unobtrusive client-side form validation.

XUI Validation is based on jQuery and provides a simple mechanism for adding new custom validations that will apply via unobtrusive semantic hooks to any form.

Why another unobtrusive validation framework? Because the other OSS validation frameworks I have come across are not as easily extensible, or provide the ability to display a summary of errors a the top of the form (on submit).

Check out the demonstration page demonstration page, or download the package the package to see what I mean.

Thoughts, ideas, feedback? Leave me a comment.