- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / examples / extensions / fx / options.js
1 // Copyright (c) 2012 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 function playSound(id) {
6   console.log(id);
7   chrome.extension.getBackgroundPage().playSound(id, false);
8 }
9
10 function stopSound(id) {
11   chrome.extension.getBackgroundPage().stopSound(id);
12 }
13
14 function soundChanged(event) {
15   var key = event.target.name;
16   var checked = event.target.checked;
17   if (checked) {
18     localStorage.setItem(key, "enabled");
19     playSound(event.target.name);
20   } else {
21     localStorage.setItem(key, "disabled");
22     stopSound(event.target.name);
23   }
24 }
25
26 function showSounds() {
27   var sounds = document.getElementById("sounds");
28   if (!localStorage.length) {
29     sounds.innerText = "";
30     return;
31   }
32   sounds.innerText = "Discovered sounds: (uncheck to disable)";
33   var keys = new Array();
34   for (var key in localStorage) {
35     keys.push(key);
36     console.log(key);
37   }
38   keys.sort();
39   for (var index in keys) {
40     var key = keys[index];
41     var div = document.createElement("div");
42     var check = document.createElement("input");
43     check.type = "checkbox"
44     check.name = key;
45     check.checked = localStorage[key] == "enabled";
46     check.onchange = soundChanged;
47     div.appendChild(check);
48     var text = document.createElement("span");
49     text.id = key;
50     text.innerText = key;
51     text.className = "sound";
52     text.onclick = function(event) { playSound(event.target.id); };
53     div.appendChild(text);
54     sounds.appendChild(div);
55   }
56 }
57
58 document.addEventListener('DOMContentLoaded', showSounds);
59 document.addEventListener('focus', showSounds);