Index: trunk/extensions/HeaderTabs/HeaderTabs_body.jq.php |
— | — | @@ -35,13 +35,14 @@ |
36 | 36 | |
37 | 37 | for ( $i = 0; $i < ( count( $parts ) / 2 ); $i++ ) { |
38 | 38 | preg_match( '/id="(.*?)"/', $parts[$i * 2], $matches ); |
39 | | - // Forward slashes in tab IDs cause a problem |
40 | | - // in the jQuery UI tabs() function - |
41 | | - // replace them with two underlines (two, to |
42 | | - // avoid conflicting with another tab that |
43 | | - // might have the same name, but with a space |
44 | | - // instead of a slash). |
45 | | - $tabid = str_replace('.2F', '__', $matches[1]); |
| 39 | + // Almost all special characters in tab IDs |
| 40 | + // cause a problem in the jQuery UI tabs() |
| 41 | + // function - in the URLs they already come out |
| 42 | + // as URL-encoded, which is good, but for some |
| 43 | + // reason it's as ".2F", etc., instead of |
| 44 | + // "%2F" - so replace all "." with "_", and |
| 45 | + // everything should be fine. |
| 46 | + $tabid = str_replace('.', '_', $matches[1]); |
46 | 47 | |
47 | 48 | preg_match( '/<span.*?class="mw-headline".*?>\s*(.*?)\s*<\/h1>/', $parts[$i * 2], $matches ); |
48 | 49 | $tabtitle = $matches[1]; |
— | — | @@ -77,8 +78,6 @@ |
78 | 79 | } |
79 | 80 | |
80 | 81 | public static function addHTMLHeader( &$wgOut ) { |
81 | | - global $htUseHistory; // unused, for now |
82 | | - |
83 | 82 | $wgOut->addModules( 'jquery.ui.tabs' ); |
84 | 83 | $js_text =<<<END |
85 | 84 | <script type="text/javascript"> |
— | — | @@ -94,8 +93,18 @@ |
95 | 94 | $(".tabLink").click( function() { |
96 | 95 | var href = $(this).attr('href'); |
97 | 96 | var tabName = href.replace( "#tab=", "" ); |
98 | | - // Fix for tabs with slashes in their name. |
99 | | - tabName = tabName.replace( "/", "__" ); |
| 97 | + // Almost all non-alphanumeric characters in tab names cause |
| 98 | + // problems for jQuery UI tabs, including '.'. The solution: |
| 99 | + // URL-encode all the characters, then replace the resulting |
| 100 | + // '%', plus '.', with '_'. |
| 101 | + tabName = escape( tabName ); |
| 102 | + // For some reason, the JS escape() function doesn't handle |
| 103 | + // '+', '/' or '@' - take care of these manually. |
| 104 | + tabName = tabName.replace( /\+/g, "%2B" ); |
| 105 | + tabName = tabName.replace( /\//g, "%2F" ); |
| 106 | + tabName = tabName.replace( /@/g, "%40" ); |
| 107 | + tabName = tabName.replace( /%/g, "_" ); |
| 108 | + tabName = tabName.replace( /\./g, "_" ); |
100 | 109 | $("#headertabs").tabs('select', tabName); |
101 | 110 | return false; //$htUseHistory; |
102 | 111 | } ); |