- Datepicker - Using a default function with a custom function
- var $myBadDates = new Array (<?php foreach($aryDates as $disabledate) { echo " "$disabledate","; } echo " 1"; ?>); //Creates the array (The echo " 1"; is merely to close the array and will not affect the outcome
- function checkAvailability(mydate)
- {
- var $return=true;
- var $returnclass ="available";
- $checkdate = $.datepicker.formatDate('yy-mm-dd', mydate);
- for(var i = 0; i < $myBadDates.length; i++)
- {
- if($myBadDates[i] == $checkdate)
- {
- $return = false;
- $returnclass= "unavailable";
- }
- }
- return [$return,$returnclass];
- }
- $(function()
- {
- //To enable End Date picker only when Start Date has been chosen (And to disable all dates prior of said date)
- var end = $('#enddate').datepicker( {numberOfMonths: 3, stepMonths: 3, beforeShowDay: checkAvailability,});
- // Defining a function, because we're binding this to two different events
- function enableEnd() {
- end.attr('disabled', !this.value.length) // Enable the end input element if the first one has anything in it
- .datepicker('option', 'minDate', this.value); // Set the minimum date to the date in the first input
- }
- //End of function
- // Datepicker
- $('#startdate').datepicker({
- numberOfMonths: 3,
- stepMonths: 3,
- beforeShowDay: checkAvailability,
- minDate: +1,
- onSelect: enableEnd // Call enableEnd when a date is selected in the first datepicker
- }).bind('input', enableEnd); // Do the same when something is inputted by the user
- //hover states on the static widgets
- $('#dialog_link, ul#icons li').hover(
- function() {$(this).toggleClass('ui-state-hover');}
- );
- });
- //End of Function
- function checkAvailability(d) {
- if (
- d.getDay() == 6 /* saturday */ ||
- d.getDay() == 0 /* sunday */
- ) {
- return [false,'unavailable unavailable-cuz-its-weekend'];
- }
- $checkdate = $.datepicker.formatDate('yy-mm-dd', d);
- for (var i = 0; i < $myBadDates.length; i++) {
- if($myBadDates[i] == $checkdate)
- {
- return [false, "unavailable"];
- }
- }
- return [true, "available"];
- }