Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/01/2012, 16:11
bartman742
 
Fecha de Ingreso: enero-2012
Mensajes: 64
Antigüedad: 12 años, 3 meses
Puntos: 0
Respuesta: calendario jquery

Código Javascript:
Ver original
  1. dpSetDisabled : function(s)
  2.         {
  3.             return _w.call(this, 'setDisabled', s);
  4.         },
  5.  
  6.         dpSetStartDate : function(d)
  7.         {
  8.             return _w.call(this, 'setStartDate', d);
  9.         },
  10.  
  11.         dpSetEndDate : function(d)
  12.         {
  13.             return _w.call(this, 'setEndDate', d);
  14.         },
  15.  
  16.         dpGetSelected : function()
  17.         {
  18.             var c = _getController(this[0]);
  19.             if (c) {
  20.                 return c.getSelected();
  21.             }
  22.             return null;
  23.         },
  24.  
  25.         dpSetSelected : function(d, v, m, e)
  26.         {
  27.             if (v == undefined) v=true;
  28.             if (m == undefined) m=true;
  29.             if (e == undefined) e=true;
  30.             return _w.call(this, 'setSelected', Date.fromString(d), v, m, e);
  31.         },
  32.  
  33.         dpSetDisplayedMonth : function(m, y)
  34.         {
  35.             return _w.call(this, 'setDisplayedMonth', Number(m), Number(y), true);
  36.         },
  37.  
  38.         dpDisplay : function(e)
  39.         {
  40.             return _w.call(this, 'display', e);
  41.         },
  42.  
  43.         dpSetRenderCallback : function(a)
  44.         {
  45.             return _w.call(this, 'setRenderCallback', a);
  46.         },
  47.  
  48.         dpSetPosition : function(v, h)
  49.         {
  50.             return _w.call(this, 'setPosition', v, h);
  51.         },
  52.  
  53.         dpSetOffset : function(v, h)
  54.         {
  55.             return _w.call(this, 'setOffset', v, h);
  56.         },
  57.  
  58.         dpClose : function()
  59.         {
  60.             return _w.call(this, '_closeCalendar', false, this[0]);
  61.         },
  62.  
  63.         dpRerenderCalendar : function()
  64.         {
  65.             return _w.call(this, '_rerenderCalendar');
  66.         },
  67.         // private function called on unload to clean up any expandos etc and prevent memory links...
  68.         _dpDestroy : function()
  69.         {
  70.             // TODO - implement this?
  71.         }
  72.     });
  73.    
  74.    
  75.     var _w = function(f, a1, a2, a3, a4)
  76.     {
  77.         return this.each(
  78.             function()
  79.             {
  80.                 var c = _getController(this);
  81.                 if (c) {
  82.                     c[f](a1, a2, a3, a4);
  83.                 }
  84.             }
  85.         );
  86.     };
  87.    
  88.     function DatePicker(ele)
  89.     {
  90.         this.ele = ele;
  91.        
  92.         // initial values...
  93.         this.displayedMonth     =   null;
  94.         this.displayedYear      =   null;
  95.         this.startDate          =   null;
  96.         this.endDate            =   null;
  97.         this.showYearNavigation =   null;
  98.         this.closeOnSelect      =   null;
  99.         this.displayClose       =   null;
  100.         this.rememberViewedMonth=   null;
  101.         this.selectMultiple     =   null;
  102.         this.numSelectable      =   null;
  103.         this.numSelected        =   null;
  104.         this.verticalPosition   =   null;
  105.         this.horizontalPosition =   null;
  106.         this.verticalOffset     =   null;
  107.         this.horizontalOffset   =   null;
  108.         this.button             =   null;
  109.         this.renderCallback     =   [];
  110.         this.selectedDates      =   {};
  111.         this.inline             =   null;
  112.         this.context            =   '#dp-popup';
  113.         this.settings           =   {};
  114.     };
  115.     $.extend(
  116.         DatePicker.prototype,
  117.         {  
  118.             init : function(s)
  119.             {
  120.                 this.setStartDate(s.startDate);
  121.                 this.setEndDate(s.endDate);
  122.                 this.setDisplayedMonth(Number(s.month), Number(s.year));
  123.                 this.setRenderCallback(s.renderCallback);
  124.                 this.showYearNavigation = s.showYearNavigation;
  125.                 this.closeOnSelect = s.closeOnSelect;
  126.                 this.displayClose = s.displayClose;
  127.                 this.rememberViewedMonth =  s.rememberViewedMonth;
  128.                 this.selectMultiple = s.selectMultiple;
  129.                 this.numSelectable = s.selectMultiple ? s.numSelectable : 1;
  130.                 this.numSelected = 0;
  131.                 this.verticalPosition = s.verticalPosition;
  132.                 this.horizontalPosition = s.horizontalPosition;
  133.                 this.hoverClass = s.hoverClass;
  134.                 this.setOffset(s.verticalOffset, s.horizontalOffset);
  135.                 this.inline = s.inline;
  136.                 this.settings = s;
  137.                 if (this.inline) {
  138.                     this.context = this.ele;
  139.                     this.display();
  140.                 }
  141.             },
  142.             setStartDate : function(d)
  143.             {
  144.                 if (d) {
  145.                     if (d instanceof Date) {
  146.                         this.startDate = d;
  147.                     } else {
  148.                         this.startDate = Date.fromString(d);
  149.                     }
  150.                 }
  151.                 if (!this.startDate) {
  152.                     this.startDate = (new Date()).zeroTime();
  153.                 }
  154.                 this.setDisplayedMonth(this.displayedMonth, this.displayedYear);
  155.             },
  156.             setEndDate : function(d)
  157.             {
  158.                 if (d) {
  159.                     if (d instanceof Date) {
  160.                         this.endDate = d;
  161.                     } else {
  162.                         this.endDate = Date.fromString(d);
  163.                     }
  164.                 }
  165.                 if (!this.endDate) {
  166.                     this.endDate = (new Date('12/31/2999')); // using the JS Date.parse function which expects mm/dd/yyyy
  167.                 }
  168.                 if (this.endDate.getTime() < this.startDate.getTime()) {
  169.                     this.endDate = this.startDate;
  170.                 }
  171.                 this.setDisplayedMonth(this.displayedMonth, this.displayedYear);
  172.             },
  173.             setPosition : function(v, h)
  174.             {
  175.                 this.verticalPosition = v;
  176.                 this.horizontalPosition = h;
  177.             },
  178.             setOffset : function(v, h)
  179.             {
  180.                 this.verticalOffset = parseInt(v) || 0;
  181.                 this.horizontalOffset = parseInt(h) || 0;
  182.             },
  183.             setDisabled : function(s)
  184.             {
  185.                 $e = $(this.ele);
  186.                 $e[s ? 'addClass' : 'removeClass']('dp-disabled');
  187.                 if (this.button) {
  188.                     $but = $(this.button);
  189.                     $but[s ? 'addClass' : 'removeClass']('dp-disabled');
  190.                     $but.attr('title', s ? '' : $.dpText.TEXT_CHOOSE_DATE);
  191.                 }
  192.                 if ($e.is(':text')) {
  193.                     $e.attr('disabled', s ? 'disabled' : '');
  194.                 }
  195.             },
  196.             setDisplayedMonth : function(m, y, rerender)
  197.             {
  198.                 if (this.startDate == undefined || this.endDate == undefined) {
  199.                     return;
  200.                 }
  201.                 var s = new Date(this.startDate.getTime());
  202.                 s.setDate(1);
  203.                 var e = new Date(this.endDate.getTime());
  204.                 e.setDate(1);
  205.                
  206.                 var t;
  207.                 if ((!m && !y) || (isNaN(m) && isNaN(y))) {
  208.                     // no month or year passed - default to current month
  209.                     t = new Date().zeroTime();
  210.                     t.setDate(1);
  211.                 } else if (isNaN(m)) {
  212.                     // just year passed in - presume we want the displayedMonth
  213.                     t = new Date(y, this.displayedMonth, 1);
  214.                 } else if (isNaN(y)) {
  215.                     // just month passed in - presume we want the displayedYear
  216.                     t = new Date(this.displayedYear, m, 1);
  217.                 } else {
  218.                     // year and month passed in - that's the date we want!
  219.                     t = new Date(y, m, 1)
  220.                 }
  221.                 // check if the desired date is within the range of our defined startDate and endDate
  222.                 if (t.getTime() < s.getTime()) {
  223.                     t = s;
  224.                 } else if (t.getTime() > e.getTime()) {
  225.                     t = e;
  226.                 }
  227.                 var oldMonth = this.displayedMonth;
  228.                 var oldYear = this.displayedYear;
  229.                 this.displayedMonth = t.getMonth();
  230.                 this.displayedYear = t.getFullYear();
  231.  
  232.                 if (rerender && (this.displayedMonth != oldMonth || this.displayedYear != oldYear))
  233.                 {
  234.                     this._rerenderCalendar();
  235.                     $(this.ele).trigger('dpMonthChanged', [this.displayedMonth, this.displayedYear]);
  236.                 }
  237.             },
  238.             setSelected : function(d, v, moveToMonth, dispatchEvents)
  239.             {
  240.                 if (d < this.startDate || d.zeroTime() > this.endDate.zeroTime()) {
  241.                     // Don't allow people to select dates outside range...
  242.                     return;
  243.                 }
  244.                 var s = this.settings;
  245.                 if (s.selectWeek)
  246.                 {
  247.                     d = d.addDays(- (d.getDay() - Date.firstDayOfWeek + 7) % 7);
  248.                     if (d < this.startDate) // The first day of this week is before the start date so is unselectable...
  249.                     {
  250.                         return;
  251.                     }
  252.                 }
  253.                 if (v == this.isSelected(d)) // this date is already un/selected
  254.                 {
  255.                     return;
  256.                 }
  257.                 if (this.selectMultiple == false) {
  258.                     this.clearSelected();
  259.                 } else if (v && this.numSelected == this.numSelectable) {
  260.                     // can't select any more dates...
  261.                     return;
  262.                 }
  263.                 if (moveToMonth && (this.displayedMonth != d.getMonth() || this.displayedYear != d.getFullYear())) {
  264.                     this.setDisplayedMonth(d.getMonth(), d.getFullYear(), true);
  265.                 }
  266.                 this.selectedDates[d.asString()] = v;
  267.                 this.numSelected += v ? 1 : -1;
  268.                 var selectorString = 'td.' + (d.getMonth() == this.displayedMonth ? 'current-month' : 'other-month');
  269.                 var $td;
  270.                 $(selectorString, this.context).each(
  271.                     function()
  272.                     {
  273.                         if ($(this).data('datePickerDate') == d.asString()) {
  274.                             $td = $(this);
  275.                             if (s.selectWeek)
  276.                             {
  277.                                 $td.parent()[v ? 'addClass' : 'removeClass']('selectedWeek');
  278.                             }
  279.                             $td[v ? 'addClass' : 'removeClass']('selected');
  280.                         }
  281.                     }
  282.                 );
  283.                 $('td', this.context).not('.selected')[this.selectMultiple &&  this.numSelected == this.numSelectable ? 'addClass' : 'removeClass']('unselectable');
  284.                
  285.                 if (dispatchEvents)
  286.                 {
  287.                     var s = this.isSelected(d);
  288.                     $e = $(this.ele);
  289.                     var dClone = Date.fromString(d.asString());
  290.                     $e.trigger('dateSelected', [dClone, $td, s]);
  291.                     $e.trigger('change');
  292.                 }
  293.             },
  294.             isSelected : function(d)
  295.             {
  296.                 return this.selectedDates[d.asString()];
  297.             },
  298.             getSelected : function()
  299.             {
  300.                 var r = [];
  301.                 for(var s in this.selectedDates) {
  302.                     if (this.selectedDates[s] == true) {
  303.                         r.push(Date.fromString(s));
  304.                     }
  305.                 }
  306.                 return r;
  307.             },
  308.             clearSelected : function()
  309.             {
  310.                 this.selectedDates = {};
  311.                 this.numSelected = 0;
  312.                 $('td.selected', this.context).removeClass('selected').parent().removeClass('selectedWeek');
  313.             },