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

Unified Diff: options.js

Issue 29333544: Issue 3515 - Use fetch() API instead XMLHttpRequest (UI) (Closed)
Patch Set: Created Jan. 14, 2016, 5:35 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -312,42 +312,44 @@
function loadRecommendations()
{
- var request = new XMLHttpRequest();
- request.open("GET", "subscriptions.xml", false);
- request.addEventListener("load", function()
- {
- var list = document.getElementById("subscriptionSelector");
- var docElem = request.responseXML.documentElement;
- var elements = docElem.getElementsByTagName("subscription");
- for (var i = 0; i < elements.length; i++)
+ fetch("subscriptions.xml")
+ .then(function(response)
{
- var element = elements[i];
- var subscription = Object.create(null);
- subscription.title = element.getAttribute("title");
- subscription.url = element.getAttribute("url");
- subscription.disabled = null;
- subscription.downloadStatus = null;
- subscription.homepage = null;
- subscription.lastSuccess = null;
- var recommendation = Object.create(null);
- recommendation.type = element.getAttribute("type");
- var prefix = element.getAttribute("prefixes");
- if (prefix)
+ return response.text();
+ })
+ .then(function(text)
+ {
+ var list = document.getElementById("subscriptionSelector");
+ var doc = new DOMParser().parseFromString(text, "application/xml");
+ var elements = doc.documentElement.getElementsByTagName("subscription");
+ for (var i = 0; i < elements.length; i++)
{
- prefix = prefix.replace(/\W/g, "_");
- subscription.title = ext.i18n.getMessage("options_language_" + prefix);
+ var element = elements[i];
+ var subscription = Object.create(null);
+ subscription.title = element.getAttribute("title");
+ subscription.url = element.getAttribute("url");
+ subscription.disabled = null;
+ subscription.downloadStatus = null;
+ subscription.homepage = null;
+ subscription.lastSuccess = null;
+ var recommendation = Object.create(null);
+ recommendation.type = element.getAttribute("type");
+ var prefix = element.getAttribute("prefixes");
+ if (prefix)
+ {
+ prefix = prefix.replace(/\W/g, "_");
+ subscription.title = ext.i18n.getMessage("options_language_" + prefix);
+ }
+ else
+ {
+ var type = recommendation.type.replace(/\W/g, "_");
+ subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title");
+ }
+
+ recommendationsMap[subscription.url] = recommendation;
+ updateSubscription(subscription);
}
- else
- {
- var type = recommendation.type.replace(/\W/g, "_");
- subscription.title = ext.i18n.getMessage("common_feature_" + type + "_title");
- }
-
- recommendationsMap[subscription.url] = recommendation;
- updateSubscription(subscription);
- }
- }, false);
- request.send(null);
+ });
}
function onClick(e)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld