wizardService.js
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27  */
28 
34 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 //
37 // Songbird wizard widget services.
38 //
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------------------
41 
42 //------------------------------------------------------------------------------
43 //
44 // Songbird wizard widget imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Songbird imports.
49 Components.utils.import("resource://app/jsmodules/DOMUtils.jsm");
50 
51 
52 //------------------------------------------------------------------------------
53 //
54 // Songbird wizard widget services defs.
55 //
56 //------------------------------------------------------------------------------
57 
58 // Component manager defs.
59 if (typeof(Cc) == "undefined")
60  var Cc = Components.classes;
61 if (typeof(Ci) == "undefined")
62  var Ci = Components.interfaces;
63 if (typeof(Cr) == "undefined")
64  var Cr = Components.results;
65 if (typeof(Cu) == "undefined")
66  var Cu = Components.utils;
67 
68 
69 //------------------------------------------------------------------------------
70 //------------------------------------------------------------------------------
71 //
72 // Songbird wizard widget services.
73 //
74 //------------------------------------------------------------------------------
75 //------------------------------------------------------------------------------
76 
84 function sbWizardSvc(aWidget) {
85  this._widget = aWidget;
86 }
87 
88 // Define the object.
89 sbWizardSvc.prototype = {
90  // Set the constructor.
92 
93  //
94  // Internal widget services fields.
95  //
96  // _widget Songbird wizard page widget.
97  // _domEventListenerSet Set of DOM event listeners.
98  //
99 
100  _widget: null,
101  _domEventListenerSet: null,
102 
103 
104  //----------------------------------------------------------------------------
105  //
106  // Widget services.
107  //
108  //----------------------------------------------------------------------------
109 
114  initialize: function sbWizardSvc_initialize() {
115  var _this = this;
116  var func;
117 
118  // Create a DOM event listener set.
119  this._domEventListenerSet = new DOMEventListenerSet();
120 
121  // Listen for wizard events.
122  func = function(aEvent) { return _this._doKeyPress(aEvent); };
123  this._domEventListenerSet.add(this._widget, "keypress", func, false);
124  func = function(aEvent) { return _this._doFinish(aEvent); };
125  this._domEventListenerSet.add(this._widget, "wizardfinish", func, false);
126  },
127 
128 
133  finalize: function sbWizardSvc_finalize() {
134  // Remove DOM event listeners.
135  if (this._domEventListenerSet) {
136  this._domEventListenerSet.removeAll();
137  }
138  this._domEventListenerSet = null;
139 
140  // Clear object fields.
141  this._widget = null;
142  },
143 
144 
145  //----------------------------------------------------------------------------
146  //
147  // Widget event handling services.
148  //
149  //----------------------------------------------------------------------------
150 
157  _doKeyPress: function sbWizardSvc__doKeyPress(aEvent) {
158  // Get the pressed key code.
159  var keyCode = aEvent.keyCode;
160 
161  // Get the current page.
162  var currentPage = this._widget.currentPage;
163 
164  // If the cancel button is disabled or hidden, block the escape key.
165  if (keyCode == Ci.nsIDOMKeyEvent.DOM_VK_ESCAPE) {
166  var cancelButton = this._widget.getButton("cancel");
167  var hideWizardButton =
168  cancelButton.getAttribute("hidewizardbutton") == "true";
169  if (cancelButton.disabled || cancelButton.hidden || hideWizardButton) {
170  aEvent.stopPropagation();
171  aEvent.preventDefault();
172  }
173  }
174 
175  // If the next and finished buttons are disabled or hidden, block the enter
176  // and return keys.
177  if ((keyCode == Ci.nsIDOMKeyEvent.DOM_VK_ENTER) ||
178  (keyCode == Ci.nsIDOMKeyEvent.DOM_VK_RETURN)) {
179  var nextButton = this._widget.getButton("next");
180  var hideNextButton =
181  nextButton.getAttribute("hidewizardbutton") == "true";
182  var finishButton = this._widget.getButton("finish");
183  var hideFinishButton =
184  finishButton.getAttribute("hidewizardbutton") == "true";
185  if ((nextButton.disabled || nextButton.hidden || hideNextButton) &&
186  (finishButton.disabled || finishButton.hidden || hideFinishButton)) {
187  aEvent.stopPropagation();
188  aEvent.preventDefault();
189  }
190  }
191  },
192 
193 
200  _doFinish: function sbWizardSvc__doFinish(aEvent) {
201  // Advance to post-finish pages if specified. Return false to prevent
202  // finish.
203  var currentPage = this._widget.currentPage;
204  if (currentPage.hasAttribute("postfinish")) {
205  // Indicate post-finish state before switching pages.
206  this._widget._postFinish = true;
207 
208  // Switch to post-finish pages.
209  var postFinishPageID = currentPage.getAttribute("postfinish");
210  this._widget.goTo(postFinishPageID);
211 
212  // Cancel finish.
213  aEvent.preventDefault();
214  return false;
215  }
216 
217  return true;
218  }
219 }
220 
221 
222 //------------------------------------------------------------------------------
223 //------------------------------------------------------------------------------
224 //
225 // Songbird wizard page widget services.
226 //
227 //------------------------------------------------------------------------------
228 //------------------------------------------------------------------------------
229 
237 function sbWizardPageSvc(aWidget) {
238  this._widget = aWidget;
239 }
240 
241 // Define the object.
242 sbWizardPageSvc.prototype = {
243  // Set the constructor.
244  constructor: sbWizardPageSvc,
245 
246  //
247  // Internal widget services fields.
248  //
249  // _widget Songbird wizard page widget.
250  // _domEventListenerSet Set of DOM event listeners.
251  // _wizardElem Wizard page wizard element.
252  //
253 
254  _widget: null,
255  _domEventListenerSet: null,
256  _wizardElem: null,
257 
258 
259  //----------------------------------------------------------------------------
260  //
261  // Widget services.
262  //
263  //----------------------------------------------------------------------------
264 
269  initialize: function sbWizardPageSvc_initialize() {
270  var _this = this;
271  var func;
272 
273  // Create a DOM event listener set.
274  this._domEventListenerSet = new DOMEventListenerSet();
275 
276  // Get the parent wizard page element.
277  this._wizardElem = this._widget.parentNode;
278 
279  // Listen for page show events.
280  func = function() { return _this._doPageShow(); };
281  this._domEventListenerSet.add(this._widget, "pageshow", func, false);
282 
283  // Listen for button related attribute modified events.
284  func = function(aEvent) { return _this._doButtonDOMAttrModified(aEvent); };
285  var buttonAttributesElem = this._getElement("button_attributes");
286  this._domEventListenerSet.add(buttonAttributesElem,
287  "DOMAttrModified",
288  func,
289  false);
290  },
291 
292 
297  finalize: function sbWizardPageSvc_finalize() {
298  // Remove DOM event listeners.
299  if (this._domEventListenerSet) {
300  this._domEventListenerSet.removeAll();
301  }
302  this._domEventListenerSet = null;
303 
304  // Clear object fields.
305  this._widget = null;
306  this._wizardElem = null;
307  },
308 
309 
310  //----------------------------------------------------------------------------
311  //
312  // Widget event handling services.
313  //
314  //----------------------------------------------------------------------------
315 
320  _doPageShow: function sbWizardPageSvc__doPageShow() {
321  // Update the wizard buttons.
322  this._updateButtons();
323  },
324 
325 
332  _doButtonDOMAttrModified:
333  function sbWizardPageSvc__doButtonDOMAttrModified(aEvent) {
334  // Update the wizard buttons.
335  this._updateButtons();
336  },
337 
338 
339  //----------------------------------------------------------------------------
340  //
341  // Internal widget services.
342  //
343  //----------------------------------------------------------------------------
344 
349  _updateButtons: function sbWizardPageSvc__updateButtons() {
350  // Get the current wizard page.
351  var currentPage = this._wizardElem.currentPage;
352 
353  // Get the button hide and show settings.
354  var hideBackButton = currentPage.getAttribute("hideback") == "true";
355  var hideCancelButton = currentPage.getAttribute("hidecancel") == "true";
356  var hideNextButton = currentPage.getAttribute("hidenext") == "true";
357  var hideFinishButton = currentPage.getAttribute("hidefinish") == "true";
358  var showBackButton = currentPage.getAttribute("showback") == "true";
359  var showCancelButton = currentPage.getAttribute("showcancel") == "true";
360  var showNextButton = currentPage.getAttribute("shownext") == "true";
361  var showFinishButton = currentPage.getAttribute("showfinish") == "true";
362  var showExtra1Button = currentPage.getAttribute("showextra1") == "true";
363  var showExtra2Button = currentPage.getAttribute("showextra2") == "true";
364 
365  // Hide navigation buttons by default on post-finish pages.
366  if (this._wizardElem.postFinish) {
367  hideBackButton = true;
368  hideNextButton = true;
369  hideFinishButton = true;
370  }
371 
372  // Update the buttons. Hide extra buttons by default.
373  this._showHideButton("back", showBackButton, hideBackButton);
374  this._showHideButton("cancel", showCancelButton, hideCancelButton);
375  this._showHideButton("next", showNextButton, hideNextButton);
376  this._showHideButton("finish", showFinishButton, hideFinishButton);
377  this._showHideButton("extra1", showExtra1Button, true);
378  this._showHideButton("extra2", showExtra2Button, true);
379 
380  // Focus the next or finish buttons unless they're disabled or hidden.
381  var finishButton = this._wizardElem.getButton("finish");
382  var hideFinishButton =
383  finishButton.getAttribute("hidewizardbutton") == "true";
384  var nextButton = this._wizardElem.getButton("next");
385  var hideNextButton =
386  nextButton.getAttribute("hidewizardbutton") == "true";
387  if (!finishButton.hidden && !finishButton.disabled && !hideFinishButton)
388  finishButton.focus();
389  else if (!nextButton.hidden && !nextButton.disabled && !hideNextButton)
390  nextButton.focus();
391  },
392 
393 
399  _showHideButton: function sbWizardPageSvc__showHideButton(aButtonID,
400  aShow,
401  aHide) {
402  // Get the button element.
403  var button = this._wizardElem.getButton(aButtonID);
404 
405  // If button is set to be shown, force it to be visible.
406  // If button is set to be hidden, force it to be hidden. Use an attribute
407  // and CSS to hide in order to let the Mozilla wizard widget implementation
408  // control the hidden attribute.
409  // If button is not set to be shown or hidden, remove the hidden attribute
410  // and allow the Mozilla wizard widget to control the show/hide state.
411  if (aShow) {
412  button.removeAttribute("hidewizardbutton");
413  button.hidden = false;
414  } else if (aHide) {
415  button.setAttribute("hidewizardbutton", "true");
416  } else {
417  button.removeAttribute("hidewizardbutton");
418  }
419  },
420 
421 
431  _getElement: function sbWizardPageSvc__getElement(aElementID) {
432  return document.getAnonymousElementByAttribute(this._widget,
433  "anonid",
434  aElementID);
435  }
436 }
437 
const Cu
function Fx prototype initialize
const Cc
var cancelButton
function DOMEventListenerSet()
Definition: DOMUtils.jsm:766
DataRemote prototype constructor
var _this
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
function sbWizardSvc(aWidget)