IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Lien depuis un Datepicker


Sujet :

jQuery

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    51
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 51
    Par défaut Lien depuis un Datepicker
    Bonjour a tous,

    Je me bat pour essayer de faire en sorte que quand je clic sur une case d'un évenement sur mon datepicker, cela me retourne sur une url du genre

    events.php?events_id=x

    Je retourne par jzon l'id de l'events dans le scripts test.php

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    (function($){
    	/**
    	 * Returns a dictionary, where the keys are the day of the month,
    	 * and the value is the text.
    	 * @param year - The year of the events.
    	 * @param month - The month of the events.
    	 * @param calendarID - Events for a specific calendar.
    	 */
    	function getMonthEvents(year, month, calendarId, callback){
     
    		var param = "year="+year+"&month="+month;
    	    var event;
     
    		$.ajax({
    			type: "GET",
    			url: "test.php",
    			data : param,
    			dataType: "script",
    			error:function(msg){
    				alert( "Error !: " + msg );
    			},
    			success:function(data){
    				callback(data);
    			}
    		});
    	}
     
    	// Receives January->1
    	function addTipsys(year, month, calendarId){
    	   var theEvents = getMonthEvents(year, month, calendarId, function(data){
    	   	alert(data)
    	   	return data;
    	   });
    	   var theDateLinks = $('#' + calendarId + ' .ui-datepicker-calendar a');
    	   for(eventDay in theEvents){
    		  // Minus one, because the date in the tipies are regular dates (1-31)
    		  // and the links are 0-based.
    		  theDateLinks.eq(eventDay-1)  // select the right link
    			 .attr('original-title', theEvents[eventDay])  // set the text
    			 .tipsy({html: true, gravity: 'w'});   // init the tipsy, set your properties.
    	   }
    	}
     
    	// Because the the event `onChangeMonthYear` get's called before updating
    	// the items, we'll add our code after the elements get rebuilt. We will hook
    	// to the `_updateDatepicker` method in the `Datepicker`.
    	// Saves the original function.
    	var _updateDatepicker_o = $.datepicker._updateDatepicker;
    	// Replaces the function.
    	$.datepicker._updateDatepicker = function(inst){
    	   // First we call the original function from the appropiate context.
    	   _updateDatepicker_o.apply(this, [inst]);
    	   // No we can update the Tipsys.
    	   addTipsys(inst.drawYear, inst.drawMonth+1, inst.id);
    	};
     
    	// Finally the calendar initializer.
    	$(function(){
    	   // Creates the date picker, with your options.
    	   $("#datepicker").datepicker();
    	   // Gets the date and initializes the first round of tipsies.
    	   var currentDate = $('#datepicker').datepicker('getDate');
    	   // month+1 because the event considers January->1
    	   // Last element is null, because, it doesn't actualy get used in the hanlder.
    	   addTipsys(currentDate.getYear(), currentDate.getMonth()+1, 'datepicker');
    	});
     
    	})(jQuery);
    Si vous pouvez me mettre sur la voie, car la je crise ^^

    Merci d'avance

    Decad7

  2. #2
    Rédacteur

    Avatar de danielhagnoul
    Homme Profil pro
    Étudiant perpétuel
    Inscrit en
    Février 2009
    Messages
    6 389
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant perpétuel
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2009
    Messages : 6 389
    Billets dans le blog
    125
    Par défaut
    Bonsoir

    Si j'ai bien compris, il y a un bloc de code qui fait double emploi !

    Je vous suggère de tester deux solutions, la première ayant ma préférence.

    Première test :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    (function($){
    	/**
    	 * Returns a dictionary, where the keys are the day of the month,
    	 * and the value is the text.
    	 * @param year - The year of the events.
    	 * @param month - The month of the events.
    	 * @param calendarID - Events for a specific calendar.
    	 */
    	function getMonthEvents(year, month, calendarId, callback){
     
    		var param = "year="+year+"&month="+month;
    	    var event;
     
    		$.ajax({
    			type: "GET",
    			url: "test.php",
    			data : param,
    			dataType: "script",
    			error:function(msg){
    				alert( "Error !: " + msg );
    			},
    			success:function(data){
    				callback(data);
    			}
    		});
    	}
     
    	// Receives January->1
    	function addTipsys(year, month, calendarId){
    	   var theEvents = getMonthEvents(year, month, calendarId, function(data){
    	   	alert(data)
    	   	return data;
    	   });
    	   var theDateLinks = $('#' + calendarId + ' .ui-datepicker-calendar a');
    	   for(eventDay in theEvents){
    		  // Minus one, because the date in the tipies are regular dates (1-31)
    		  // and the links are 0-based.
    		  theDateLinks.eq(eventDay-1)  // select the right link
    			 .attr('original-title', theEvents[eventDay])  // set the text
    			 .tipsy({html: true, gravity: 'w'});   // init the tipsy, set your properties.
    	   }
    	}
     
     /*
     * Ce bloc de code peu orthodoxe est inutile, il fait double emploi !
     */
     /*
    	// Because the the event `onChangeMonthYear` get's called before updating
    	// the items, we'll add our code after the elements get rebuilt. We will hook
    	// to the `_updateDatepicker` method in the `Datepicker`.
    	// Saves the original function.
    	var _updateDatepicker_o = $.datepicker._updateDatepicker;
    	// Replaces the function.
    	$.datepicker._updateDatepicker = function(inst){
    	   // First we call the original function from the appropiate context.
    	   _updateDatepicker_o.apply(this, [inst]);
    	   // No we can update the Tipsys.
    	   addTipsys(inst.drawYear, inst.drawMonth+1, inst.id);
    	};
    */
     
    	// Finally the calendar initializer.
    	$(function(){
    		$( "#datepicker" ).datepicker({
    			onSelect: function( dateText, inst ){
    				// inst.currentDay est aussi disponible
    				addTipsys( inst.currentYear, inst.currentMonth + 1, inst.id );
    			}
    		});
    	});
     
    })(jQuery);
    Second test :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    (function($){
    	/**
    	 * Returns a dictionary, where the keys are the day of the month,
    	 * and the value is the text.
    	 * @param year - The year of the events.
    	 * @param month - The month of the events.
    	 * @param calendarID - Events for a specific calendar.
    	 */
    	function getMonthEvents(year, month, calendarId, callback){
     
    		var param = "year="+year+"&month="+month;
    	    var event;
     
    		$.ajax({
    			type: "GET",
    			url: "test.php",
    			data : param,
    			dataType: "script",
    			error:function(msg){
    				alert( "Error !: " + msg );
    			},
    			success:function(data){
    				callback(data);
    			}
    		});
    	}
     
    	// Receives January->1
    	function addTipsys(year, month, calendarId){
    	   var theEvents = getMonthEvents(year, month, calendarId, function(data){
    	   	alert(data)
    	   	return data;
    	   });
    	   var theDateLinks = $('#' + calendarId + ' .ui-datepicker-calendar a');
    	   for(eventDay in theEvents){
    		  // Minus one, because the date in the tipies are regular dates (1-31)
    		  // and the links are 0-based.
    		  theDateLinks.eq(eventDay-1)  // select the right link
    			 .attr('original-title', theEvents[eventDay])  // set the text
    			 .tipsy({html: true, gravity: 'w'});   // init the tipsy, set your properties.
    	   }
    	}
     
    	// Because the the event `onChangeMonthYear` get's called before updating
    	// the items, we'll add our code after the elements get rebuilt. We will hook
    	// to the `_updateDatepicker` method in the `Datepicker`.
    	// Saves the original function.
    	var _updateDatepicker_o = $.datepicker._updateDatepicker;
    	// Replaces the function.
    	$.datepicker._updateDatepicker = function(inst){
    	   // First we call the original function from the appropiate context.
    	   _updateDatepicker_o.apply(this, [inst]);
    	   // No we can update the Tipsys.
    	   addTipsys(inst.drawYear, inst.drawMonth+1, inst.id);
    	};
     
    	// Finally the calendar initializer.
    	$(function(){
    	   // Creates the date picker, with your options.
    	   $("#datepicker").datepicker();
     
    /*
    * Ne sert à rien ! aucune date n'a encore été choisie !
    * C'est _updateDatepicker_o ci-dessus qui fait le travail
    */
    /*
    	   // Gets the date and initializes the first round of tipsies.
    	   var currentDate = $('#datepicker').datepicker('getDate');
    	   // month+1 because the event considers January->1
    	   // Last element is null, because, it doesn't actualy get used in the hanlder.
    	   addTipsys(currentDate.getYear(), currentDate.getMonth()+1, 'datepicker');
    */
    	});
     
    	})(jQuery);

    Blog

    Sans l'analyse et la conception, la programmation est l'art d'ajouter des bogues à un fichier texte vide.
    (Louis Srygley : Without requirements or design, programming is the art of adding bugs to an empty text file.)

Discussions similaires

  1. [Tableaux] Lien depuis une image
    Par hedi_wazo2001 dans le forum Langage
    Réponses: 5
    Dernier message: 21/12/2006, 11h12
  2. [Mail] lien depuis un email
    Par gforce dans le forum Langage
    Réponses: 4
    Dernier message: 19/11/2006, 16h17
  3. Les liens depuis Thunderbird ne marchent pas
    Par Cazaux-Moutou-Philippe dans le forum Applications et environnements graphiques
    Réponses: 3
    Dernier message: 20/03/2006, 22h27
  4. Réponses: 4
    Dernier message: 09/11/2005, 18h44
  5. Liens depuis une base de donnée statique
    Par LucG dans le forum Access
    Réponses: 4
    Dernier message: 26/10/2005, 11h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo