/**
* Interfase con el usuario
* Monografias.com
*
* @author Daniela Rodriguez Careri
* @requires jQuery
*
*/
// TODO: Eliminar llamadas a funciones heredadas
// TODO: Implemementar minificador
// TODO: Implementar lazy loading y test de presencia en una sola funcion
var mono = {
version : "1.5.1.0"
};
mono.CFG = {};
mono.CFG.IS_DEVEL = (window.location.host.indexOf("stage1") !== -1);
mono.CFG.IS_EXTERNAL = (window.location.host.indexOf("www") == -1);
mono.CFG.IS_BLOGS = (window.location.host.indexOf("blogs") !== -1);
if (mono.CFG.IS_EXTERNAL && mono.CFG.IS_DEVEL) {
mono.CFG.URL_MONO = "http://www.stage1.monografias.com/";
} else if (mono.CFG.IS_EXTERNAL && !mono.CFG.IS_DEVEL) {
mono.CFG.URL_MONO = "http://www.monografias.com/";
} else {
mono.CFG.URL_MONO = "/";
}
mono.CFG.DEBUG = true && mono.CFG.IS_DEVEL;
mono.CFG.URL_BASE = "/";
mono.CFG.URL_LOGIN = mono.CFG.URL_MONO + "usuario/login";
mono.CFG.URL_REGISTRO = mono.CFG.URL_MONO + "usuario/registro";
mono.CFG.URL_RANDOM = mono.CFG.URL_MONO + "random/";
mono.CFG.URL_JAVASCRIPT = mono.CFG.URL_RANDOM + "js/";
mono.CFG.COMENTARIOS_MAX_CAPS = 70; // m�ximo porcentaje de caracteres en mayusculas tolerables en un comentario
mono.MSG_TYPE = { ADVERTENCIA: "advert", INFORMACION: "informacion", ERROR: "error", STOP: "stop", PROCESANDO: "procesando"}
/***********************************************************************************************************************
* Constantes idioma
*/
mono.msg = {
ERROR_500 : "Ha ocurrido un error en el servidor. Por favor, vuelva a intentar en unos minutos.",
ERROR_403_COMENTARIO : "Para dejar un comentario debe iniciar sesión.",
ERROR_403_DENUNCIA : "Para denunciar un comentario, debe iniciar sesion.",
ERROR_403_VOTAR : "Para poder votar, debe iniciar sesion.",
ERROR_400_COMENTARIO : "Antes de enviar, escriba el comentario.",
ERROR_AUTENTICACION : "El usuario y la contraseña no coinciden.",
ERROR_SERVIDOR : "Ocurrió un error en Monografias.com. Por favor, espere unos instantes e intente nuevamente.",
ERROR_FALTA_EMAIL : "Falta escribir el e-mail.",
ERROR_FALTA_PASS : "Falta escribir la contraseña.",
PLEASE_WAIT : "Aguarde un instante por favor...",
CONFIRMA_DENUNCIA : "Confirme por favor que este comentario viola los Terminos y Condiciones de Monografias.com",
DENUNCIA_ENVIADA : " | Comentario denunciado",
NO_VOTAR_DOBLE : "No puede votar el mismo comentario dos veces",
CTRL_D_FAVORITO : "Presione Aceptar y luego CTRL + D para agregar esta p�gina a sus favoritos.",
REGISTRESE : "¡Regístrese!",
INICIAR_SESION : "Iniciar sesión",
SALIR : "Salir"
}
/***********************************************************************************************************************
* Algunas utilidades
*/
mono.util = {
getCookie : function(nombre) {
var results = document.cookie.match ( '(^|;) ?' + nombre + '=([^;]*)(;|$)' );
if (results) {
return (unescape(results[2]));
} else {
return null;
}
},
setCookie : function(nombre, value, neverexpires) {
var cookie_string = nombre + "=" + escape(value) + "; path=/";
if (neverexpires) {
var cookie_date = new Date();
cookie_date.setDate (cookie_date.getDate() + 365 );
cookie_string += "; expires=" + cookie_date.toGMTString() + "; path=/";
}
document.cookie = cookie_string;
},
deleteCookie : function(nombre) {
var cookie_date = new Date();
cookie_date.setDate(cookie_date.getDate() - 1 );
console.log(cookie_date.toGMTString());
document.cookie = nombre += "=; expires=" + cookie_date.toGMTString() + "; path=/";
},
sanearTexto : function(t) {
var mayus = t.match(/[A-Z]/g);
if (mayus) {
var cantMayus = mayus.length;
var total = t.length;
if ( ((cantMayus/total)*100) > mono.CFG.COMENTARIOS_MAX_CAPS ) {
t = t.charAt(0).toUpperCase() + t.substr(1).toLowerCase(); // HOLA --> Hola
}
}
t = t.replace(/([A-Za-z0-9,\.!\?\$\-])\1{5,}/g, "$1"+"$1"+"$1"+"$1"); // Holaaaaaaaaaaaaaa --> Holaaaa
return t;
},
createMsg : function(mensaje, tipo, opt) {
var opciones = {};
opciones.cerrar = opt ? opt.cerrar : false;
opciones.dismiss = opt ? opt.dismiss : false;
$texto = $("");
$texto.html(mensaje);
$msg = $("");
$msg.addClass("mensaje-de").addClass(tipo);
if (opciones.cerrar) $msg.addClass('con-cerrar');
if (opciones.dismiss) $msg.addClass('con-dismiss');
$msg.html($texto);
return ($msg);
},
agregarFavorito : function() {
var titulo = document.title;
var url = parent.location.href;
if (url == "http://www.monografias.com/") { titulo = "Monografias.com"; }
if (document.all) {
window.external.AddFavorite(url, titulo);
} else {
alert(mono.msg.CTRL_D_FAVORITO);
}
},
base64encode : function (input) {
_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
while (i > 2;
enc2 = ((chr1 & 3) > 4);
enc3 = ((chr2 & 15) > 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
}
return output;
},
evalResultData : function (texto) {
var rx = (texto.replace(/\r|\n|\r\n|\t/g, ""));
try {
var r = eval( "(" + rx + ")" );
return (r);
} catch(ex) {
return false;
}
},
// Todas las llamadas a window.registro enviadas a esta funcion
// que a su vez, ya no abre mas el popup de registro, sino que lleva
// al nuevo formulario de registro en sistema de perfiles
registroRedirect : function() {
mono.console.log ("Se llamo a la funcion obsoleta registro()");
window.location = mono.CFG.URL_REGISTRO;
},
// TODO: popup y registro son heredadas, optimizar en una sola
popup : function(url) {
cuteLittleWindow = window.open(url, "littleWindow", "location=no,width=390,height=470,scrollbars=yes");
},
registro : function(url) {
cuteLittleWindow = window.open(url, "littleWindow", "location=no,width=415,height=475,scrollbars=yes");
}
}
/***********************************************************************************************************************
* Funciones de interfase con el usuario
*/
mono.ui = {
activarAjaxLogin : function() {
$.fn.colorbox.settings.bgOpacity = 0.60;
$.fn.colorbox.settings.transition = "elastic";
$("#js-login").colorbox({
contentWidth:"500px",
contentHeight:"210px",
//contentAjax: mono.CFG.URL_JAVASCRIPT + "/inc_loginform.html", // no porque no respeta autocomplete
//contentIframe: mono.CFG.URL_JAVASCRIPT + "/inc_loginform.html", // no porque se complica demasiado comunicarse con el iframe
contentInline:"#login-box-container .login-box",
afterShowCallback : function() {
var $form = $("#js-loginform", "#colorbox");
var $notificacion = $(".login-box .notificacion", "#colorbox");
// Enviar login
$form.submit(function(e) {
e.preventDefault();
$notificacion.html(mono.util.createMsg(mono.msg.PLEASE_WAIT, mono.MSG_TYPE.PROCESANDO));
$form.desactivar();
var errores = "";
var email = $(":input[name='email']", $form).val();
var pass = $(":input[name='password']", $form).val();
var recordar = $(":input[name='recordar']", $form).attr("checked") ? 1 : 0;
if (!email) { errores += mono.msg.ERROR_FALTA_EMAIL; }
if (!pass) { errores += " " + mono.msg.ERROR_FALTA_PASS; }
if (errores) {
$notificacion.html(mono.util.createMsg(errores, mono.MSG_TYPE.ERROR));
$notificacion.show();
$form.activar();
return false;
} else {
if (mono.CFG.IS_EXTERNAL) { // si no estamos en el dominio raiz, logueamos por JSONP
var queryString = mono.CFG.URL_LOGIN + "?email=" + email +
"&password=" + mono.util.base64encode(pass) + "&recordar=" + recordar + "&jsoncallback=?";
$.getJSON(queryString, function(response) {
mono.ui.handleLoginResult(response);
});
} else { // sino, via ajax
$.ajax({
url : mono.CFG.URL_LOGIN,
type : "POST",
data : $form.serialize(),
success : function(response) {
mono.ui.handleLoginResult(mono.util.evalResultData(response));
},
error : function(XHR, estado, error) {
mono.console.log (XHR, estado, error);
switch (XHR.status) {
case 401 : {
$notificacion.html(mono.util.createMsg(mono.msg.ERROR_AUTENTICACION, mono.MSG_TYPE.ERROR));
$notificacion.show();
$form.activar();
} break;
default : {
$notificacion.html(mono.util.createMsg(mono.msg.ERROR_SERVIDOR, mono.MSG_TYPE.ERROR));
$notificacion.show();
$form.activar();
} break;
}
}
}); // ajax
} // if external
} // if errores
}); // submit handler
} // aftershowcallback
});//colorbox
if (mono.CFG.IS_BLOGS) { // Cualquier otro clic en "iniciar sesion" en blogs debe disparar el cuadro ajax
$(".js-login-blogs").click(function(e) {
e.preventDefault();
$("#js-login").trigger("click");
});
}
if (mono.temp_mono_id) { // hack para ticket #128: Clic en "inicie sesion" en monografias tambien debe disparar el cuadro ajax
$("#js-inicia-primero a:eq(1)").click(function(e) {
e.preventDefault();
$("#js-login").trigger("click");
});
}
},
handleLoginResult : function(response) {
mono.console.dir(response);
var $form = $("#js-loginform", "#colorbox");
var $notificacion = $(".login-box .notificacion", "#colorbox");
if (response.result) {
location.reload(); // si logueo exitoso por ahora actualizar la pagina
// TODO: refrescar por javascript lo que haga falta (sera viable?)
} else {
$notificacion.html(mono.util.createMsg(mono.msg.ERROR_AUTENTICACION, mono.MSG_TYPE.ERROR));
$notificacion.show();
$form.activar();
}
},
// Traer en un IFrame la página para recomendar
invitarAmigoAjax : function() {
$.fn.colorbox.settings.bgOpacity = 0.60;
$.fn.colorbox.settings.transition = "elastic";
$("#js-invitar-amigo").colorbox({
contentWidth:"400px",
contentHeight:"400px",
contentIframe: mono.CFG.URL_BASE + "cgi-bin2/recomendar.pl"
});
}
};
/***********************************************************************************************************************
* Activar la interfase con el usuario para todas las paginas
*/
mono.setHandlers = function() {
// Login
if (mono.TEMP.usuario) {
var $loginregister = $('
' +
mono.TEMP.usuario.firstname + (mono.TEMP.usuario.lastname ? " " +
(mono.TEMP.usuario.lastname.length > 20 ? mono.TEMP.usuario.lastname.split(" ")[0] : mono.TEMP.usuario.lastname) : "") +
' | ' + mono.msg.SALIR + '');
$("#Idioma").html($loginregister);
} else {
var $loginregister = $('
' +
mono.msg.REGISTRESE + ' | ' +
mono.msg.INICIAR_SESION + '');
$("#Idioma").html($loginregister);
if ($("#login-box-container").length) { // activar el login por ajax solo si se encuentra presente el formulario
$.getScript(mono.CFG.URL_JAVASCRIPT + "jquery.colorbox.js", function() {
setTimeout(mono.ui.activarAjaxLogin, 500);
});
}
}
//"Invitar un amigo"
if (jQuery.fn.colorbox) {
mono.ui.invitarAmigoAjax();
} else {
$.getScript(mono.CFG.URL_JAVASCRIPT + "jquery.colorbox.js", function() {
setTimeout(mono.ui.invitarAmigoAjax, 500);
});
}
// Reemplazar [arroba] por @
// Lo habia hecho en jQuery (11ms), pero nativo es mas rapido (3ms)
var maildivider="[arroba]";
var href;
for (i=0; i" + t + "
");
//$("#mono_debug_console .inner").scrollTo({top:'+=20px'});
},
"info": function(){},
"warn": function(){},
"error": function(){},
"assert": function(){},
"dir": function(){},
"dirxml": function(){},
"group": function(){},
"groupEnd": function(){},
"time": function(){},
"timeEnd": function(){},
"count": function(){},
"trace": function(){},
"profile": function(){},
"profileEnd": function(){}
}
$(document).ready(function() {
var $consola = $('');
$("body").append($consola);
$("#mono_debug_console .show_hide").bind("click", function(e){
$("#mono_debug_console").toggleClass("abierto").find(".inner").toggle();
});
});
} else {
// O la consola de Firebug para Firefox
mono.console = console;
}
} else {
// con debug desactivado todas las llamadas a consola se env�an a la nada
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
mono.console = {};
for (var i = 0; i
[ gobierno de chile | metro valencia | tolerancia | soledad | venta de empresas ]
horoscopos
diseņo grafico valencia