2011-03-28 14:21:28 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/* Prototypes */
|
2013-04-18 08:00:54 +00:00
|
|
|
if (!String.prototype.trim) {
|
|
|
|
String.prototype.trim = function () {
|
|
|
|
return this.replace(/^\s+|\s+$/g,'');
|
|
|
|
};
|
2012-07-11 08:00:16 +00:00
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
var listener = {
|
|
|
|
set: function (el,type,callback) {
|
|
|
|
if (document.addEventListener) {
|
|
|
|
el.addEventListener(type, callback, false);
|
|
|
|
} else {
|
|
|
|
// IE hack courtesy of http://blog.stchur.com/2006/10/12/fixing-ies-attachevent-failures
|
|
|
|
var f = function() {
|
|
|
|
callback.call(el);
|
|
|
|
};
|
2013-06-06 08:01:03 +00:00
|
|
|
el.attachEvent('on' + type, f);
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Site wide functions */
|
|
|
|
|
|
|
|
// http://www.thefutureoftheweb.com/blog/adddomloadevent
|
|
|
|
// retrieved 2010-08-12
|
2013-06-27 08:01:06 +00:00
|
|
|
var addDOMLoadEvent = (
|
|
|
|
function() {
|
|
|
|
var e = [], t, s, n, i, o, d = document, w = window, r = 'readyState', c = 'onreadystatechange',
|
|
|
|
x = function() {
|
|
|
|
n = 1;
|
|
|
|
clearInterval(t);
|
|
|
|
while (i = e.shift()) {
|
|
|
|
i();
|
|
|
|
}
|
|
|
|
if (s) {
|
|
|
|
s[c] = ''
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return function(f) {
|
|
|
|
if (n) {
|
|
|
|
return f();
|
|
|
|
}
|
|
|
|
if (!e[0]) {
|
|
|
|
d.addEventListener && d.addEventListener("DOMContentLoaded", x, false);
|
|
|
|
/*@cc_on@*//*@if(@_win32)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/
|
|
|
|
if (/WebKit/i.test(navigator.userAgent))
|
|
|
|
t = setInterval(function() {
|
|
|
|
/loaded|complete/.test(d[r]) && x()
|
|
|
|
}, 10);
|
|
|
|
o = w.onload;
|
|
|
|
w.onload = function() {
|
|
|
|
x();
|
|
|
|
o && o()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.push(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)();
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
//PHP ports
|
|
|
|
function isset(variable) {
|
|
|
|
return (typeof(variable) === 'undefined') ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_array(input) {
|
|
|
|
return typeof(input) === 'object' && input instanceof Array;
|
|
|
|
}
|
|
|
|
|
|
|
|
function function_exists(function_name) {
|
|
|
|
return (typeof this.window[function_name] === 'function');
|
|
|
|
}
|
|
|
|
|
|
|
|
function html_entity_decode(str) {
|
2013-04-18 08:00:54 +00:00
|
|
|
var el = document.createElement("div");
|
|
|
|
el.innerHTML = str;
|
|
|
|
for (var i = 0, ret = ''; i < el.childNodes.length; i++) {
|
|
|
|
ret += el.childNodes[i].nodeValue;
|
|
|
|
}
|
|
|
|
return ret;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_size(size) {
|
|
|
|
var steps = 0;
|
2013-06-06 08:01:03 +00:00
|
|
|
while (size >= 1024) {
|
2011-03-28 14:21:28 +00:00
|
|
|
steps++;
|
2013-06-06 08:01:03 +00:00
|
|
|
size = size / 1024;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
var ext;
|
2013-06-27 08:01:06 +00:00
|
|
|
switch (steps) {
|
2011-03-28 14:21:28 +00:00
|
|
|
case 1: ext = ' B';
|
|
|
|
break;
|
|
|
|
case 1: ext = ' KB';
|
|
|
|
break;
|
|
|
|
case 2: ext = ' MB';
|
|
|
|
break;
|
|
|
|
case 3: ext = ' GB';
|
|
|
|
break;
|
|
|
|
case 4: ext = ' TB';
|
|
|
|
break;
|
|
|
|
case 5: ext = ' PB';
|
|
|
|
break;
|
|
|
|
case 6: ext = ' EB';
|
|
|
|
break;
|
|
|
|
case 7: ext = ' ZB';
|
|
|
|
break;
|
|
|
|
case 8: ext = ' EB';
|
|
|
|
break;
|
|
|
|
default: "0.00 MB";
|
|
|
|
}
|
|
|
|
return (size.toFixed(2) + ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_ratio_color(ratio) {
|
|
|
|
if (ratio < 0.1) { return 'r00'; }
|
|
|
|
if (ratio < 0.2) { return 'r01'; }
|
|
|
|
if (ratio < 0.3) { return 'r02'; }
|
|
|
|
if (ratio < 0.4) { return 'r03'; }
|
|
|
|
if (ratio < 0.5) { return 'r04'; }
|
|
|
|
if (ratio < 0.6) { return 'r05'; }
|
|
|
|
if (ratio < 0.7) { return 'r06'; }
|
|
|
|
if (ratio < 0.8) { return 'r07'; }
|
|
|
|
if (ratio < 0.9) { return 'r08'; }
|
|
|
|
if (ratio < 1) { return 'r09'; }
|
|
|
|
if (ratio < 2) { return 'r10'; }
|
|
|
|
if (ratio < 5) { return 'r20'; }
|
|
|
|
return 'r50';
|
|
|
|
}
|
|
|
|
|
|
|
|
function ratio(dividend, divisor, color) {
|
2013-04-18 08:00:54 +00:00
|
|
|
if (!color) {
|
2011-03-28 14:21:28 +00:00
|
|
|
color = true;
|
|
|
|
}
|
2013-04-18 08:00:54 +00:00
|
|
|
if (divisor == 0 && dividend == 0) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return '--';
|
2013-04-18 08:00:54 +00:00
|
|
|
} else if (divisor == 0) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return '<span class="r99">∞</span>';
|
2013-04-18 08:00:54 +00:00
|
|
|
} else if (dividend == 0 && divisor > 0) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return '<span class="r00">-∞</span>';
|
|
|
|
}
|
2013-06-06 08:01:03 +00:00
|
|
|
var rat = ((dividend / divisor) - 0.005).toFixed(2); //Subtract .005 to floor to 2 decimals
|
2013-04-18 08:00:54 +00:00
|
|
|
if (color) {
|
2011-03-28 14:21:28 +00:00
|
|
|
var col = get_ratio_color(rat);
|
2013-04-18 08:00:54 +00:00
|
|
|
if (col) {
|
2013-06-27 08:01:06 +00:00
|
|
|
rat = '<span class="' + col + '">' + rat + '</span>';
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function save_message(message) {
|
|
|
|
var messageDiv = document.createElement("div");
|
|
|
|
messageDiv.className = "save_message";
|
|
|
|
messageDiv.innerHTML = message;
|
|
|
|
$("#content").raw().insertBefore(messageDiv,$("#content").raw().firstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
function error_message(message) {
|
|
|
|
var messageDiv = document.createElement("div");
|
|
|
|
messageDiv.className = "error_message";
|
|
|
|
messageDiv.innerHTML = message;
|
|
|
|
$("#content").raw().insertBefore(messageDiv,$("#content").raw().firstChild);
|
|
|
|
}
|
|
|
|
|
2013-06-06 08:01:03 +00:00
|
|
|
//returns key if true, and false if false. better than the PHP funciton
|
2011-03-28 14:21:28 +00:00
|
|
|
function in_array(needle, haystack, strict) {
|
|
|
|
if (strict === undefined) {
|
|
|
|
strict = false;
|
|
|
|
}
|
|
|
|
for (var key in haystack) {
|
|
|
|
if ((haystack[key] == needle && strict === false) || haystack[key] === needle) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function array_search(needle, haystack, strict) {
|
|
|
|
if (strict === undefined) {
|
|
|
|
strict = false;
|
|
|
|
}
|
|
|
|
for (var key in haystack) {
|
|
|
|
if ((strict === false && haystack[key] == needle) || haystack[key] === needle) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var util = function (selector, context) {
|
|
|
|
return new util.fn.init(selector, context);
|
2013-07-01 08:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function URL() {
|
|
|
|
var path = window.location.pathname.split('/');
|
|
|
|
var path = path[path.length - 1].split(".")[0];
|
|
|
|
var splitted = window.location.search.substr(1).split("&");
|
|
|
|
var query = {};
|
2013-08-28 23:08:41 +00:00
|
|
|
var length = 0;
|
2013-07-01 08:01:00 +00:00
|
|
|
for (var i = 0; i < splitted.length; i++) {
|
|
|
|
var q = splitted[i].split("=");
|
2013-11-08 08:01:03 +00:00
|
|
|
if (q != "") {
|
2013-08-28 23:08:41 +00:00
|
|
|
query[q[0]] = q[1];
|
|
|
|
length++;
|
|
|
|
}
|
2013-07-01 08:01:00 +00:00
|
|
|
};
|
2013-08-28 23:08:41 +00:00
|
|
|
query['length'] = length;
|
2013-07-01 08:01:00 +00:00
|
|
|
var response = new Array();
|
|
|
|
response['path'] = path;
|
|
|
|
response['query'] = query;
|
|
|
|
return response;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
function isNumberKey(e) {
|
|
|
|
var charCode = (e.which) ? e.which : e.keyCode
|
|
|
|
if (charCode == 46) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-23 08:00:59 +00:00
|
|
|
function sleep(milliseconds) {
|
|
|
|
var start = new Date().getTime();
|
|
|
|
for (var i = 0; i < 1e7; i++) {
|
|
|
|
if ((new Date().getTime() - start) > milliseconds){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 23:08:41 +00:00
|
|
|
$.fn.extend({
|
2011-03-28 14:21:28 +00:00
|
|
|
results: function () {
|
2013-06-27 08:01:06 +00:00
|
|
|
return this.size();
|
2011-03-28 14:21:28 +00:00
|
|
|
},
|
2013-06-17 08:01:02 +00:00
|
|
|
gshow: function () {
|
|
|
|
return this.remove_class('hidden');
|
|
|
|
},
|
|
|
|
ghide: function (force) {
|
|
|
|
return this.add_class('hidden', force);
|
|
|
|
},
|
|
|
|
gtoggle: function (force) {
|
|
|
|
//Should we interate and invert all entries, or just go by the first?
|
2013-06-27 08:01:06 +00:00
|
|
|
if (!in_array('hidden', this[0].className.split(' '))) {
|
2013-06-17 08:01:02 +00:00
|
|
|
this.add_class('hidden', force);
|
|
|
|
} else {
|
|
|
|
this.remove_class('hidden');
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
2011-03-28 14:21:28 +00:00
|
|
|
listen: function (event, callback) {
|
2013-06-28 08:01:04 +00:00
|
|
|
for (var i = 0, il = this.size(); i < il; i++) {
|
2013-06-27 08:01:06 +00:00
|
|
|
var object = this[i];
|
2011-03-28 14:21:28 +00:00
|
|
|
if (document.addEventListener) {
|
|
|
|
object.addEventListener(event, callback, false);
|
|
|
|
} else {
|
|
|
|
object.attachEvent('on' + event, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
2011-10-18 08:00:10 +00:00
|
|
|
add_class: function (class_name, force) {
|
2013-06-28 08:01:04 +00:00
|
|
|
for (var i = 0, il = this.size(); i < il; i++) {
|
2013-06-27 08:01:06 +00:00
|
|
|
var object = this[i];
|
2011-03-28 14:21:28 +00:00
|
|
|
if (object.className === '') {
|
|
|
|
object.className = class_name;
|
2011-10-18 08:00:10 +00:00
|
|
|
} else if (force || !in_array(class_name, object.className.split(' '))) {
|
2011-03-28 14:21:28 +00:00
|
|
|
object.className = object.className + ' ' + class_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
remove_class: function (class_name) {
|
2013-06-28 08:01:04 +00:00
|
|
|
for (var i = 0, il = this.size(); i < il; i++) {
|
2013-06-27 08:01:06 +00:00
|
|
|
var object = this[i];
|
2011-03-28 14:21:28 +00:00
|
|
|
var classes = object.className.split(' ');
|
2011-10-18 08:00:10 +00:00
|
|
|
var result = array_search(class_name, classes);
|
|
|
|
if (result !== false) {
|
2013-07-24 08:00:46 +00:00
|
|
|
classes.splice(result, 1);
|
2011-10-18 08:00:10 +00:00
|
|
|
object.className = classes.join(' ');
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
has_class: function(class_name) {
|
2013-06-28 08:01:04 +00:00
|
|
|
for (var i = 0, il = this.size(); i < il; i++) {
|
2013-06-27 08:01:06 +00:00
|
|
|
var object = this[i];
|
2011-03-28 14:21:28 +00:00
|
|
|
var classes = object.className.split(' ');
|
2012-08-23 08:00:17 +00:00
|
|
|
if (array_search(class_name, classes)) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2012-08-23 08:00:17 +00:00
|
|
|
toggle_class: function(class_name) {
|
2013-06-28 08:01:04 +00:00
|
|
|
for (var i = 0, il = this.size(); i < il; i++) {
|
2013-06-27 08:01:06 +00:00
|
|
|
var object = this[i];
|
2012-08-23 08:00:17 +00:00
|
|
|
var classes = object.className.split(' ');
|
|
|
|
var result = array_search(class_name, classes);
|
|
|
|
if (result !== false) {
|
2013-07-24 08:00:46 +00:00
|
|
|
classes.splice(result, 1);
|
2012-08-23 08:00:17 +00:00
|
|
|
object.className = classes.join(' ');
|
|
|
|
} else {
|
|
|
|
if (object.className === '') {
|
|
|
|
object.className = class_name;
|
|
|
|
} else {
|
|
|
|
object.className = object.className + ' ' + class_name;
|
2013-02-22 08:00:24 +00:00
|
|
|
}
|
2012-08-23 08:00:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
2011-03-28 14:21:28 +00:00
|
|
|
disable : function () {
|
2013-10-11 08:01:04 +00:00
|
|
|
$(this).prop('disabled', true);
|
2011-03-28 14:21:28 +00:00
|
|
|
return this;
|
|
|
|
},
|
2013-02-23 08:00:22 +00:00
|
|
|
enable : function () {
|
2013-10-11 08:01:04 +00:00
|
|
|
$(this).prop('disabled', false);
|
2013-02-23 08:00:22 +00:00
|
|
|
return this;
|
|
|
|
},
|
2011-03-28 14:21:28 +00:00
|
|
|
raw: function (number) {
|
2013-10-11 08:01:04 +00:00
|
|
|
if (typeof number == 'undefined') {
|
2011-03-28 14:21:28 +00:00
|
|
|
number = 0;
|
|
|
|
}
|
2013-10-11 08:01:04 +00:00
|
|
|
return $(this).get(number);
|
2011-03-28 14:21:28 +00:00
|
|
|
},
|
|
|
|
nextElementSibling: function () {
|
2013-06-27 08:01:06 +00:00
|
|
|
var here = this[0];
|
2013-02-22 08:00:24 +00:00
|
|
|
if (here.nextElementSibling) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return $(here.nextElementSibling);
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
here = here.nextSibling;
|
|
|
|
} while (here.nodeType != 1);
|
|
|
|
return $(here);
|
|
|
|
},
|
|
|
|
previousElementSibling: function () {
|
2013-06-27 08:01:06 +00:00
|
|
|
var here = this[0];
|
2013-02-22 08:00:24 +00:00
|
|
|
if (here.previousElementSibling) {
|
2011-03-28 14:21:28 +00:00
|
|
|
return $(here.previousElementSibling);
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
here = here.nextSibling;
|
|
|
|
} while (here.nodeType != 1);
|
|
|
|
return $(here);
|
2013-08-28 23:08:41 +00:00
|
|
|
},
|
|
|
|
updateTooltip: function(tooltip) {
|
|
|
|
if ($.fn.tooltipster) {
|
|
|
|
$(this).tooltipster('update', tooltip);
|
|
|
|
} else {
|
|
|
|
$(this).attr('title', tooltip);
|
|
|
|
}
|
2013-10-11 08:01:04 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Disable unset form elements to allow search URLs cleanups
|
|
|
|
disableUnset: function() {
|
2014-04-02 08:00:56 +00:00
|
|
|
$('input, select', this).filter(function() {
|
|
|
|
return $(this).val() === "";
|
|
|
|
}).disable();
|
2013-10-11 08:01:04 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Prevent double submission of forms
|
|
|
|
preventDoubleSubmission: function() {
|
|
|
|
$(this).submit(function(e) {
|
|
|
|
var $form = $(this);
|
|
|
|
if ($form.data('submitted') === true) {
|
|
|
|
// Previously submitted - don't submit again
|
|
|
|
e.preventDefault();
|
|
|
|
} else {
|
|
|
|
// Mark it so that the next submit can be ignored
|
|
|
|
$form.data('submitted', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Keep chainability
|
|
|
|
return this;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
2013-06-27 08:01:06 +00:00
|
|
|
});
|