Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions examples/urlinternal/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
$(function(){
var loc = document.location,
fragment1 = loc.href.replace( /#.*$/, '' ) + '#test-anchor',
fragment2 = loc.href.replace( /^https?:\/\/(?:.*?)(\/[^#]*)#?.*$/i, '$1' ) + '#test-anchor';

fragment2 = loc.href.replace( /^https?:([^#]*)#?.*$/i, '$1' ) + '#test-anchor';
fragment3 = loc.href.replace( /^https?:\/\/(?:.*?)(\/[^#]*)#?.*$/i, '$1' ) + '#test-anchor';

$('#fragment1').attr({ href: fragment1 }).html( '<span>' + fragment1 + '</span>' );
$('#fragment2').attr({ href: fragment2 }).html( '<span>' + fragment2 + '</span>' );
$('#fragment3').attr({ href: fragment3 }).html( '<span>' + fragment3 + '</span>' );

$.elemUrlAttr({ span: 'data-url' });

Expand Down Expand Up @@ -234,7 +236,8 @@ function callback_urlFragment() {
<tr><td><a href="./#test-anchor">./#test-anchor</a></td></tr>
<tr><td><a href="../urlinternal/#test-anchor">../urlinternal/#test-anchor</a></td></tr>
<tr><td><a href="#" id="fragment1">absolute path to this page plus a fragment</a></td></tr>
<tr><td><a href="#" id="fragment2">/relative path to this page plus a fragment</a></td></tr>
<tr><td><a href="#" id="fragment2">protocol relative absolute path to this page plus a fragment</a></td></tr>
<tr><td><a href="#" id="fragment3">/relative path to this page plus a fragment</a></td></tr>

<tr class="header"><th>non-navigating links</th></tr>
<tr class="meta"><td>element</td></tr>
Expand Down
4 changes: 4 additions & 0 deletions jquery.ba-urlinternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
matches = loc.href.match( /^((https?:\/\/.*?\/)?[^#]*)#?.*$/ ),
loc_fragbase = matches[1] + '#',
loc_hostbase = matches[2],
loc_fragbasenoprotocol = loc_fragbase.replace( /^https?:(.*)/g, '$1' ),

// Method references.
jq_elemUrlAttr,
Expand Down Expand Up @@ -184,6 +185,9 @@
// url is absolute and contains a fragment, but is otherwise the same URI.
|| url.indexOf( loc_fragbase ) === 0

// url is "protocol relative" absolute and contains a fragment, but is otherwise the same URI.
|| ( matches[0].slice(0, 2) === '//' && url.indexOf( loc_fragbasenoprotocol ) === 0 )

// url is relative, begins with '/', contains a fragment, and is otherwise
// the same URI.
|| ( matches[1] === '/' ? loc_hostbase + matches[2] === loc_fragbase
Expand Down
4 changes: 2 additions & 2 deletions jquery.ba-urlinternal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions unit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

var loc = document.location,
fragment1 = loc.href.replace( /#.*$/, '' ) + '#test-anchor',
fragment2 = loc.href.replace( /^https?:\/\/(?:.*?)(\/[^#]*)#?.*$/i, '$1' ) + '#test-anchor',
fragment2 = loc.href.replace( /^https?:([^#]*)#?.*$/i, '$1' ) + '#test-anchor',
fragment3 = loc.href.replace( /^https?:\/\/(?:.*?)(\/[^#]*)#?.*$/i, '$1' ) + '#test-anchor',
domain = loc.host.replace( /^www\./, '' ),
www_domain = 'www.' + domain,
re_domain = domain.replace( /\./g, '\\.' ),
Expand Down Expand Up @@ -63,6 +64,7 @@
+ '<div class="n0 n1 n2 f3 wf3"><a href="../unit/#test-anchor">../unit/#test-anchor</a></div>'
+ '<div class="n0 n1 n2 f3 wf3"><a href="' + fragment1 + '">' + fragment1 + '</a></div>'
+ '<div class="n0 n1 n2 f3 wf3"><a href="' + fragment2 + '">' + fragment2 + '</a></div>'
+ '<div class="n0 n1 n2 f3 wf3"><a href="' + fragment3 + '">' + fragment3 + '</a></div>'

+ '<div class="i0 i1 i2 wi0 wi1 wi2"><form action="?mode=test" method="post">form</form></div>'
+ '<div class="i0 i1 i2 wi0 wi1 wi2"><form action="http://' + domain + '/foo/?a=1&b=2" method="get">form</form></div>'
Expand Down Expand Up @@ -119,7 +121,7 @@
module("isUrlInternal");

test("$.isUrlInternal", function() {
expect( 150 );
expect( 153 );

$.each( tests, function(i,func){
func();
Expand Down Expand Up @@ -152,7 +154,7 @@
module("isUrlExternal");

test("$.isUrlExternal", function() {
expect( 150 );
expect( 153 );

$.each( tests, function(i,func){
func();
Expand Down Expand Up @@ -185,7 +187,7 @@
module("isUrlFragment");

test("$.isUrlFragment", function() {
expect( 50 );
expect( 51 );

$('#test').children().each(function(){
var props = get_props( 3, this, 'f' );
Expand Down