[jQuery] jQuery history plugin - from making the back button work to a more elaborate Hijax solution

[jQuery] jQuery history plugin - from making the back button work to a more elaborate Hijax solution

Hi jQuerians,
people demanded, so I started to extract the history functionality from
the tabs plugin to make a standalone plugin out of it.
Worked out so far:
http://stilbuero.de/jquery/history/
http://stilbuero.de/jquery/tabs/
It's still alpha, support for Firefox, Safari and Opera is there, IE not
yet but will be added. Also todo is to automatically show the
appropriate part, if the hash in the url refers to some point in the
history but I can borrow that from the tabs plugin as well.
At the moment it works by hooking into links and adding an event
handler, like (prototypical code, setHash is required by Safari):
$('a').click(function(e) {
$.history.setHash('#' + this.href.split('#')[1], e);
});
That's ok for me, I think its important to be able to control which
links should be "observed" anyway. So the snippet above might become
$('a.hijax').history();
with
jQuery.fn.history = function() {
return this.each(function() {
$(this).click(function(e) {
jQuery.history.setHash('#' + this.href.split('#')[1]);
});
});
};
Or maybe it is reasonable to use a custom event? I'd like that:
$('a.hijax').bind('history', function() {...}).click(function() {
$(this).trigger('history');
});
Does that work?
But:
You all know, I'm all for unobtrusive JS and the concept of progressive
enhancement. I don't like having a link in my HTML like <a
href="#chapter-1"> which actually points nowhere with JS disabled.
Why not implement a better solution for being able to implement Hijax
the easy way (like what the form module is already offering)?
So the links stay as they are and point to an existing ressource:
<a href="chapter-1.php">
Then I intercept all these links, change the href value to hashes and
load on click the content from the URL of the initial href value via
XHR. Links that already have a hash in their URL won't load via XHR but
add to history (that is needed to stay compatible with tabs).
That would 1. result in history support (in most browsers) and 2. in a
nice gracefully degrading application with JS disabled or for browsers
not supported by jQuery. Totally unobtrusive.
That concept would of course involve the back-end as well. There it must
be decided upon the "X-Requested-With" request header what to send back
(whole page or only the part of the page that needs to be updated.
What do you guys think? Feedback and ideas welcome...
-- Klaus
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/