Skip to content

Commit 7aa7778

Browse files
committedMar 29, 2025··
1 parent e98b191 commit 7aa7778

File tree

1 file changed

+45
-24
lines changed
  • vendor/assets/javascripts/jquery-ui/widgets

1 file changed

+45
-24
lines changed
 

‎vendor/assets/javascripts/jquery-ui/widgets/tabs.js

+45-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//= require jquery-ui/widget
55

66
/*!
7-
* jQuery UI Tabs 1.14.1
7+
* jQuery UI Tabs @VERSION
88
* https://jqueryui.com
99
*
1010
* Copyright OpenJS Foundation and other contributors
@@ -43,7 +43,7 @@
4343
"use strict";
4444

4545
$.widget( "ui.tabs", {
46-
version: "1.14.1",
46+
version: "@VERSION",
4747
delay: 300,
4848
options: {
4949
active: null,
@@ -66,26 +66,19 @@ $.widget( "ui.tabs", {
6666
load: null
6767
},
6868

69-
_isLocal: ( function() {
70-
var rhash = /#.*$/;
69+
_isLocal: function( anchor ) {
70+
var anchorUrl = new URL( anchor.href ),
71+
locationUrl = new URL( location.href );
7172

72-
return function( anchor ) {
73-
var anchorUrl, locationUrl;
73+
return anchor.hash.length > 1 &&
7474

75-
anchorUrl = anchor.href.replace( rhash, "" );
76-
locationUrl = location.href.replace( rhash, "" );
77-
78-
// Decoding may throw an error if the URL isn't UTF-8 (#9518)
79-
try {
80-
anchorUrl = decodeURIComponent( anchorUrl );
81-
} catch ( error ) {}
82-
try {
83-
locationUrl = decodeURIComponent( locationUrl );
84-
} catch ( error ) {}
85-
86-
return anchor.hash.length > 1 && anchorUrl === locationUrl;
87-
};
88-
} )(),
75+
// `href` may contain a hash but also username & password;
76+
// we want to ignore them, so we check the three fields
77+
// below instead.
78+
anchorUrl.origin === locationUrl.origin &&
79+
anchorUrl.pathname === locationUrl.pathname &&
80+
anchorUrl.search === locationUrl.search;
81+
},
8982

9083
_create: function() {
9184
var that = this,
@@ -126,18 +119,31 @@ $.widget( "ui.tabs", {
126119
_initialActive: function() {
127120
var active = this.options.active,
128121
collapsible = this.options.collapsible,
129-
locationHashDecoded = decodeURIComponent( location.hash.substring( 1 ) );
122+
locationHash = location.hash.substring( 1 ),
123+
locationHashDecoded = decodeURIComponent( locationHash );
130124

131125
if ( active === null ) {
132126

133127
// check the fragment identifier in the URL
134-
if ( locationHashDecoded ) {
128+
if ( locationHash ) {
135129
this.tabs.each( function( i, tab ) {
136-
if ( $( tab ).attr( "aria-controls" ) === locationHashDecoded ) {
130+
if ( $( tab ).attr( "aria-controls" ) === locationHash ) {
137131
active = i;
138132
return false;
139133
}
140134
} );
135+
136+
// If not found, decode the hash & try again.
137+
// See the comment in `_processTabs` under the `_isLocal` check
138+
// for more information.
139+
if ( active === null ) {
140+
this.tabs.each( function( i, tab ) {
141+
if ( $( tab ).attr( "aria-controls" ) === locationHashDecoded ) {
142+
active = i;
143+
return false;
144+
}
145+
} );
146+
}
141147
}
142148

143149
// Check for a tab marked active via a class
@@ -435,9 +441,24 @@ $.widget( "ui.tabs", {
435441

436442
// Inline tab
437443
if ( that._isLocal( anchor ) ) {
438-
selector = decodeURIComponent( anchor.hash );
444+
445+
// The "scrolling to a fragment" section of the HTML spec:
446+
// https://html.spec.whatwg.org/#scrolling-to-a-fragment
447+
// uses a concept of document's indicated part:
448+
// https://html.spec.whatwg.org/#the-indicated-part-of-the-document
449+
// Slightly below there's an algorithm to compute the indicated
450+
// part:
451+
// https://html.spec.whatwg.org/#the-indicated-part-of-the-document
452+
// First, the algorithm tries the hash as-is, without decoding.
453+
// Then, if one is not found, the same is attempted with a decoded
454+
// hash. Replicate this logic.
455+
selector = anchor.hash;
439456
panelId = selector.substring( 1 );
440457
panel = that.element.find( "#" + CSS.escape( panelId ) );
458+
if ( !panel.length ) {
459+
panelId = decodeURIComponent( panelId );
460+
panel = that.element.find( "#" + CSS.escape( panelId ) );
461+
}
441462

442463
// remote tab
443464
} else {

0 commit comments

Comments
 (0)