* LocationHtml5Url represents an 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)
| 11758 | * @param {string} basePrefix url path prefix |
| 11759 | */ |
| 11760 | function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) { |
| 11761 | this.$$html5 = true; |
| 11762 | basePrefix = basePrefix || ''; |
| 11763 | parseAbsoluteUrl(appBase, this); |
| 11764 | |
| 11765 | |
| 11766 | /** |
| 11767 | * Parse given html5 (regular) url string into properties |
| 11768 | * @param {string} url HTML5 url |
| 11769 | * @private |
| 11770 | */ |
| 11771 | this.$$parse = function(url) { |
| 11772 | var pathUrl = beginsWith(appBaseNoFile, url); |
| 11773 | if (!isString(pathUrl)) { |
| 11774 | throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url, |
| 11775 | appBaseNoFile); |
| 11776 | } |
| 11777 | |
| 11778 | parseAppUrl(pathUrl, this); |
| 11779 | |
| 11780 | if (!this.$$path) { |
| 11781 | this.$$path = '/'; |
| 11782 | } |
| 11783 | |
| 11784 | this.$$compose(); |
| 11785 | }; |
| 11786 | |
| 11787 | /** |
| 11788 | * Compose url and update `absUrl` property |
| 11789 | * @private |
| 11790 | */ |
| 11791 | this.$$compose = function() { |
| 11792 | var search = toKeyValue(this.$$search), |
| 11793 | hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : ''; |
| 11794 | |
| 11795 | this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash; |
| 11796 | this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/' |
| 11797 | }; |
| 11798 | |
| 11799 | this.$$parseLinkUrl = function(url, relHref) { |
| 11800 | if (relHref && relHref[0] === '#') { |
| 11801 | // special case for links to hash fragments: |
| 11802 | // keep the old url and only replace the hash fragment |
| 11803 | this.hash(relHref.slice(1)); |
| 11804 | return true; |
| 11805 | } |
| 11806 | var appUrl, prevAppUrl; |
| 11807 | var rewrittenUrl; |
| 11808 | |
| 11809 | if (isDefined(appUrl = beginsWith(appBase, url))) { |
| 11810 | prevAppUrl = appUrl; |
| 11811 | if (isDefined(appUrl = beginsWith(basePrefix, appUrl))) { |
| 11812 | rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl); |
| 11813 | } else { |
| 11814 | rewrittenUrl = appBase + prevAppUrl; |
| 11815 | } |
| 11816 | } else if (isDefined(appUrl = beginsWith(appBaseNoFile, url))) { |
| 11817 | rewrittenUrl = appBaseNoFile + appUrl; |
nothing calls this directly
no test coverage detected