Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1021 bytes
|
Line | |
---|
1 | // Copyright 2014 Simon Lydell
|
---|
2 | // X11 (“MIT”) Licensed. (See LICENSE.)
|
---|
3 |
|
---|
4 | void (function(root, factory) {
|
---|
5 | if (typeof define === "function" && define.amd) {
|
---|
6 | define(factory)
|
---|
7 | } else if (typeof exports === "object") {
|
---|
8 | module.exports = factory()
|
---|
9 | } else {
|
---|
10 | root.resolveUrl = factory()
|
---|
11 | }
|
---|
12 | }(this, function() {
|
---|
13 |
|
---|
14 | function resolveUrl(/* ...urls */) {
|
---|
15 | var numUrls = arguments.length
|
---|
16 |
|
---|
17 | if (numUrls === 0) {
|
---|
18 | throw new Error("resolveUrl requires at least one argument; got none.")
|
---|
19 | }
|
---|
20 |
|
---|
21 | var base = document.createElement("base")
|
---|
22 | base.href = arguments[0]
|
---|
23 |
|
---|
24 | if (numUrls === 1) {
|
---|
25 | return base.href
|
---|
26 | }
|
---|
27 |
|
---|
28 | var head = document.getElementsByTagName("head")[0]
|
---|
29 | head.insertBefore(base, head.firstChild)
|
---|
30 |
|
---|
31 | var a = document.createElement("a")
|
---|
32 | var resolved
|
---|
33 |
|
---|
34 | for (var index = 1; index < numUrls; index++) {
|
---|
35 | a.href = arguments[index]
|
---|
36 | resolved = a.href
|
---|
37 | base.href = resolved
|
---|
38 | }
|
---|
39 |
|
---|
40 | head.removeChild(base)
|
---|
41 |
|
---|
42 | return resolved
|
---|
43 | }
|
---|
44 |
|
---|
45 | return resolveUrl
|
---|
46 |
|
---|
47 | }));
|
---|
Note:
See
TracBrowser
for help on using the repository browser.