I need help with datePicker
Hi everybody !
I'm new on this forum, sorry if i'm not at the good place to post this.. and sorry for my english im french :)
So.. i need to developp à calendar with event associate on some day..
i make this with datePicker and look my calendar :
i create some event ( 3 in total ) and the color on days 1, 2 and 3 are day with event ! and when i click on a day with an event, i display event info in specific div. All is ok, that work, BUT when i click on a day with element, my div with color for event disapear.. :/
Check my code :
- (function($) {
- $(document).ready(function() {
- var events = [
- {
- Title: "Événement 1",
- Date: new Date("10/01/2016"),
- Lieu: "Paris",
- Extrait: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
- Type: "Régionaux",
- Day: "1"
- },
- {
- Title: "Événement 2",
- Date: new Date("10/02/2016"),
- Lieu: "Toulouse",
- Extrait: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
- Type: "Divers",
- Day: "2"
- },
- {
- Title: "Événement 3",
- Date: new Date("10/03/2016"),
- Lieu: "Marseille",
- Extrait: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
- Type: "Nationaux",
- Day: "3"
- }
- ];
- $("#cal_content").datepicker({
- dayNamesMin: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ],
- monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ],
- nextText: "Suivant",
- prevText: "Précédent",
- beforeShowDay: function(date) {
- var result = [true, '', null];
- var matching = $.grep(events, function(event) {
- return event.Date.valueOf() === date.valueOf();
- });
- if (matching.length) {
- result = [true, 'highlight', null];
- }
- return result;
- },
- onSelect: function(dateText) {
- var date,
- selectedDate = new Date(dateText),
- i = 0,
- event = null;
- /* Determine if the user clicked an event: */
- while (i < events.length && !event) {
- date = events[i].Date;
- if (selectedDate.valueOf() === date.valueOf()) {
- //console.log('clicked');
- event = events[i];
- }else{
- //console.log('no clicked');
- }
- i++;
- }
- if (event) {
- /* If the event is defined, perform some action here; show a tooltip, navigate to a URL, etc. */
- //alert(event.Title);
- $('#cal_event_content').html(
- '<div class="event type_'+event.Type+'">'
- +'<span class="title">'+event.Title+'</span>'
- +'<span class="lieu">'+event.Lieu+'</span>'
- +'<span class="content">'+event.Extrait+'</span>'
- +'</div>'
- );
- }
- }
- });
- $(".ui-datepicker-calendar .ui-state-default").each(function () {
- //you can get the year using below code.
- var year = $(".ui-datepicker-year").first().html();
- var nb;
- for (nb = 0; nb < events.length; ++nb) {
- if ($(".ui-datepicker-month").first().html() == "Octobre" && $(this).html() == events[nb].Day) {
- //add custome text to date cell
- //$(this).parent().attr('data-type',"Nationaux");
- var type = events[nb].Type;
- $(this).after('<div class="puce_color '+type+'"></div>');
- }
- }
- });
- });
- })( jQuery );
On line 80, this is what i use to insert "puce_color" with good event type to add the small color on the good day..
But i don't know how to keep my "puce_color" after click a event day..
Can someone help me please ? Did am i on the good way ?
Thanks for help :)