mouseWheelVolume.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
27 //
28 // Mouse Wheel Support
29 //
30 
31 try
32 {
33 
34  // Module specific global for auto-init/deinit support
35  var mousewheel_volume = {};
36  mousewheel_volume.init_once = 0;
37  mousewheel_volume.deinit_once = 0;
38  mousewheel_volume.onLoad = function()
39  {
40  if (mousewheel_volume.init_once++) { dump("WARNING: mousewheel_volume double init!!\n"); return; }
41  window.addEventListener("DOMMouseScroll", mousewheel_volume.onDOMMouseScroll, false);
42  }
43  mousewheel_volume.onUnload = function()
44  {
45  if (mousewheel_volume.deinit_once++) { dump("WARNING: mousewheel_volume double deinit!!\n"); return; }
46  window.removeEventListener("DOMMouseScroll", mousewheel_volume.onDOMMouseScroll, false);
47  window.removeEventListener("load", mousewheel_volume.onLoad, false);
48  window.removeEventListener("unload", mousewheel_volume.onUnload, false);
49  }
50 
51  // Auto-init/deinit registration
52  window.addEventListener("load", mousewheel_volume.onLoad, false);
53  window.addEventListener("unload", mousewheel_volume.onUnload, false);
54 
55  // Functionality
56  mousewheel_volume.onDOMMouseScroll = function(evt)
57  {
58  try
59  {
60  var node = evt.originalTarget;
61  while (node != document && node != null)
62  {
63  // if your object implements an event on the wheel,
64  // but is not one of these, you should either give
65  // it an attribute of wheelvolume="false" or
66  // prevent the event from bubbling altogether
67  if (node.tagName == "tree") return;
68  if (node.tagName == "xul:tree") return;
69  if (node.tagName == "listbox") return;
70  if (node.tagName == "xul:listbox") return;
71  if (node.tagName == "browser") return;
72  if (node.tagName == "xul:browser") return;
73 
74  if (node.getAttribute &&
75  node.getAttribute("wheelvolume") == "false")
76  return;
77  node = node.parentNode;
78  }
79 
80  if (node == null)
81  {
82  // could not walk up to the window before hitting a document,
83  // we're inside a sub document. the evt will continue bubbling,
84  // and we'll catch it on the next pass
85  return;
86  }
87 
88  var mm =
89  Components.classes["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
90  .getService(Components.interfaces.sbIMediacoreManager);
91 
92  // walked up to the window
93  var curVol = mm.volumeControl.volume;
94  var v = curVol + ((evt.detail > 0) ? -0.03 : 0.03);
95  if (v < 0) v = 0;
96  if (v > 1) v = 1;
97  mm.volumeControl.volume = v;
98  if (v != 0) SBDataSetStringValue("faceplate.volume.last", v);
99  }
100  catch (err)
101  {
102  dump("onMouseWheelVolume - " + err);
103  }
104  }
105 }
106 catch (err)
107 {
108  dump("mouseWheelVolume.js - " + err);
109 }
110 
111 
let window
return null
Definition: FeedWriter.js:1143
let node
function SBDataSetStringValue(aKey, aStringValue)
Set a string value. Changes the value of the data remote to the boolean passed in, regardless of its value before.