Permalink
Browse files

Tabs: Override _isLocal() to account for Ajax nav

We cannot compare hrefs to location.href

Fixes gh-7169
Fixes gh-7725
Closes gh-7727
  • Loading branch information...
gabrielschulhof authored and arschmitz committed Sep 29, 2014
1 parent 9fa3803 commit bc62f9850e12d6b89a17cded8863fa6eaadb755d
Showing with 107 additions and 0 deletions.
  1. +1 −0 js/index.php
  2. +1 −0 js/jquery.mobile.js
  3. +39 −0 js/widgets/tabs.ajax.js
  4. +34 −0 tests/unit/tabs/index.html
  5. +32 −0 tests/unit/tabs/tabs_core.js
View
@@ -95,6 +95,7 @@
'widgets/table.columntoggle.js',
'widgets/table.reflow.js',
'../external/jquery-ui/tabs.js',
'widgets/tabs.ajax.js',
'zoom.js',
'zoom/iosorientationfix.js',
'init.js'
View
@@ -53,6 +53,7 @@ define([
"./widgets/filterable",
"./widgets/filterable.backcompat",
"./jquery-ui/tabs",
"./widgets/tabs.ajax",
"./zoom",
"./zoom/iosorientationfix"
], function( require ) {
View
@@ -0,0 +1,39 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Extension to make Tabs widget aware of jQuery Mobile's navigation
//>>label: Tabs
//>>group: Widgets
define( [
"jquery",
"../defaults",
"../navigation/path",
"../navigation/base",
"jquery-ui/tabs" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
( function( $, undefined ) {
$.widget( "ui.tabs", $.ui.tabs, {
_isLocal: function( anchor ) {
var path, baseUrl, absUrl;
if ( $.mobile.ajaxEnabled ) {
path = $.mobile.path;
baseUrl = path.parseUrl( $.mobile.base.element.attr( "href" ) );
absUrl = path.parseUrl( path.makeUrlAbsolute( anchor.getAttribute( "href" ),
baseUrl ) );
return ( path.isSameDomain( absUrl.href, baseUrl.href ) &&
absUrl.pathname === baseUrl.pathname );
}
return this._superApply( arguments );
}
});
})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
View
@@ -0,0 +1,34 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Table Integration Test</title>
<script src="../../../external/requirejs/require.js"></script>
<script src="../../../js/requirejs.config.js"></script>
<script src="../../../js/jquery.tag.inserter.js"></script>
<script src="../../jquery.setNameSpace.js"></script>
<script src="../../jquery.testHelper.js"></script>
<script src="../../../external/qunit/qunit.js"></script>
<script>
$.testHelper.asyncLoad([
[
"widgets/tabs.ajax",
"support"
],
[ "tabs_core.js" ]
]);
</script>
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
<link rel="stylesheet" href="../../jqm-tests.css"/>
<script src="../../swarminject.js"></script>
</head>
<body>
<div id="qunit"></div>
</body>
</html>
@@ -0,0 +1,32 @@
( function() {
var originalBase,
originalBaseSupport,
phonyDirectory = "/foo/bar/baz/";
module( "Tabs extension", {
setup: function() {
originalBaseSupport = $.support.dynamicBaseTag;
$.support.dynamicBaseTag = true;
originalBase = $.mobile.base.element.attr( "href" );
$.mobile.base.set( phonyDirectory );
},
teardown: function() {
$.support.dynamicBaseTag = originalBaseSupport;
$.mobile.base.set( originalBase );
}
});
test( "_isLocal() correctly identifies URLs as local/non-local", function() {
var _isLocal = $.ui.tabs.prototype._isLocal;
deepEqual( _isLocal( $( "<a href='#some-id'></a>" )[ 0 ] ), true,
"'#some-id' identified as local" );
deepEqual( _isLocal( $( "<a href='" + phonyDirectory + "#some-other-id'></a>" )[ 0 ] ), true,
"'" + phonyDirectory + "#some-other-id' defined as local" );
});
})();

0 comments on commit bc62f98

Please sign in to comment.