* Prepares a parts of the current or specified reference for later use in the library * * @param {string} [href] * @param {boolean} [isWindowLocation] * @param {boolean} [isNotAPI] * @return {Object}
(href, isWindowLocation, isNotAPI)
| 415 | * @return {Object} |
| 416 | */ |
| 417 | function parseURL(href, isWindowLocation, isNotAPI) { |
| 418 | var re = /(?:([a-zA-Z0-9\-]+\:))?(?:\/\/(?:[^@]*@)?([^\/:\?#]+)(?::([0-9]+))?)?([^\?#]*)(?:(\?[^#]+)|\?)?(?:(#.*))?/; |
| 419 | if (href != null && href !== '' && !isWindowLocation) { |
| 420 | var current = parseURL(), |
| 421 | base = document.getElementsByTagName('base')[0]; |
| 422 | if (!isNotAPI && base && base.getAttribute('href')) { |
| 423 | // Fix for IE ignoring relative base tags. |
| 424 | // See http://stackoverflow.com/questions/3926197/html-base-tag-and-local-folder-path-with-internet-explorer |
| 425 | base.href = base.href; |
| 426 | current = parseURL(base.href, null, true); |
| 427 | } |
| 428 | var _pathname = current._pathname, _protocol = current._protocol; |
| 429 | // convert to type of string |
| 430 | href = '' + href; |
| 431 | // convert relative link to the absolute |
| 432 | href = /^(?:\w+\:)?\/\//.test(href) ? href.indexOf("/") === 0 |
| 433 | ? _protocol + href : href : _protocol + "//" + current._host + ( |
| 434 | href.indexOf("/") === 0 ? href : href.indexOf("?") === 0 |
| 435 | ? _pathname + href : href.indexOf("#") === 0 |
| 436 | ? _pathname + current._search + href : _pathname.replace(/[^\/]+$/g, '') + href |
| 437 | ); |
| 438 | } else { |
| 439 | href = isWindowLocation ? href : windowLocation.href; |
| 440 | // if current browser not support History-API |
| 441 | if (!isSupportHistoryAPI || isNotAPI) { |
| 442 | // get hash fragment |
| 443 | href = href.replace(/^[^#]*/, '') || "#"; |
| 444 | // form the absolute link from the hash |
| 445 | // https://github.com/devote/HTML5-History-API/issues/50 |
| 446 | href = windowLocation.protocol.replace(/:.*$|$/, ':') + '//' + windowLocation.host + settings['basepath'] |
| 447 | + href.replace(new RegExp("^#[\/]?(?:" + settings["type"] + ")?"), ""); |
| 448 | } |
| 449 | } |
| 450 | // that would get rid of the links of the form: /../../ |
| 451 | anchorElement.href = href; |
| 452 | // decompose the link in parts |
| 453 | var result = re.exec(anchorElement.href); |
| 454 | // host name with the port number |
| 455 | var host = result[2] + (result[3] ? ':' + result[3] : ''); |
| 456 | // folder |
| 457 | var pathname = result[4] || '/'; |
| 458 | // the query string |
| 459 | var search = result[5] || ''; |
| 460 | // hash |
| 461 | var hash = result[6] === '#' ? '' : (result[6] || ''); |
| 462 | // relative link, no protocol, no host |
| 463 | var relative = pathname + search + hash; |
| 464 | // special links for set to hash-link, if browser not support History API |
| 465 | var nohash = pathname.replace(new RegExp("^" + settings["basepath"], "i"), settings["type"]) + search; |
| 466 | // result |
| 467 | return { |
| 468 | _href: result[1] + '//' + host + relative, |
| 469 | _protocol: result[1], |
| 470 | _host: host, |
| 471 | _hostname: result[2], |
| 472 | _port: result[3] || '', |
| 473 | _pathname: pathname, |
| 474 | _search: search, |
no outgoing calls
no test coverage detected