MCPcopy
hub / github.com/angular-ui/ui-router / LocationHashbangUrl

Function LocationHashbangUrl

test/angular/1.3/angular.js:10740–10839  ·  view source on GitHub ↗

* LocationHashbangUrl represents url * This object is exposed as $location service when developer doesn't opt into html5 mode. * It also serves as the base class for html5 mode fallback on legacy browsers. * * @constructor * @param {string} appBase application base URL * @param {string} appBas

(appBase, appBaseNoFile, hashPrefix)

Source from the content-addressed store, hash-verified

10738 * @param {string} hashPrefix hashbang prefix
10739 */
10740function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
10741
10742 parseAbsoluteUrl(appBase, this);
10743
10744
10745 /**
10746 * Parse given hashbang url into properties
10747 * @param {string} url Hashbang url
10748 * @private
10749 */
10750 this.$$parse = function(url) {
10751 var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url);
10752 var withoutHashUrl;
10753
10754 if (!isUndefined(withoutBaseUrl) && withoutBaseUrl.charAt(0) === '#') {
10755
10756 // The rest of the url starts with a hash so we have
10757 // got either a hashbang path or a plain hash fragment
10758 withoutHashUrl = beginsWith(hashPrefix, withoutBaseUrl);
10759 if (isUndefined(withoutHashUrl)) {
10760 // There was no hashbang prefix so we just have a hash fragment
10761 withoutHashUrl = withoutBaseUrl;
10762 }
10763
10764 } else {
10765 // There was no hashbang path nor hash fragment:
10766 // If we are in HTML5 mode we use what is left as the path;
10767 // Otherwise we ignore what is left
10768 if (this.$$html5) {
10769 withoutHashUrl = withoutBaseUrl;
10770 } else {
10771 withoutHashUrl = '';
10772 if (isUndefined(withoutBaseUrl)) {
10773 appBase = url;
10774 this.replace();
10775 }
10776 }
10777 }
10778
10779 parseAppUrl(withoutHashUrl, this);
10780
10781 this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase);
10782
10783 this.$$compose();
10784
10785 /*
10786 * In Windows, on an anchor node on documents loaded from
10787 * the filesystem, the browser will return a pathname
10788 * prefixed with the drive name ('/C:/path') when a
10789 * pathname without a drive is set:
10790 * * a.setAttribute('href', '/foo')
10791 * * a.pathname === '/C:/foo' //true
10792 *
10793 * Inside of Angular, we're always using pathnames that
10794 * do not include drive names for routing.
10795 */
10796 function removeWindowsDriveName(path, url, base) {
10797 /*

Callers

nothing calls this directly

Calls 9

parseAbsoluteUrlFunction · 0.70
beginsWithFunction · 0.70
isUndefinedFunction · 0.70
parseAppUrlFunction · 0.70
removeWindowsDriveNameFunction · 0.70
toKeyValueFunction · 0.70
encodeUriSegmentFunction · 0.70
encodePathFunction · 0.70
stripHashFunction · 0.70

Tested by

no test coverage detected