MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / LocationHtml5Url

Function LocationHtml5Url

test/fixtures/foo.js:9233–9289  ·  view source on GitHub ↗

* 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} basePrefix url path prefix

(appBase, basePrefix)

Source from the content-addressed store, hash-verified

9231 * @param {string} basePrefix url path prefix
9232 */
9233function LocationHtml5Url(appBase, basePrefix) {
9234 this.$$html5 = true;
9235 basePrefix = basePrefix || '';
9236 var appBaseNoFile = stripFile(appBase);
9237 parseAbsoluteUrl(appBase, this, appBase);
9238
9239
9240 /**
9241 * Parse given html5 (regular) url string into properties
9242 * @param {string} newAbsoluteUrl HTML5 url
9243 * @private
9244 */
9245 this.$$parse = function(url) {
9246 var pathUrl = beginsWith(appBaseNoFile, url);
9247 if (!isString(pathUrl)) {
9248 throw $locationMinErr('ipthprfx', 'Invalid url "{0}", missing path prefix "{1}".', url,
9249 appBaseNoFile);
9250 }
9251
9252 parseAppUrl(pathUrl, this, appBase);
9253
9254 if (!this.$$path) {
9255 this.$$path = '/';
9256 }
9257
9258 this.$$compose();
9259 };
9260
9261 /**
9262 * Compose url and update `absUrl` property
9263 * @private
9264 */
9265 this.$$compose = function() {
9266 var search = toKeyValue(this.$$search),
9267 hash = this.$$hash ? '#' + encodeUriSegment(this.$$hash) : '';
9268
9269 this.$$url = encodePath(this.$$path) + (search ? '?' + search : '') + hash;
9270 this.$$absUrl = appBaseNoFile + this.$$url.substr(1); // first char is always '/'
9271 };
9272
9273 this.$$rewrite = function(url) {
9274 var appUrl, prevAppUrl;
9275
9276 if ( (appUrl = beginsWith(appBase, url)) !== undefined ) {
9277 prevAppUrl = appUrl;
9278 if ( (appUrl = beginsWith(basePrefix, appUrl)) !== undefined ) {
9279 return appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
9280 } else {
9281 return appBase + prevAppUrl;
9282 }
9283 } else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) {
9284 return appBaseNoFile + appUrl;
9285 } else if (appBaseNoFile == url + '/') {
9286 return appBaseNoFile;
9287 }
9288 };
9289}
9290

Callers

nothing calls this directly

Calls 8

stripFileFunction · 0.85
parseAbsoluteUrlFunction · 0.85
beginsWithFunction · 0.85
isStringFunction · 0.85
parseAppUrlFunction · 0.85
toKeyValueFunction · 0.85
encodeUriSegmentFunction · 0.85
encodePathFunction · 0.85

Tested by

no test coverage detected