Fixes #900 - buttons with rel attribute set to external don't show active state

This commit is contained in:
adammessinger 2011-01-30 23:43:53 -08:00 committed by John Bender
parent 8b5f083974
commit cb4f540645
2 changed files with 43 additions and 25 deletions

View file

@ -68,6 +68,10 @@
//check if the url is relative
isRelative: function( url ){
return /^[^\/|#]/.test( url ) && !path.hasProtocol( url );
},
isEmbeddedPage: function( url ){
return /^#/.test( url );
}
},
@ -582,8 +586,16 @@
//get href, remove same-domain protocol and host
url = path.clean( $this.attr( "href" ) ),
//check if it's external
isExternal = path.isExternal( url ) || $this.is( "[rel='external']" ),
//rel set to external
isRelExternal = $this.is( "[rel='external']" ),
//rel set to external
isEmbeddedPage = path.isEmbeddedPage( url ),
//check for protocol or rel and its not an embedded page
//TODO overlap in logic from isExternal, rel=external check should be
// moved into more comprehensive isExternalLink
isExternal = path.isExternal( url ) || isRelExternal && !isEmbeddedPage;
//if target attr is specified we mimic _blank... for now
hasTarget = $this.is( "[target]" );

View file

@ -37,63 +37,61 @@
same(called, 2, "change page should be called twice");
});
test( "path.get method is working properly", function(){
same($.mobile.path.get(), window.location.hash, "get method returns location.hash");
same($.mobile.path.get( "#foo/bar/baz.html" ), "foo/bar/", "get method with hash arg returns path with no filename or hash prefix");
same($.mobile.path.get( "#foo/bar/baz.html/" ), "foo/bar/baz.html/", "last segment of hash is retained if followed by a trailing slash");
});
test( "path.getFilePath method is working properly", function(){
same($.mobile.path.getFilePath("foo.html" + "&" + $.mobile.subPageUrlKey ), "foo.html", "returns path without sub page key");
});
test( "path.set method is working properly", function(){
$.mobile.urlHistory.listeningEnabled = false;
$.mobile.path.set("foo");
same("foo", window.location.hash.replace(/^#/,""), "sets location.hash properly");
location.hash = "";
});
test( "path.makeAbsolute is working properly", function(){
$.mobile.urlHistory.listeningEnabled = false;
$.mobile.path.set("bar/");
same( $.mobile.path.makeAbsolute("test.html"), "bar/test.html", "prefixes path with absolute base path from hash");
location.hash = "";
});
test( "path.clean is working properly", function(){
var localroot = location.href.split("/").slice(0, 3).join("/"),
remoteroot = "http://google.com/",
fakepath = "foo/bar/baz.html",
localpath = localroot + fakepath,
remotepath = remoteroot + fakepath;
same( $.mobile.path.clean( localpath ), fakepath, "removes location protocol, host, port from same-domain path");
same( $.mobile.path.clean( remotepath ), remotepath, "does nothing to an external domain path");
});
test( "path.stripHash is working properly", function(){
same( $.mobile.path.stripHash( "#bar" ), "bar", "returns a hash without the # prefix");
});
test( "path.hasProtocol is working properly", function(){
same( $.mobile.path.hasProtocol( "tel:5559999" ), true, "value in tel protocol format has protocol" );
same( $.mobile.path.hasProtocol( location.href ), true, "location href has protocol" );
same( $.mobile.path.hasProtocol( "foo/bar/baz.html" ), false, "simple directory path has no protocol" );
same( $.mobile.path.hasProtocol( "file://foo/bar/baz.html" ), true, "simple directory path with file:// has protocol" );
});
test( "path.isRelative is working properly", function(){
same( $.mobile.path.isRelative("#foo/bar"), false, "path starting with a # is not relative" );
same( $.mobile.path.isRelative("/foo/bar"), false, "path starting with a / is not relative" );
same( $.mobile.path.isRelative("http://example.com/foo"), false, "full url path is not relative" );
same( $.mobile.path.isRelative("foo/bar.html"), true, "simple path is relative" );
});
test( "path.isExternal is working properly", function(){
same( $.mobile.path.isExternal( location.href ), false, "same domain is not external" );
same( $.mobile.path.isExternal( "http://example.com" ), true, "example.com is external" );
@ -108,44 +106,52 @@
same($.mobile.path.isExternal("foo"), false, "simple string");
same($.mobile.path.isExternal("#foo"), false, "local id reference");
});
test( "path.isEmbeddedPage should return true when the url represents a page id", function(){
same($.mobile.path.isEmbeddedPage("#foo"), true, "local id ref");
});
test( "path.isEmbeddedPage should return false when doesnt contain a preceding hash", function(){
same($.mobile.path.isEmbeddedPage("foo"), false, "local id ref");
same($.mobile.path.isEmbeddedPage("foo/bar/baz"), false, "local id ref");
});
test( "urlHistory is working properly", function(){
//urlHistory
same( $.type( $.mobile.urlHistory.stack ), "array", "urlHistory.stack is an array" );
//preload the stack
$.mobile.urlHistory.stack[0] = { url: "foo", transition: "bar" };
$.mobile.urlHistory.stack[1] = { url: "baz", transition: "shizam" };
$.mobile.urlHistory.stack[2] = { url: "shizoo", transition: "shizaah" };
//active index
same( $.mobile.urlHistory.activeIndex , 0, "urlHistory.activeIndex is 0" );
//getActive
same( $.type( $.mobile.urlHistory.getActive() ) , "object", "active item is an object" );
same( $.mobile.urlHistory.getActive().url , "foo", "active item has url foo" );
same( $.mobile.urlHistory.getActive().transition , "bar", "active item has transition bar" );
//get prev / next
same( $.mobile.urlHistory.getPrev(), undefined, "urlHistory.getPrev() is undefined when active index is 0" );
$.mobile.urlHistory.activeIndex = 1;
same( $.mobile.urlHistory.getPrev().url, "foo", "urlHistory.getPrev() has url foo when active index is 1" );
$.mobile.urlHistory.activeIndex = 0;
same( $.mobile.urlHistory.getNext().url, "baz", "urlHistory.getNext() has url baz when active index is 0" );
//add new
$.mobile.urlHistory.activeIndex = 2;
$.mobile.urlHistory.addNew("test");
same( $.mobile.urlHistory.stack.length, 4, "urlHistory.addNew() adds an item after the active index" );
same( $.mobile.urlHistory.activeIndex, 3, "urlHistory.addNew() moves the activeIndex to the newly added item" );
//clearForward
$.mobile.urlHistory.activeIndex = 0;
$.mobile.urlHistory.clearForward();
same( $.mobile.urlHistory.stack.length, 1, "urlHistory.clearForward() clears the url stack after the active index" );
});
//url listening
asyncTest( "ability to disable our hash change event listening", function(){
$.mobile.urlHistory.listeningEnabled = false;
@ -160,5 +166,5 @@
location.hash = "";
}, 1000);
});
})(jQuery);