www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

progressBar.js (3657B)


      1 /*
      2     ***** BEGIN LICENSE BLOCK *****
      3     
      4     Copyright © 2018 Center for History and New Media
      5 				     George Mason University, Fairfax, Virginia, USA
      6 				     http://zotero.org
      7     
      8     This file is part of Zotero.
      9     
     10     Zotero is free software: you can redistribute it and/or modify
     11     it under the terms of the GNU Affero General Public License as published by
     12     the Free Software Foundation, either version 3 of the License, or
     13     (at your option) any later version.
     14     
     15     Zotero is distributed in the hope that it will be useful,
     16     but WITHOUT ANY WARRANTY; without even the implied warranty of
     17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18     GNU Affero General Public License for more details.
     19     
     20     You should have received a copy of the GNU Affero General Public License
     21     along with Zotero.  If not, see <http://www.gnu.org/licenses/>.
     22     
     23     ***** END LICENSE BLOCK *****
     24 */
     25 Components.utils.import("resource://gre/modules/Services.jsm");
     26 
     27 var Zotero_ProgressBar = new function () {
     28 	var initialized, io;
     29 	
     30 	/**
     31 	 * Pre-initialization, when the dialog has loaded but has not yet appeared
     32 	 */
     33 	this.onDOMContentLoaded = function(event) {
     34 		if(event.target === document) {
     35 			initialized = true;
     36 			io = window.arguments[0].wrappedJSObject;
     37 			if (io.onLoad) {
     38 				io.onLoad(_onProgress);
     39 			}
     40 			
     41 			// Only hide chrome on Windows or Mac
     42 			if(Zotero.isMac) {
     43 				document.documentElement.setAttribute("drawintitlebar", true);
     44 			} else if(Zotero.isWin) {
     45 				document.documentElement.setAttribute("hidechrome", true);
     46 			}
     47 			
     48 			new WindowDraggingElement(document.getElementById("quick-format-dialog"), window);
     49 		
     50 		}
     51 	};
     52 	
     53 	/**
     54 	 * Center the window
     55 	 */
     56 	this.onLoad = function(event) {
     57 		if(event.target !== document) return;		
     58 		// make sure we are visible
     59 		window.focus();
     60 		window.setTimeout(function() {
     61 			var targetX = Math.floor(-window.outerWidth/2 + (window.screen.width / 2));
     62 			var targetY = Math.floor(-window.outerHeight/2 + (window.screen.height / 2));
     63 			Zotero.debug("Moving window to "+targetX+", "+targetY);
     64 			window.moveTo(targetX, targetY);
     65 		}, 0);
     66 	};
     67 	
     68 	/**
     69 	 * Called when progress changes
     70 	 */
     71 	function _onProgress(percent) {
     72 		var meter = document.getElementById("quick-format-progress-meter");
     73 		if(percent === null) {
     74 			meter.mode = "undetermined";
     75 		} else {
     76 			meter.mode = "determined";
     77 			meter.value = Math.round(percent);
     78 		}
     79 	}
     80 	
     81 	/**
     82 	 * Resizes windows
     83 	 * @constructor
     84 	 */
     85 	var Resizer = function(panel, targetWidth, targetHeight, pixelsPerStep, stepsPerSecond) {
     86 		this.panel = panel;
     87 		this.curWidth = panel.clientWidth;
     88 		this.curHeight = panel.clientHeight;
     89 		this.difX = (targetWidth ? targetWidth - this.curWidth : 0);
     90 		this.difY = (targetHeight ? targetHeight - this.curHeight : 0);
     91 		this.step = 0;
     92 		this.steps = Math.ceil(Math.max(Math.abs(this.difX), Math.abs(this.difY))/pixelsPerStep);
     93 		this.timeout = (1000/stepsPerSecond);
     94 		
     95 		var me = this;
     96 		this._animateCallback = function() { me.animate() };
     97 	};
     98 	
     99 	/**
    100 	 * Performs a step of the animation
    101 	 */
    102 	Resizer.prototype.animate = function() {
    103 		if(this.stopped) return;
    104 		this.step++;
    105 		this.panel.sizeTo(this.curWidth+Math.round(this.step*this.difX/this.steps),
    106 			this.curHeight+Math.round(this.step*this.difY/this.steps));
    107 		if(this.step !== this.steps) {
    108 			window.setTimeout(this._animateCallback, this.timeout);
    109 		}
    110 	};
    111 	
    112 	/**
    113 	 * Halts resizing
    114 	 */
    115 	Resizer.prototype.stop = function() {
    116 		this.stopped = true;
    117 	};
    118 }
    119 
    120 window.addEventListener("DOMContentLoaded", Zotero_ProgressBar.onDOMContentLoaded, false);
    121 window.addEventListener("load", Zotero_ProgressBar.onLoad, false);