Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/09/2012, 12:40
Darkmarine
 
Fecha de Ingreso: septiembre-2009
Mensajes: 27
Antigüedad: 14 años, 8 meses
Puntos: 0
Exclamación javascript no funciona despues de cargar contenido con ajax

Como he dicho en el título tengo un calendario el cual tiene eventos, y al pasar por encima del dia, si es que hay algo sale un popup con información de el. Todo funciona correctamente, hasta que cargo por ajax otro mes, en ese momento el javascript presupongo que ya no lo carga y no se como hacer para cargarlo.

La página web con el calendario es la siguiente http://mrparty.es/eventos.php

En eventos.php tengo este código

Código:
                            <div id="calendariomes">
							<?php include('includes/carga-calendario.php');?>
                            </div>
y carga este contenido, la primera vez es un include normal, pero luego segun cambio de mes lo carga por ajax

Código:
<?php 
include_once('includes.php');
?>
<?php
include('calendar.php');
if (isset($_GET['mes'])){
	$mes = $_GET['mes'];	
}else{
	$mes = date('Y-m-j');
	//$mes = "14-08-2012";
	
}
$calendar = new Calendar($mes);
setlocale(LC_ALL, 'es_ES'); // Spanish
$calendar->week_start = 1;
$compruebo_eventos = dame_lista('eventos','ev_id',0,'ev_activo=1','ev_fecha DESC');
$cc_eventos = count($compruebo_eventos);

for($y=0;$y<$cc_eventos;$y++){
	$dias_eventos[] = dame_campo('eventos','ev_fecha','ev_id='.$compruebo_eventos[$y]);	
}
$calendar->highlighted_dates = $dias_eventos;	
print($calendar->output_calendar());
?>
el calendario es una clase que no la voy a poner porque es muy larga pero digamos que construye todo el calendario. Solo pongo el enlace para que veais que llamo a la función.

Código:
onclick=\"cargarCalendario('".date("Y-m-d", strtotime("$mes -1 month"))."')\"
y la función para sacar información de cada día, que es lo que falla al cambiar d mes es la siguiente

Código:
$(function () {
	$('.date_has_event').each(function () {
		// options
		var distance = 10;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = $(this);
		var popup = $('.events ul', this).css('opacity', 0);

		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				popup.css({
					bottom: 20,
					left: -76,
					display: 'block' // brings the popup back in to view
				})

				// (we're using chaining on the popup) now animate it's opacity and position
				.animate({
					bottom: '+=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					// once the animation is complete, set the tracker variables
					beingShown = false;
					shown = true;
				});
			}
		}).mouseout(function () {
			// reset the timer if we get fired again - avoids double animations
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					bottom: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					// once the animate is complete, set the tracker variables
					shown = false;
					// hide the popup entirely after the effect (opacity alone doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});
});
Espero que podais solucionarme el problema, por lo que he buscado por internet hablan de algo como .live pero la verdad es que ando perdidísimo en js, un saludo!