* LocationHtml5Url represents a URL * This object is exposed as $location service when HTML5 mode is enabled and supported * * @constructor * @param {string} appBase application base URL * @param {string} appBaseNoFile application base URL stripped of any filename * @param {string} basePrefix
(appBase, appBaseNoFile, basePrefix)
| 13869 | * @param {string} basePrefix URL path prefix |
| 13870 | */ |
| 13871 | function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { |
| 13872 | this.$$html5 = true; |
| 13873 | basePrefix = basePrefix || ''; |
| 13874 | parseAbsoluteUrl(appBase, this); |
| 13875 | |
| 13876 | |
| 13877 | /** |
| 13878 | * Parse given HTML5 (regular) URL string into properties |
| 13879 | * @param {string} url HTML5 URL |
| 13880 | * @private |
| 13881 | */ |
| 13882 | this.$$parse = function(url) { |
| 13883 | var pathUrl = stripBaseUrl(appBaseNoFile, url); |
| 13884 | if (!isString(pathUrl)) { |
| 13885 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 13886 | appBaseNoFile); |
| 13887 | } |
| 13888 | |
| 13889 | parseAppUrl(pathUrl, this, true); |
| 13890 | |
| 13891 | if (!this.$$path) { |
| 13892 | this.$$path = '/'; |
| 13893 | } |
| 13894 | |
| 13895 | this.$$compose(); |
| 13896 | }; |
| 13897 | |
| 13898 | /** |
| 13899 | * Compose url and update `absUrl` property |
| 13900 | * @private |
| 13901 | */ |
| 13902 | this.$$compose = function() { |
| 13903 | var search = toKeyValue(this.$$search), |
| 13904 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 13905 | |
| 13906 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 13907 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 13908 | |
| 13909 | this.$$urlUpdatedByLocation = true; |
| 13910 | }; |
| 13911 | |
| 13912 | this.$$parseLinkUrl = function(url, relHref) { |
| 13913 | if (relHref && relHref[0] === '#') { |
| 13914 | // special case for links to hash fragments: |
| 13915 | // keep the old url and only replace the hash fragment |
| 13916 | this.hash(relHref.slice(1)); |
| 13917 | return true; |
| 13918 | } |
| 13919 | var appUrl, prevAppUrl; |
| 13920 | var rewrittenUrl; |
| 13921 | |
| 13922 | |
| 13923 | if (isDefined(appUrl = stripBaseUrl(appBase, url))) { |
| 13924 | prevAppUrl = appUrl; |
| 13925 | if (basePrefix && isDefined(appUrl = stripBaseUrl(basePrefix, appUrl))) { |
| 13926 | rewrittenUrl = appBaseNoFile + (stripBaseUrl('/', appUrl) || appUrl); |
| 13927 | } else { |
| 13928 | rewrittenUrl = appBase + prevAppUrl; |
nothing calls this directly
no test coverage detected