wordpress-theme-openmamba/scripts/socialbox.js

127 lines
5.7 KiB
JavaScript
Raw Permalink Normal View History

2014-11-13 21:33:23 +01:00
var webbuildhost = ""
var socialbox_fullrefresh_count = 0;
function socialbox_refresh_times() {
"use strict";
2014-11-13 21:33:23 +01:00
var times = document.getElementsByName("socialtime");
var datenow = new Date();
var utcnow = parseInt(Date.UTC(datenow.getUTCFullYear(), datenow.getUTCMonth(), datenow.getUTCDate(),
datenow.getUTCHours(), datenow.getUTCMinutes(), datenow.getUTCSeconds()) / 1000);
for (var i = 0; i < times.length; i++) {
if (times[i].attributes[0].name == "time") {
var socialtime = times[i].attributes[0].value;
} else {
var socialtime = times[i].attributes[1].value;
}
var timeago = utcnow - socialtime;
if ((times[i].innerHTML == "") ||
(timeago <= 120) || // update every 15 secs if < 2 min
(timeago <= 7200 && (socialbox_fullrefresh_count % 4 == 0)) || // update every minute if < 120 min
(timeago <= 86400 && (socialbox_fullrefresh_count % 120 == 0)) || // update every thirty minutes if < 1 day
(socialbox_fullrefresh_count >= 240)) // else update all every hour
{
var daysago = parseInt(timeago / 86400);
var hoursago = parseInt(timeago / 3600 % 24);
var minutesago = parseInt(timeago / 60 % 60);
var secondsago = parseInt(timeago % 60);
times[i].innerHTML = "(";
if (daysago > 1) times[i].innerHTML += daysago + " days";
else if (daysago == 1) times[i].innerHTML += "1 day, " + hoursago + " hours";
else if (hoursago > 1) times[i].innerHTML += hoursago + " hours";
else if (hoursago == 1) times[i].innerHTML += "1 hour, " + minutesago + " minutes";
else if (minutesago > 1) times[i].innerHTML += minutesago + " minutes";
else if (minutesago == 1) times[i].innerHTML += "1 minute, " + secondsago + " seconds";
else times[i].innerHTML += secondsago + " seconds";
times[i].innerHTML += " ago) ";
}
}
if (socialbox_fullrefresh_count++ >= 240) socialbox_fullrefresh_count = 0;
}
var socialbox_interval = null;
var socialbox_reloadtime = 5000;
2014-11-13 21:33:23 +01:00
function ajax_getvalues_refresh(request,user,user_email,secret) {
"use strict";
var webbuildurl = "/cgi-bin/webbuild.cgi"
var xmlhttp1;
2014-11-13 21:33:23 +01:00
if (typeof webbuildhost != 'undefined' && webbuildhost != "") {
webbuildurl = "/cgi-bin/webbuild-" + webbuildhost + ".cgi";
2014-11-13 21:33:23 +01:00
}
var fromid = 0;
if (socialbox_interval != null) {
clearInterval(socialbox_interval);
}
if (document.getElementsByName("social").length > 0) {
if (document.getElementsByName("social")[0].attributes[0].name == "sid") {
fromid = parseInt(document.getElementsByName("social")[0].attributes[0].value) + 1;
} else {
fromid = parseInt(document.getElementsByName("social")[0].attributes[1].value) + 1;
}
}
if (request != "")
request=request+"&REQUEST=refresh&USER="+user+"&USER_EMAIL="+user_email+"&SECRET="+secret+"&FROMID="+fromid;
else
request="REQUEST=refresh&USER="+user+"&USER_EMAIL="+user_email+"&SECRET="+secret+"&FROMID="+fromid;
if (window.XMLHttpRequest)
try {
xmlhttp1 = new XMLHttpRequest();
} catch(e) {
console.log('XMLHttpRequest Error');
socialbox_interval = setInterval("ajax_getvalues_refresh(\"\",\""+user+"\",\""+user_email+"\",\""+secret+"\",\""+webbuildhost+"\")",socialbox_reloadtime);
}
2014-11-13 21:33:23 +01:00
else if (window.ActiveXObject)
try {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
console.log('XMLHttpRequest Error');
socialbox_interval = setInterval("ajax_getvalues_refresh(\"\",\""+user+"\",\""+user_email+"\",\""+secret+"\",\""+webbuildhost+"\")",socialbox_reloadtime);
}
2014-11-13 21:33:23 +01:00
else
return;
xmlhttp1.onreadystatechange = function() {
if (xmlhttp1.readyState != 4)
return;
if (xmlhttp1.responseXML == undefined) {
console.log('XMLHttpRequest Undefined response');
socialbox_interval = setInterval("ajax_getvalues_refresh(\"\",\""+user+"\",\""+user_email+"\",\""+secret+"\",\""+webbuildhost+"\")",socialbox_reloadtime);
2014-11-13 21:33:23 +01:00
return;
}
var xmldoc = xmlhttp1.responseXML.documentElement;
2020-06-16 10:02:28 +02:00
if (xmldoc.getElementsByTagName("socialbox")[0] != undefined) {
var nodes = xmldoc.getElementsByTagName("socialbox")[0].childNodes;
for (var i = 0; i < nodes.length; i++) {
var id = nodes[i].attributes[0].value;
$("<span name=social sid=\""+ id + "\">" + nodes[i].childNodes[0].nodeValue + "</span>")
.clone().hide().prependTo("#socialbox").slideDown();
}
if (nodes.length > 0) {
var span_nodes = $("#socialbox").children("span").each(function(idx, el) {
if (idx >= 50) el.remove(); // keep a maximum of 50 elements
});
2020-06-16 10:02:28 +02:00
}
2014-11-13 21:33:23 +01:00
}
if (xmldoc.getElementsByTagName("processes")[0] != undefined) {
document.getElementById("processes").innerHTML = xmldoc.getElementsByTagName("processes")[0].childNodes[0].nodeValue;
$(function() { $('.scroll-pane3').jScrollPane({scrollbarWidth:10}); });
}
$(function() { $('.scroll-pane').jScrollPane({scrollbarWidth:10}); });
socialbox_refresh_times();
socialbox_interval = setInterval("ajax_getvalues_refresh(\"\",\""+user+"\",\""+user_email+"\",\""+secret+"\",\""+webbuildhost+"\")",socialbox_reloadtime);
}
xmlhttp1.timeout = function() {
console.log('XMLHttpRequest Timeout');
socialbox_interval = setInterval("ajax_getvalues_refresh(\"\",\""+user+"\",\""+user_email+"\",\""+secret+"\",\""+webbuildhost+"\")",socialbox_reloadtime);
2014-11-13 21:33:23 +01:00
}
xmlhttp1.open("POST", webbuildurl, true);
2014-11-13 21:33:23 +01:00
xmlhttp1.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp1.send(request);
}