mirror of
https://gitlab.com/CodeSolutionsProject/CodeShare.git
synced 2026-02-15 01:21:35 +01:00
120 lines
3.6 KiB
JavaScript
120 lines
3.6 KiB
JavaScript
function doAjax(postValue) {
|
|
//document.getElementById('ajaxPut').innerHTML = "<div class='container-fluid'><div class='row'></div><div class='row'><div class='loader'></div></div></div></div>";
|
|
// Obtener la instancia del objeto XMLHttpRequest (ajax)
|
|
conexion = new XMLHttpRequest();
|
|
// Preparar la funcion de respuesta
|
|
conexion.onreadystatechange = ajaxresponse; //Cuando el ajax sea procesado y suceda algo, se ejecuta esta funcion
|
|
// Realizar peticion HTTP
|
|
conexion.open('POST', 'ajax.php');
|
|
conexion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
conexion.send(postValue); //Las variables a mandar, en este caso POST
|
|
}
|
|
|
|
function ajaxresponse(){
|
|
if(conexion.readyState == 4){ //Esto es para que cambie cuando haya respuesta, que no es en todos los momentos
|
|
document.getElementById('ajaxPut').innerHTML = conexion.responseText; //Pondra todo lo devuelto por "file" (Que sera un php que de //echos dependiendo de lo enviado) en un div
|
|
}
|
|
reHightlight();
|
|
}
|
|
|
|
function reHightlight(){
|
|
var codebox = document.getElementsByClassName("codeto");
|
|
for(var i=0;i<codebox.length;++i){
|
|
hljs.highlightBlock(codebox[i]);
|
|
}
|
|
}
|
|
|
|
function mostrar(div) {
|
|
obj = document.getElementById(div);
|
|
obj.style.display = (obj.style.display == 'none') ? 'block' : 'none';
|
|
}
|
|
|
|
function getAjax() {
|
|
var checkboxes = document.getElementsByClassName("codeFilterCheckBoxInput");
|
|
var i;
|
|
var count = false;
|
|
var send;
|
|
for (i = 0; i<checkboxes.length;i++){
|
|
if(checkboxes[i].checked){
|
|
if(count){
|
|
send = send + "&lang"+i+"="+checkboxes[i].value;
|
|
}else{
|
|
send = "lang"+i+"="+checkboxes[i].value;
|
|
count = !count;
|
|
}
|
|
}
|
|
}
|
|
if(document.getElementById("search").value!="")
|
|
send = send+"&search="+document.getElementById("search").value;
|
|
doAjax(send);
|
|
}
|
|
|
|
|
|
/*
|
|
* Gestión de cookies.
|
|
*/
|
|
function obtenerCookie(clave) {
|
|
var name = clave + "=";
|
|
var ca = document.cookie.split(';');
|
|
for(var i=0; i<ca.length; i++) {
|
|
var c = ca[i];
|
|
while (c.charAt(0)==' ') c = c.substring(1);
|
|
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function comprobarCookie(clave) {
|
|
var clave = obtenerCookie(clave);
|
|
if (clave!="") {
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function crearCookie(clave, valor, diasexpiracion) {
|
|
var d = new Date();
|
|
d.setTime(d.getTime() + (diasexpiracion*24*60*60*1000));
|
|
var expires = "expires="+d.toUTCString();
|
|
document.cookie = clave + "=" + valor + "; " + expires;
|
|
}
|
|
|
|
function borrarCookie(clave){
|
|
crearCookie(clave,"",-1);
|
|
}
|
|
|
|
function desloguearse(){
|
|
borrarCookie("logueado");
|
|
borrarCookie("usuario");
|
|
borrarCookie("token");
|
|
location.reload(true);
|
|
}
|
|
|
|
function unselectAll() {
|
|
var checkboxes = document.getElementsByClassName("codeFilterCheckBoxInput");
|
|
var i;
|
|
for (i = 0; i<checkboxes.length;i++){
|
|
if(checkboxes[i].type == "checkbox")
|
|
checkboxes[i].checked = false;
|
|
else{
|
|
checkboxes[i].onclick = selectAll;
|
|
checkboxes[i].innerHTML = "Select all";
|
|
}
|
|
}
|
|
getAjax();
|
|
}
|
|
|
|
function selectAll() {
|
|
var checkboxes = document.getElementsByClassName("codeFilterCheckBoxInput");
|
|
var i;
|
|
for (i = 0; i<checkboxes.length;i++){
|
|
if(checkboxes[i].type == "checkbox")
|
|
checkboxes[i].checked = true;
|
|
else{
|
|
checkboxes[i].onclick = unselectAll;
|
|
checkboxes[i].innerHTML = "Unselect all";
|
|
}
|
|
}
|
|
getAjax();
|
|
} |