|
19 | 19 | if( newPath == undefined ){
|
20 | 20 | newPath = location.hash;
|
21 | 21 | }
|
22 |
| - newPath = newPath.replace(/#/,'').split('/'); |
23 |
| - if(newPath.length){ |
24 |
| - var lastSegment = newPath[newPath.length-1]; |
25 |
| - if( lastSegment.indexOf('.') > -1 || lastSegment == ''){ |
26 |
| - newPath.pop(); |
27 |
| - } |
28 |
| - } |
29 |
| - return newPath.join('/') + (newPath.length ? '/' : ''); |
| 22 | + return newPath.replace(/#/,'').replace(/[^\/]*\.[^\/*]+$/, ''); |
30 | 23 | },
|
31 | 24 |
|
32 | 25 | //return the substring of a filepath before the sub-page key, for making a server request
|
|
48 | 41 | }
|
49 | 42 | },
|
50 | 43 |
|
51 |
| - //base element management, defined depending on dynamic base tag support |
52 |
| - base = $.support.dynamicBaseTag ? { |
53 |
| - |
54 |
| - //define base element, for use in routing asset urls that are referenced in Ajax-requested markup |
55 |
| - element: $("<base>", { href: path.origin }).prependTo( $head ), |
56 |
| - |
57 |
| - //set the generated BASE element's href attribute to a new page's base path |
58 |
| - set: function( href ){ |
59 |
| - base.element.attr('href', path.origin + path.get( href )); |
60 |
| - }, |
61 |
| - |
62 |
| - //set the generated BASE element's href attribute to a new page's base path |
63 |
| - reset: function(){ |
64 |
| - base.element.attr('href', path.origin ); |
65 |
| - } |
66 |
| - |
67 |
| - } : undefined, |
68 |
| - |
69 |
| - |
70 | 44 | //will be defined when a link is clicked and given an active class
|
71 | 45 | $activeClickedLink = null,
|
72 | 46 |
|
|
88 | 62 | //toggled internally when location.hash is updated to match the url of a successful page load
|
89 | 63 | hashListener = true;
|
90 | 64 |
|
| 65 | + //existing base tag? |
| 66 | + var $base = $head.children("base"), |
| 67 | + hostURL = location.protocol + '//' + location.host, |
| 68 | + docLocation = path.get( hostURL + location.pathname ), |
| 69 | + docBase = docLocation; |
| 70 | + |
| 71 | + if ($base.length){ |
| 72 | + var href = $base.attr("href"); |
| 73 | + if (href){ |
| 74 | + if (href.search(/^[^:/]+:\/\/[^/]+\/?/) == -1){ |
| 75 | + //the href is not absolute, we need to turn it into one |
| 76 | + //so that we can turn paths stored in our location hash into |
| 77 | + //relative paths. |
| 78 | + if (href.charAt(0) == '/'){ |
| 79 | + //site relative url |
| 80 | + docBase = hostURL + href; |
| 81 | + } |
| 82 | + else { |
| 83 | + //the href is a document relative url |
| 84 | + docBase = docLocation + href; |
| 85 | + //XXX: we need some code here to calculate the final path |
| 86 | + // just in case the docBase contains up-level (../) references. |
| 87 | + } |
| 88 | + } |
| 89 | + else { |
| 90 | + //the href is an absolute url |
| 91 | + docBase = href; |
| 92 | + } |
| 93 | + } |
| 94 | + //make sure docBase ends with a slash |
| 95 | + docBase = docBase + (docBase.charAt(docBase.length - 1) == '/' ? ' ' : '/'); |
| 96 | + } |
| 97 | + |
| 98 | + //base element management, defined depending on dynamic base tag support |
| 99 | + base = $.support.dynamicBaseTag ? { |
| 100 | + |
| 101 | + //define base element, for use in routing asset urls that are referenced in Ajax-requested markup |
| 102 | + element: ($base.length ? $base : $("<base>", { href: docBase }).prependTo( $head )), |
| 103 | + |
| 104 | + //set the generated BASE element's href attribute to a new page's base path |
| 105 | + set: function( href ){ |
| 106 | + base.element.attr('href', docBase + path.get( href )); |
| 107 | + }, |
| 108 | + |
| 109 | + //set the generated BASE element's href attribute to a new page's base path |
| 110 | + reset: function(){ |
| 111 | + base.element.attr('href', docBase ); |
| 112 | + } |
| 113 | + |
| 114 | + } : undefined; |
| 115 | + |
| 116 | + |
| 117 | + |
91 | 118 | //set location pathname from intial directory request
|
92 | 119 | path.setOrigin();
|
93 | 120 |
|
|
0 commit comments