* LocationUrl represents an url * This object is exposed as $location service when HTML5 mode is enabled and supported * * @constructor * @param {string} url HTML5 url * @param {string} pathPrefix
(url, pathPrefix, appBaseUrl)
| 5137 | * @param {string} pathPrefix |
| 5138 | */ |
| 5139 | function LocationUrl(url, pathPrefix, appBaseUrl) { |
| 5140 | pathPrefix = pathPrefix || ''; |
| 5141 | |
| 5142 | /** |
| 5143 | * Parse given html5 (regular) url string into properties |
| 5144 | * @param {string} newAbsoluteUrl HTML5 url |
| 5145 | * @private |
| 5146 | */ |
| 5147 | this.$$parse = function(newAbsoluteUrl) { |
| 5148 | var match = matchUrl(newAbsoluteUrl, this); |
| 5149 | |
| 5150 | if (match.path.indexOf(pathPrefix) !== 0) { |
| 5151 | throw Error('Invalid url "' + newAbsoluteUrl + '", missing path prefix "' + pathPrefix + '" !'); |
| 5152 | } |
| 5153 | |
| 5154 | this.$$path = decodeURIComponent(match.path.substr(pathPrefix.length)); |
| 5155 | this.$$search = parseKeyValue(match.search); |
| 5156 | this.$$hash = match.hash && decodeURIComponent(match.hash) || ''; |
| 5157 | |
| 5158 | this.$$compose(); |
| 5159 | }; |
| 5160 | |
| 5161 | /** |
| 5162 | * Compose url and update `absUrl` property |
| 5163 | * @private |
| 5164 | */ |
| 5165 | this.$$compose = function() { |
| 5166 | var search = toKeyValue(this.$$search), |
| 5167 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 5168 | |
| 5169 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 5170 | this.$$absUrl = composeProtocolHostPort(this.$$protocol, this.$$host, this.$$port) + |
| 5171 | pathPrefix + this.$$url; |
| 5172 | }; |
| 5173 | |
| 5174 | |
| 5175 | this.$$rewriteAppUrl = function(absoluteLinkUrl) { |
| 5176 | if(absoluteLinkUrl.indexOf(appBaseUrl) == 0) { |
| 5177 | return absoluteLinkUrl; |
| 5178 | } |
| 5179 | } |
| 5180 | |
| 5181 | |
| 5182 | this.$$parse(url); |
| 5183 | } |
| 5184 | |
| 5185 | |
| 5186 | /** |
nothing calls this directly
no test coverage detected