- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / examples / api / topsites / basic / popup.js
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Event listener for clicks on links in a browser action popup.
6 // Open the link in a new tab of the current window.
7 function onAnchorClick(event) {
8   chrome.tabs.create({ url: event.srcElement.href });
9   return false;
10 }
11
12 // Given an array of URLs, build a DOM list of these URLs in the
13 // browser action popup.
14 function buildPopupDom(mostVisitedURLs) {
15   var popupDiv = document.getElementById('mostVisited_div');
16   var ol = popupDiv.appendChild(document.createElement('ol'));
17
18   for (var i = 0; i < mostVisitedURLs.length; i++) {
19     var li = ol.appendChild(document.createElement('li'));
20     var a = li.appendChild(document.createElement('a'));
21     a.href = mostVisitedURLs[i].url;
22     a.appendChild(document.createTextNode(mostVisitedURLs[i].title));
23     a.addEventListener('click', onAnchorClick);
24   }
25 }
26
27 chrome.topSites.get(buildPopupDom);