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

Side by Side Diff: options.js

Issue 8621090: Replaced chrome.i18n by a platform-independent i18n object in UI (Closed)
Patch Set: Created Oct. 22, 2012, 8:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « i18n.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var backgroundPage = chrome.extension.getBackgroundPage(); 1 var backgroundPage = chrome.extension.getBackgroundPage();
2 var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscr iption", 2 var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscr iption",
3 "DownloadableSubscription", "Filter", "WhitelistFilter", 3 "DownloadableSubscription", "Filter", "WhitelistFilter",
4 "Synchronizer", "Prefs", "Utils", "require"]; 4 "Synchronizer", "Prefs", "Utils", "require"];
5 for (var i = 0; i < imports.length; i++) 5 for (var i = 0; i < imports.length; i++)
6 window[imports[i]] = backgroundPage[imports[i]]; 6 window[imports[i]] = backgroundPage[imports[i]];
7 7
8 // Loads options from localStorage and sets UI elements accordingly 8 // Loads options from localStorage and sets UI elements accordingly
9 function loadOptions() 9 function loadOptions()
10 { 10 {
11 // Set page title to i18n version of "Adblock Plus Options" 11 // Set page title to i18n version of "Adblock Plus Options"
12 document.title = chrome.i18n.getMessage("options"); 12 document.title = i18n.getMessage("options");
13 13
14 // Set links 14 // Set links
15 $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl); 15 $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl);
16 $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/ g, "acceptable_ads").replace(/%LANG%/g, Utils.appLocale)); 16 $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/ g, "acceptable_ads").replace(/%LANG%/g, Utils.appLocale));
17 17
18 // Add event listeners 18 // Add event listeners
19 window.addEventListener("unload", unloadOptions, false); 19 window.addEventListener("unload", unloadOptions, false);
20 $("#updateFilterLists").click(updateFilterLists); 20 $("#updateFilterLists").click(updateFilterLists);
21 $("#startSubscriptionSelection").click(startSubscriptionSelection); 21 $("#startSubscriptionSelection").click(startSubscriptionSelection);
22 $("#subscriptionSelector").change(updateSubscriptionSelection); 22 $("#subscriptionSelector").change(updateSubscriptionSelection);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 { 170 {
171 selectedIndex = i; 171 selectedIndex = i;
172 selectedPrefix = prefix; 172 selectedPrefix = prefix;
173 } 173 }
174 } 174 }
175 } 175 }
176 list.appendChild(option); 176 list.appendChild(option);
177 } 177 }
178 178
179 var option = document.createElement("option"); 179 var option = document.createElement("option");
180 option.text = chrome.i18n.getMessage("filters_addSubscriptionOther_label") + "\u2026"; 180 option.text = i18n.getMessage("filters_addSubscriptionOther_label") + "\u202 6";
181 option._data = null; 181 option._data = null;
182 list.appendChild(option); 182 list.appendChild(option);
183 183
184 list.selectedIndex = selectedIndex; 184 list.selectedIndex = selectedIndex;
185 185
186 if (delayedSubscriptionSelection) 186 if (delayedSubscriptionSelection)
187 startSubscriptionSelection.apply(null, delayedSubscriptionSelection); 187 startSubscriptionSelection.apply(null, delayedSubscriptionSelection);
188 }; 188 };
189 request.send(null); 189 request.send(null);
190 } 190 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 { 229 {
230 var list = document.getElementById("subscriptionSelector"); 230 var list = document.getElementById("subscriptionSelector");
231 var data = list.options[list.selectedIndex]._data; 231 var data = list.options[list.selectedIndex]._data;
232 if (data) 232 if (data)
233 doAddSubscription(data.url, data.title, data.homepage); 233 doAddSubscription(data.url, data.title, data.homepage);
234 else 234 else
235 { 235 {
236 var url = document.getElementById("customSubscriptionLocation").value.replac e(/^\s+/, "").replace(/\s+$/, ""); 236 var url = document.getElementById("customSubscriptionLocation").value.replac e(/^\s+/, "").replace(/\s+$/, "");
237 if (!/^https?:/i.test(url)) 237 if (!/^https?:/i.test(url))
238 { 238 {
239 alert(chrome.i18n.getMessage("global_subscription_invalid_location")); 239 alert(i18n.getMessage("global_subscription_invalid_location"));
240 $("#customSubscriptionLocation").focus(); 240 $("#customSubscriptionLocation").focus();
241 return; 241 return;
242 } 242 }
243 243
244 var title = document.getElementById("customSubscriptionTitle").value.replace (/^\s+/, "").replace(/\s+$/, ""); 244 var title = document.getElementById("customSubscriptionTitle").value.replace (/^\s+/, "").replace(/\s+$/, "");
245 if (!title) 245 if (!title)
246 title = url; 246 title = url;
247 247
248 doAddSubscription(url, title, null); 248 doAddSubscription(url, title, null);
249 } 249 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 title.href = subscription.homepage; 309 title.href = subscription.homepage;
310 else 310 else
311 title.href = subscription.url; 311 title.href = subscription.url;
312 312
313 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 313 var enabled = element.getElementsByClassName("subscriptionEnabled")[0];
314 enabled.checked = !subscription.disabled; 314 enabled.checked = !subscription.disabled;
315 315
316 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; 316 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0];
317 lastUpdate.classList.remove("error"); 317 lastUpdate.classList.remove("error");
318 if (Synchronizer.isExecuting(subscription.url)) 318 if (Synchronizer.isExecuting(subscription.url))
319 lastUpdate.textContent = chrome.i18n.getMessage("filters_subscription_lastDo wnload_inProgress"); 319 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress");
320 else if (subscription.downloadStatus && subscription.downloadStatus != "synchr onize_ok") 320 else if (subscription.downloadStatus && subscription.downloadStatus != "synchr onize_ok")
321 { 321 {
322 var map = 322 var map =
323 { 323 {
324 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL", 324 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL",
325 "synchronize_connection_error": "filters_subscription_lastDownload_connect ionError", 325 "synchronize_connection_error": "filters_subscription_lastDownload_connect ionError",
326 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidData ", 326 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidData ",
327 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_checks umMismatch" 327 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_checks umMismatch"
328 }; 328 };
329 if (subscription.downloadStatus in map) 329 if (subscription.downloadStatus in map)
330 lastUpdate.textContent = chrome.i18n.getMessage(map[subscription.downloadS tatus]); 330 lastUpdate.textContent = i18n.getMessage(map[subscription.downloadStatus]) ;
331 else 331 else
332 lastUpdate.textContent = subscription.downloadStatus; 332 lastUpdate.textContent = subscription.downloadStatus;
333 lastUpdate.classList.add("error"); 333 lastUpdate.classList.add("error");
334 } 334 }
335 else if (subscription.lastDownload > 0) 335 else if (subscription.lastDownload > 0)
336 { 336 {
337 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); 337 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000);
338 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); 338 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today");
339 lastUpdate.textContent = chrome.i18n.getMessage(messageID, timeDate); 339 lastUpdate.textContent = i18n.getMessage(messageID, timeDate);
340 } 340 }
341 } 341 }
342 342
343 function onFilterChange(action, item, param1, param2) 343 function onFilterChange(action, item, param1, param2)
344 { 344 {
345 switch (action) 345 switch (action)
346 { 346 {
347 case "load": 347 case "load":
348 reloadFilters(); 348 reloadFilters();
349 break; 349 break;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 var template = document.getElementById("subscriptionTemplate"); 558 var template = document.getElementById("subscriptionTemplate");
559 var element = template.cloneNode(true); 559 var element = template.cloneNode(true);
560 element.removeAttribute("id"); 560 element.removeAttribute("id");
561 element._subscription = subscription; 561 element._subscription = subscription;
562 562
563 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0]; 563 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0];
564 removeButton.setAttribute("title", removeButton.textContent); 564 removeButton.setAttribute("title", removeButton.textContent);
565 removeButton.textContent = "\xD7"; 565 removeButton.textContent = "\xD7";
566 removeButton.addEventListener("click", function() 566 removeButton.addEventListener("click", function()
567 { 567 {
568 if (!confirm(chrome.i18n.getMessage("global_remove_subscription_warning"))) 568 if (!confirm(i18n.getMessage("global_remove_subscription_warning")))
569 return; 569 return;
570 570
571 FilterStorage.removeSubscription(subscription); 571 FilterStorage.removeSubscription(subscription);
572 }, false); 572 }, false);
573 573
574 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 574 var enabled = element.getElementsByClassName("subscriptionEnabled")[0];
575 enabled.addEventListener("click", function() 575 enabled.addEventListener("click", function()
576 { 576 {
577 if (subscription.disabled == !enabled.checked) 577 if (subscription.disabled == !enabled.checked)
578 return; 578 return;
579 579
580 subscription.disabled = !enabled.checked; 580 subscription.disabled = !enabled.checked;
581 }, false); 581 }, false);
582 582
583 updateSubscriptionInfo(element); 583 updateSubscriptionInfo(element);
584 584
585 document.getElementById("filterLists").appendChild(element); 585 document.getElementById("filterLists").appendChild(element);
586 } 586 }
OLDNEW
« no previous file with comments | « i18n.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld