| 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);
|
|
|