Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5378)

Unified Diff: chrome/common/extensions/docs/examples/api/topsites/basic/popup.js

Issue 25389003: [DocServer] Updated Top Sites Sample Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added new icon Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/examples/api/topsites/basic/popup.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/examples/api/topsites/basic/popup.js
diff --git a/chrome/common/extensions/docs/examples/api/topsites/basic/popup.js b/chrome/common/extensions/docs/examples/api/topsites/basic/popup.js
new file mode 100644
index 0000000000000000000000000000000000000000..bb95ea1396bb370c5b87debc91c8f9b888615aac
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/topsites/basic/popup.js
@@ -0,0 +1,27 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Event listener for clicks on links in a browser action popup.
+// Open the link in a new tab of the current window.
+function onAnchorClick(event) {
+ chrome.tabs.create({ url: event.srcElement.href });
+ return false;
+}
+
+// Given an array of URLs, build a DOM list of these URLs in the
+// browser action popup.
+function buildPopupDom(mostVisitedURLs) {
+ var popupDiv = document.getElementById('mostVisited_div');
+ var ol = popupDiv.appendChild(document.createElement('ol'));
+
+ for (var i = 0; i < mostVisitedURLs.length; i++) {
+ var li = ol.appendChild(document.createElement('li'));
+ var a = li.appendChild(document.createElement('a'));
+ a.href = mostVisitedURLs[i].url;
+ a.appendChild(document.createTextNode(mostVisitedURLs[i].title));
+ a.addEventListener('click', onAnchorClick);
+ }
+}
+
+chrome.topSites.get(buildPopupDom);
« no previous file with comments | « chrome/common/extensions/docs/examples/api/topsites/basic/popup.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698