vzlogger/frontend/javascripts/helper.js

70 lines
2 KiB
JavaScript
Raw Normal View History

/**
* Some functions and prototypes which make our life easier
*
* @author Florian Ziegler <fz@f10-home.de>
* @author Justin Otherguy <justin@justinotherguy.org>
* @author Steffen Vogel <info@steffenvogel.de>
* @copyright Copyright (c) 2010, The volkszaehler.org project
* @package default
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/*
* This file is part of volkzaehler.org
*
* volkzaehler.org is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or any later version.
*
* volkzaehler.org is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
*/
2010-10-19 19:57:45 +02:00
/**
* Helper function to wait for multiple ajax requests to complete
*/
2010-10-06 06:34:36 +02:00
function waitAsync(callback, finished, identifier) {
if (!waitAsync.counter) { waitAsync.counter = new Array(); }
if (!waitAsync.counter[identifier]) { waitAsync.counter[identifier] = 0; }
2010-10-06 06:34:36 +02:00
waitAsync.counter[identifier]++;
return function (data, textStatus) {
callback(data, textStatus);
2010-10-06 06:34:36 +02:00
if (!--waitAsync.counter[identifier]) {
finished();
}
};
}
2010-10-06 06:34:36 +02:00
/*
* Array extensions
* according to js language specification ECMA 1.6
*/
2010-10-04 21:10:58 +02:00
Array.prototype.indexOf = function(n) {
for (var i = 0, l = this.length; i < l; i++)
if (n == this[i]) return i;
};
2010-10-04 21:10:58 +02:00
Array.prototype.remove = function(n) {
this.splice(this.indexOf(n), 1);
};
2010-10-04 21:10:58 +02:00
Array.prototype.each = function(cb) {
for (var i = 0, l = this.length; i < l; i++)
cb(i, this[i]);
};
2010-10-04 21:10:58 +02:00
Array.prototype.contains = function(n) {
return this.indexOf(n) !== undefined;
};
2010-10-04 21:10:58 +02:00
Array.prototype.clear = function() {
this.length = 0;
2010-10-19 19:57:45 +02:00
}