Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/polyfills/url.js

Issue 29333522: Issue 3515 - Adapted polyfill for URL class for consistency (Closed)
Left Patch Set: Created Jan. 14, 2016, 5:22 p.m.
Right Patch Set: Rebased and addressed comments Created Jan. 19, 2016, 2:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/url.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 (function(global)
21 {
22 var URLProperties = ["href", "protocol", "hostname",
23 "host", "pathname", "search"];
24
25 // Chrome <35 and Safari 6 used the non-standard name webkitURL
26 var URL = global.URL || global.webkitURL;
27
28 // Chrome <32 didn't implement any of those properties
29 function hasProperties()
30 {
31 var dummy = new URL("about:blank");
32 for (var i = 0; i < URLProperties.length; i++)
33 if (!(URLProperties[i] in dummy))
34 return false;
35 return true;
36 }
37
38 if (!URL || !hasProperties())
39 {
40 var doc = document.implementation.createHTMLDocument();
41
42 var base = doc.createElement("base");
43 doc.head.appendChild(base);
44
45 var anchor = doc.createElement("a");
46 doc.body.appendChild(anchor);
47
48 URL = function(url, baseUrl)
49 {
50 if (baseUrl instanceof URL)
51 base.href = baseUrl.href;
52 else
53 base.href = baseUrl || "";
54 anchor.href = url;
55
56 for (var i = 0; i < URLProperties.length; i++)
57 {
58 var prop = URLProperties[i];
59 this[prop] = anchor[prop];
60 }
61 };
62 }
63
64 global.URL = URL;
65 })(this);
LEFTRIGHT
« no previous file | lib/url.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld