Managed to scratch my own itch. Wrote front-running event handler for
clicks on A tags. In case anyone may need something like this:
This works with Sammy.js 6.x latest. (Did not have a reason to upgrade
to or test with 7.x)
Upon click on A tag, "relative" hash like "#../../path/resource" is
computed against current ("referrer") hash (for, example,
"#/asdf/qwer/zxvc/this_part_is_not_folder" to result in
"#/asdf/path/resource". The new resolved "absolute" hash is written
into href of the clicked link and we release the event. It bubbles up
and "finishes" the click, now with new href.
Presto: "relative" hash references between AJAXy subpages.
------------------
$(sammy_controlled_element_selector).on('click.sammy_front_runner',
'a', function(e){
/** @preserve
Copyright 2012 - Willow Systems Corporation (
willow-systems.com)
MIT or GPLv2
*/
var $t = $(e.currentTarget)
, encodedHash = $t.attr('href')
// if encodedHash starts with "#.." indicating start of relative hash
if (encodedHash.substr(0, 3) === '#..'){
var resolvedURL = $t.prop('href').split(encodedHash)
// if there is nothing trailing the relative hash fragment in
resolved URL
if (resolvedURL.length === 2 && resolvedURL[1] === ''){
var newHashParts = window.location.hash.split('/')
// regardless of if the end was "/" (resulting in last
string of "") or "file.ext", it's not a name of "dir". Dropping.
newHashParts.pop()
// chopping off "#" and splitting the dirs in new relative hash
var encodedHashParts = encodedHash.substr(1,
encodedHash.length).split('/')
, section
while(encodedHashParts.length){
section = encodedHashParts.shift()
if (section === "..") {
if (newHashParts.length > 1 /* we are keeping '#'
in place */) {newHashParts.pop()}
}
else if (section === ".") {}
else {newHashParts.push(section)}
}
var newHash = newHashParts.join('/')
$t.attr('href', newHash)
$t.prop('href', resolvedURL[0] + newHash)
}
}
return true;
})
-----------------------------------
> --
> You received this message because you are subscribed to the Google Groups
> "Sammy.js" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/sammyjs/-/dqfXzV9oDsMJ.
>
> To post to this group, send email to
sam...@googlegroups.com.
> To unsubscribe from this group, send email to
>
sammyjs+u...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/sammyjs?hl=en.