|
| 1 | +// from https://gist.github.com/Yaffle/1088850 |
| 2 | +(function(global) { |
| 3 | +function URLPolyfill(url, baseURL) { |
| 4 | + if (typeof url != 'string') |
| 5 | + throw new TypeError('URL must be a string'); |
| 6 | + var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); |
| 7 | + if (!m) { |
| 8 | + throw new RangeError(); |
| 9 | + } |
| 10 | + var protocol = m[1] || ""; |
| 11 | + var username = m[2] || ""; |
| 12 | + var password = m[3] || ""; |
| 13 | + var host = m[4] || ""; |
| 14 | + var hostname = m[5] || ""; |
| 15 | + var port = m[6] || ""; |
| 16 | + var pathname = m[7] || ""; |
| 17 | + var search = m[8] || ""; |
| 18 | + var hash = m[9] || ""; |
| 19 | + if (baseURL !== undefined) { |
| 20 | + var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL); |
| 21 | + var flag = protocol === "" && host === "" && username === ""; |
| 22 | + if (flag && pathname === "" && search === "") { |
| 23 | + search = base.search; |
| 24 | + } |
| 25 | + if (flag && pathname.charAt(0) !== "/") { |
| 26 | + pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname); |
| 27 | + } |
| 28 | + // dot segments removal |
| 29 | + var output = []; |
| 30 | + pathname.replace(/^(\.\.?(\/|$))+/, "") |
| 31 | + .replace(/\/(\.(\/|$))+/g, "/") |
| 32 | + .replace(/\/\.\.$/, "/../") |
| 33 | + .replace(/\/?[^\/]*/g, function (p) { |
| 34 | + if (p === "/..") { |
| 35 | + output.pop(); |
| 36 | + } else { |
| 37 | + output.push(p); |
| 38 | + } |
| 39 | + }); |
| 40 | + pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : ""); |
| 41 | + if (flag) { |
| 42 | + port = base.port; |
| 43 | + hostname = base.hostname; |
| 44 | + host = base.host; |
| 45 | + password = base.password; |
| 46 | + username = base.username; |
| 47 | + } |
| 48 | + if (protocol === "") { |
| 49 | + protocol = base.protocol; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + // convert windows file URLs to use / |
| 54 | + if (protocol == 'file:') |
| 55 | + pathname = pathname.replace(/\\/g, '/'); |
| 56 | + |
| 57 | + this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host; |
| 58 | + this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash; |
| 59 | + this.protocol = protocol; |
| 60 | + this.username = username; |
| 61 | + this.password = password; |
| 62 | + this.host = host; |
| 63 | + this.hostname = hostname; |
| 64 | + this.port = port; |
| 65 | + this.pathname = pathname; |
| 66 | + this.search = search; |
| 67 | + this.hash = hash; |
| 68 | +} |
| 69 | +global.URLPolyfill = URLPolyfill; |
| 70 | +})(typeof self != 'undefined' ? self : global); |
1 | 71 | (function(__global) { |
2 | 72 |
|
3 | 73 | var isWorker = typeof window == 'undefined' && typeof self != 'undefined' && typeof importScripts != 'undefined'; |
|
89 | 159 | throw new TypeError('No environment baseURI'); |
90 | 160 | } |
91 | 161 |
|
92 | | - var URL = __global.URL; |
93 | | - try { |
94 | | - new URL('test:///').protocol == 'test:'; |
95 | | - } |
96 | | - catch(e) { |
97 | | - URL = URLPolyfill; |
98 | | - } |
| 162 | + var URL = __global.URLPolyfill || __global.URL; |
99 | 163 |
|
100 | 164 | /* |
101 | 165 | ********************************************************************************************* |
@@ -908,74 +972,6 @@ function logloads(loads) { |
908 | 972 | throw new TypeError('ES6 transpilation is only provided in the dev module loader build.'); |
909 | 973 | } |
910 | 974 | })(); |
911 | | -// from https://gist.github.com/Yaffle/1088850 |
912 | | -function URLPolyfill(url, baseURL) { |
913 | | - if (typeof url != 'string') |
914 | | - throw new TypeError('URL must be a string'); |
915 | | - var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); |
916 | | - if (!m) { |
917 | | - throw new RangeError(); |
918 | | - } |
919 | | - var protocol = m[1] || ""; |
920 | | - var username = m[2] || ""; |
921 | | - var password = m[3] || ""; |
922 | | - var host = m[4] || ""; |
923 | | - var hostname = m[5] || ""; |
924 | | - var port = m[6] || ""; |
925 | | - var pathname = m[7] || ""; |
926 | | - var search = m[8] || ""; |
927 | | - var hash = m[9] || ""; |
928 | | - if (baseURL !== undefined) { |
929 | | - var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL); |
930 | | - var flag = protocol === "" && host === "" && username === ""; |
931 | | - if (flag && pathname === "" && search === "") { |
932 | | - search = base.search; |
933 | | - } |
934 | | - if (flag && pathname.charAt(0) !== "/") { |
935 | | - pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname); |
936 | | - } |
937 | | - // dot segments removal |
938 | | - var output = []; |
939 | | - pathname.replace(/^(\.\.?(\/|$))+/, "") |
940 | | - .replace(/\/(\.(\/|$))+/g, "/") |
941 | | - .replace(/\/\.\.$/, "/../") |
942 | | - .replace(/\/?[^\/]*/g, function (p) { |
943 | | - if (p === "/..") { |
944 | | - output.pop(); |
945 | | - } else { |
946 | | - output.push(p); |
947 | | - } |
948 | | - }); |
949 | | - pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : ""); |
950 | | - if (flag) { |
951 | | - port = base.port; |
952 | | - hostname = base.hostname; |
953 | | - host = base.host; |
954 | | - password = base.password; |
955 | | - username = base.username; |
956 | | - } |
957 | | - if (protocol === "") { |
958 | | - protocol = base.protocol; |
959 | | - } |
960 | | - } |
961 | | - |
962 | | - // convert windows file URLs to use / |
963 | | - if (protocol == 'file:') |
964 | | - pathname = pathname.replace(/\\/g, '/'); |
965 | | - |
966 | | - this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host; |
967 | | - this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash; |
968 | | - this.protocol = protocol; |
969 | | - this.username = username; |
970 | | - this.password = password; |
971 | | - this.host = host; |
972 | | - this.hostname = hostname; |
973 | | - this.port = port; |
974 | | - this.pathname = pathname; |
975 | | - this.search = search; |
976 | | - this.hash = hash; |
977 | | -} |
978 | | -(typeof self != 'undefined' ? self : global).URLPolyfill = URLPolyfill; |
979 | 975 | /* |
980 | 976 | ********************************************************************************************* |
981 | 977 |
|
|
0 commit comments