home *** CD-ROM | disk | FTP | other *** search
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Scott MacGregor <mscott@netscape.com>
- * Jens Bannmann <jens.b@web.de>
- * George Bradt
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- var SimpleTimerSliderAlert = {
- sliderQueue: [],
- application: null,
- finalHeight: 0,
- slideIncrement: 1,
- slideTime: 10,
- openTime: 0, // total time the alert should stay up once we are done animating.
-
- // Entry, message to be displayed is passed in and added to the queue.
- // Use a queue to prevent overlapping windows.
-
- addMessageToQueue: function(msg) {
- SimpleTimerSliderAlert.application = Components.classes["@mozilla.org/fuel/application;1"].
- getService(Components.interfaces.fuelIApplication);
-
- if ( !SimpleTimerSliderAlert.application.storage.has("sliderQueue") ) {
- SimpleTimerSliderAlert.setSliderQueue();
- }
-
- SimpleTimerSliderAlert.getSliderQueue();
- SimpleTimerSliderAlert.sliderQueue.push(msg);
- SimpleTimerSliderAlert.setSliderQueue();
-
- if ( SimpleTimerSliderAlert.sliderQueue.length === 1 ) {
- // If length > 1, an alert already in progress.
- SimpleTimerSliderAlert.openSliderWindow();
- }
- },
-
- // Custom slider alert. The message is displayed in a small window that slides up
- // from the bottom of the screen, holds there for a few seconds,
- // then slides down. Allows multi-line messages.
-
- openSliderWindow: function() {
- window.openDialog(
- "chrome://simpletimer/content/simpletimer-sliderAlert.xul",
- "",
- "chrome, dialog, titlebar=no, popup");
- },
-
- // Build the window.
-
- prefillAlertInfo: function() {
- var strbundle = document.getElementById("simtim-strings");
- var rowNode, descrNodeTime, descrNodeDescription;
-
- this.application = Components.classes["@mozilla.org/fuel/application;1"].
- getService(Components.interfaces.fuelIApplication);
-
- this.getSliderQueue();
-
- var displayItems = this.sliderQueue[0].displayItems;
- document.getElementById("simtim-descMessage").value = this.sliderQueue[0].msg;
-
- var parent = document.getElementById("simtim-gridItems");
- var oldRowsNode = parent.lastChild;
- var newRowsNode = document.createElement("rows");
-
- if ( displayItems !== null ) {
- for ( var i in displayItems ) {
-
- rowNode = document.createElement("row");
-
- descrNodeTime = document.createElement("description");
- descrNodeTime.setAttribute("value", displayItems[i].timeDisplay);
- rowNode.appendChild(descrNodeTime);
-
- descrNodeDescription = document.createElement("description");
- descrNodeDescription.setAttribute("value", displayItems[i].description);
- rowNode.appendChild(descrNodeDescription);
-
- newRowsNode.appendChild(rowNode);
-
- if ( i === "7" && displayItems.length > 8 ) {
- // Eight items should be enough.
- rowNode = document.createElement("row");
-
- descrNodeTime = document.createElement("description");
- descrNodeTime.setAttribute("value", strbundle.getString("msg.etc"));
- rowNode.appendChild(descrNodeTime);
-
- newRowsNode.appendChild(rowNode);
- break;
- }
- }
- }
-
- parent.replaceChild(newRowsNode, oldRowsNode);
- },
-
- // Size and position window.
-
- onAlertLoad: function() {
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefService).
- getBranch("extensions.simpletimer@grbradt.org.");
- var alertSliderMaxHeight;
-
- sizeToContent();
-
- this.finalHeight = window.outerHeight;
- window.outerHeight = 1;
-
- // Be sure to offset the alert by 10 pixels from the far right edge of the screen.
- window.moveTo( (screen.availLeft + screen.availWidth - window.outerWidth) - 10,
- screen.availTop + screen.availHeight - window.outerHeight);
-
- setTimeout("SimpleTimerSliderAlert.animateAlert()", this.slideTime);
- },
-
- // Moving the window up.
-
- animateAlert: function() {
- if ( window.outerHeight < this.finalHeight ) {
- window.screenY -= this.slideIncrement;
- window.outerHeight += this.slideIncrement;
- setTimeout("SimpleTimerSliderAlert.animateAlert()", this.slideTime);
- }
- else {
- setTimeout("SimpleTimerSliderAlert.closeAlert()", 3000);
- }
- },
-
- // Moving the window down.
-
- closeAlert: function() {
- if ( window.outerHeight > 1 ) {
- window.screenY += this.slideIncrement;
- window.outerHeight -= this.slideIncrement;
- setTimeout("SimpleTimerSliderAlert.closeAlert()", this.slideTime);
- }
- else {
- this.getSliderQueue();
- this.sliderQueue.shift();
- this.setSliderQueue();
-
- if ( this.sliderQueue.length === 0 ) {
- window.close();
- }
- else {
- // Process next in queue.
- this.prefillAlertInfo();
- this.onAlertLoad();
- }
- }
- },
-
- // Retrieve the global.
-
- getSliderQueue: function() {
- SimpleTimerSliderAlert.sliderQueue = SimpleTimerSliderAlert.application.storage.get("sliderQueue", "ERR");
- },
-
- // Update the global.
-
- setSliderQueue: function() {
- SimpleTimerSliderAlert.application.storage.set("sliderQueue", SimpleTimerSliderAlert.sliderQueue);
- },
-
- // Debug messages to console.
-
- debug: function (aMsg) {
- setTimeout(function() { throw new Error("[debug] " + aMsg); }, 0);
- }
- };