Skip to content

Instantly share code, notes, and snippets.

@iKlotho
Last active October 5, 2018 00:48
Show Gist options
  • Save iKlotho/73ce0d03affdae229b6025849c487616 to your computer and use it in GitHub Desktop.
Save iKlotho/73ce0d03affdae229b6025849c487616 to your computer and use it in GitHub Desktop.
display.js
var statusttime = 0;
var statustime;
var messagetime;
highlightiid = 0;
highlighticlass = '';
var scroll = {}
var gstatus = {}
var ReloadSound = 0;
window.onready = function(ev) {
var Tmp_Credits = document.getElementById('Display_CLI_Credits');
if (Tmp_Credits) {
setTimeout(function() {
Refresh_CLI_Credit();
}, 30000); //Kick off CLI refresh
}
}
function Refresh_CLI_Credit() {
var Tmp = {
NoStatusBox: "1"
};
ndisp('Display_CLI_Credits', '/', 'direct/d.php?p=d&', Tmp, 't=159&content=cli'); //Refresh this
setTimeout(function() {
Refresh_CLI_Credit();
}, 30000);
}
buildQuery = function(form) {
var query = "";
for (var i = 0; i < form.elements.length; i++) {
var key = form.elements[i].name;
var value = getElementValue(form.elements[i]);
if (key && value) {
if (form.elements[i].type != "checkbox") {
value = value.replace(/&/g, "%amp");
value = value.replace(/\n/g, "%%-");
value = value.replace(/#/g, "%%hash");
value = value.replace(/\+/g, "%%plus");
value = value.replace(/\\/g, "%%slash");
}
query += "&" + key + "=" + value;
}
}
return query;
}
getElementValue = function(formElement) {
if (formElement.length != null) var type = formElement[0].type;
if ((typeof(type) == 'undefined') || (type == 0)) var type = formElement.type;
switch (type) {
case 'undefined':
return;
case 'radio':
for (var x = 0; x < formElement.length; x++)
if (formElement[x].checked == true)
return formElement[x].value;
case 'select-multiple':
var myArray = new Array();
for (var x = 0; x < formElement.length; x++)
if (formElement[x].selected == true)
myArray[myArray.length] = formElement[x].value;
return myArray;
case 'checkbox':
return formElement.checked;
default:
return formElement.value;
}
}
function ndisp(display, url, p, qt, value) {
// alert(display);
var NoStatusBox = false;
if (typeof(qt) == 'object') {
if ('NoStatusBox' in qt) {
NoStatusBox = true;
}
}
if (display != "refresh" && display != "na" && display != "note") { //"refresh" refreshes page, "na" just submits request (no return data)
var ajaxdisp = document.getElementById(display);
}
var request;
try {
request = new XMLHttpRequest();
} catch (e) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your Browser Does Not Support AJAX Calls!");
return false;
}
}
}
//
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (display == "refresh") {
self.location = window.location //Reload browser
} else if (display == "alert") {
alert(request.responseText);
} else if (display != "na") {
if (request.status == 300) { //Use to refresh on ajax call to session that has timed out
self.location = window.location
} else {
if (!NoStatusBox) {
statusbox('min', '1');
}
if (request.status == 200) { //Only do this for Successful calls
ajaxdisp.innerHTML = request.responseText;
ajaxpostexec();
if (typeof(Custom_Post_Ajax) == "function" && typeof(qt) == 'object') {
if ("timeout" in qt) {
delete qt.timeout;
}
Custom_Post_Ajax(qt);
}
}
}
}
}
}
if (qt == "form") { //qt is the query type
var query = buildQuery(value);
request.open("GET","https://www.ariatelekom.com/develop/test/get_audio_form?call_id="+qt+"&types="+value, true);
request.send(null);
if (display != "na") {
statusbox('max', '1');
}
} else if (qt == "postform") {
var formData = new FormData();
formData.append(value, document.getElementById(value).files[0]);
request.open("POST", url + p);
request.send(formData);
if (display != "na") {
statusbox('max', '1');
}
} else {
value = value.replace(/\n/g, "%%-");
value = value.replace(/#/g, "%%hash");
value = value.replace(/\+/g, "%%plus");
//value = value.replace(/\*/g,"%%asterisk");
value = value.replace(/\\/g, "%%slash");
request.open("GET","https://www.ariatelekom.com/develop/test/get_audio_form?call_id="+qt+"&types="+value, true);
request.timeout = 10000;
request.ontimeout = function() {
request.abort();
if (typeof(Custom_Post_Ajax) == "function" && typeof(qt) == 'object' && "timeout" in qt) {
Custom_Post_Ajax(qt);
}
}
request.send(null);
if (display != "na" && !NoStatusBox) {
statusbox('max', '1');
}
}
//return true;
}
function SoundManagerReady() {
basicMP3Player = null;
soundManager.preferFlash = false;
basicMP3Player = new BasicMP3Player();
}
function ajaxpostexec() {
if (gstatus['search'] == 1) { //Only focus on searchfield if its set
if (document.getElementById('searchfield')) {
var $temp = document.getElementById('searchfield').value;
document.getElementById('searchfield').focus();
document.getElementById('searchfield').value = $temp;
}
gstatus['search'] = 0;
}
}
function warningbox(action) {
if (action == 'max') {
document.getElementById('warningbox').style.width = '910px';
var PageScroll = window.pageYOffset;
if (PageScroll < 100) {
PageScroll += 150;
} //At the top, add an additional 100
else {
PageScroll += 50;
}
document.getElementById('warningbox').style.top = PageScroll + 'px';
} else {
document.getElementById('warningtext').innerHTML = '';
document.getElementById('warningbox').style.width = '0px';
}
}
function notificationbox(action) {
if (action == 'max') {
document.getElementById('notificationsbox').style.width = '830px';
document.getElementById('notificationsbgbox').style.width = '100%';
document.getElementById('notificationsbgbox').style.height = '100%';
var PageScroll = window.pageYOffset + 50;
document.getElementById('notificationsbox').style.top = PageScroll + 'px';
} else {
document.getElementById('notificationstext').innerHTML = '';
document.getElementById('notificationsbox').style.width = '0px';
document.getElementById('notificationsbgbox').style.width = '0px';
document.getElementById('notificationsbgbox').style.height = '0px';
}
}
function statusbox(action, nstatustime) {
if (action == 'max') {
clearTimeout(statustime)
if (nstatustime == statusttime) {
document.getElementById('loadstatusbox').style.width = '300px';
var PageScroll = window.pageYOffset + 100;
document.getElementById('loadstatusbox').style.top = PageScroll + 'px';
//document.getElementById('loadstatusbox').style.top = '150px';
} else {
statusttime = (new Date).getTime();
statustime = setTimeout("statusbox('max'," + statusttime + ");", 1000);
}
} else {
document.getElementById('loadstatusbox').style.width = '0px';
document.getElementById('loadstatusbox').style.top = '0px';
clearTimeout(statustime)
statusttime = 0;
}
}
function scrolltoview() {
if (focusdivs = document.getElementsByName('focusthis')) {
for (var i = 0; i < focusdivs.length; i++) {
focusdivs[i].scrollIntoView();
}
}
}
function classhl(prefix, id, cl) {
if (highlightiid > 0) {
document.getElementById(prefix + highlightiid).className = highlighticlass;
}
highlighticlass = document.getElementById(prefix + id).className;
highlightiid = id;
document.getElementById(prefix + id).className = cl;
}
function messageopen(ev, t, content, align) {
clearTimeout(messagetime)
var x = ev.clientX + window.pageXOffset;
var y = ev.clientY + window.pageYOffset;
document.getElementById('tempmessagebox').style.textAlign = align;
document.getElementById('tempmessageboxtxt').innerHTML = content;
document.getElementById('tempmessagebox').style.width = '';
var w;
try {
w = document.getElementById('tempmessagebox').clientWidth;
} catch (e) {
w = 100;
}
document.getElementById('tempmessagebox').style.left = (x - (w / 2)) + 'px';
document.getElementById('tempmessagebox').style.top = (y + 20) + 'px';
messagetime = setTimeout("messageclose();", t);
}
function messageclose() {
document.getElementById('tempmessageboxtxt').innerHTML = '';
document.getElementById('tempmessagebox').style.width = '0px';
document.getElementById('tempmessagebox').style.left = '0px';
document.getElementById('tempmessagebox').style.top = '0px';
}
function collapsebox(box, headerauth) {
//var target;
//event = (typeof event === "undefined") ? headerauth : event; //Define it if not defined
//if( event ) { target = headerauth; }
//else { target = event.target || event.srcElement; }
//if (headerauth == target.id) { //Not sure why this is needed
try {
ch = document.getElementById(box + 'inner').clientHeight;
} catch (e) {
ch = 100;
}
slowscrolli(box + 'outter', ch);
//}
}
function slowscrolli(id, maxheight) {
if (scroll[id + 'r'] == 1) {
clearTimeout(scroll[id + '-count']);
slowscroll(id, scroll[id + '-e'], scroll[id + '-s'], scroll[id + '-i']);
} else {
if (!(id + '-state' in scroll) || scroll[id + '-state'] == 0) {
document.getElementById(id).style.margin = '';
slowscroll(id, 0, 0, maxheight);
scroll[id + '-state'] = 1;
} else {
slowscroll(id, maxheight, maxheight, 0);
scroll[id + '-state'] = 0;
}
scroll[id + 'r'] = 1;
}
}
function slowscroll(id, i, s, e) {
// console.log(id+' '+i+' '+s+' '+e);
if (i > e) {
if (s <= e) {
document.getElementById(id).style.height = '0px';
document.getElementById(id).style.margin = '0px';
scroll[id + 'r'] = 0;
scroll[id + '-state'] = 0;
ndisp('na', '/', 'direct/d.php?p=d&', '', 't=139&collapsename=' + id + '&state=0');
return;
}
if (s < (e + 50)) {
s = (s - 5);
} else if (s < (e + 25)) {
s = (s - 2);
document.getElementById(id).style.margin = (s / 3) + 'px'; //For slower collapse of margin
} else {
s = (s - 20);
}
document.getElementById(id).style.height = s + 'px';
} else {
if (s >= e) {
document.getElementById(id).style.height = '';
scroll[id + 'r'] = 0;
scroll[id + '-state'] = 1;
ndisp('na', '/', 'direct/d.php?p=d&', '', 't=139&collapsename=' + id + '&state=1');
return;
}
if (s > (e - 50)) {
s = (s + 5);
} else if (s > (e - 25)) {
s = (s + 2);
} else {
s = (s + 20);
}
document.getElementById(id).style.height = s + 'px';
}
scroll[id + '-i'] = i;
scroll[id + '-s'] = s;
scroll[id + '-e'] = e;
scroll[id + '-count'] = setTimeout(function() {
slowscroll(id, i, s, e);
}, 20);
}
//Search Stuff
var ttime = 0;
var searchtime;
var Search_Arg = {
Search_Field: "",
Display_Res: "",
URL: "",
Search_Field: ""
}; //Global Search Argument for use wit this shit
function Search_Fetch(Search_Term) {
clearTimeout(searchtime);
var Tmp = {
t: "Run_On_Load",
NoStatusBox: "1"
}; //Temp Args
ndisp(Search_Arg.Display_Res, '/', 'direct/d.php?p=d&', Tmp, Search_Arg.URL + Search_Term);
}
function Search_Ponder(ntime) {
clearTimeout(searchtime);
var searchfield = encodeURI(document.getElementById(Search_Arg.Search_Field).value);
if (ntime == ttime) {
gstatus['search'] = 1; //Highlight
Search_Fetch(searchfield);
} else {
ttime = (new Date).getTime();
searchtime = setTimeout("Search_Ponder(" + ttime + ");", 200);
}
}
function Search_Clear() {
clearTimeout(searchtime);
document.getElementById(Search_Arg.Search_Field).value = "";
Search_Fetch('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment