Skip to content

Instantly share code, notes, and snippets.

@matherton
Created February 5, 2014 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matherton/8823088 to your computer and use it in GitHub Desktop.
Save matherton/8823088 to your computer and use it in GitHub Desktop.
JS functions completed HKE
/* Start of live datepicker function */
var datePicker = $(function() {
$( "#from, #to" ).datepicker({
defaultDate: "+0w",
changeMonth: false,
dateFormat: 'mm-dd-yy',
numberOfMonths: 2,
minDate: 0, // the minimum selection date
onSelect: function( selectedDate ) {
if(this.id == 'from'){
var dateMin = $('#from').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 1);
var newDate = $(this).datepicker('getDate');
if (newDate) { // Not null
newDate.setDate(newDate.getDate() + 0);
}
//$('#to').datepicker("option","minDate",rMin);
//$('#to').datepicker("option","maxDate",rMax);
//$('#from').datepicker().val($.datepicker.formatDate('mm-dd-yy');
$('#to').datepicker('option', 'minDate', newDate).val($.datepicker.formatDate('mm-dd-yy', new Date(rMin)));
//ABOVE Selector: 1. sets the datepicker for #to so all dates prior to date selected in #from to unselectable
// 2. selects date selected in #from adds 1 to it and placeas it in #to so that the from field displays the next da by default
}
}
});
});
/* end of live datepicker function */
/* start of named AJAX loader function NOTE: the page that you call this on requires /js/jquery1.10.2.js */
var ajaxLoader = $(document).ready(function(){
$(document).ajaxStart(function(){
$("#plane-border").css("display","block");
});
$(document).ajaxComplete(function(){
$("#plane-border").css("display","block");
});
//change ID btnSearch to class or ID of element that loads the AJAX content
$("#btnSearch").click(function(){
$(".blank").load("loading.php"); //change loading.php to content you want to load
});
});
/* end of named AJAX loader function */
/* start of validator() function */
function validator() {
var passExpire = document.getElementById('month').value+'-'+document.getElementById('day').value+'-'+document.getElementById('year').value;
var departDate = document.getElementById('dflightDate').value;
var returnDate = document.getElementById('rflightDate').value;
if (passExpire < departDate) {
alert("You cannot book a flight if your passport expires before your departure date!");
window.location="booking-search.html";
}
else if (passExpire < returnDate) {
alert("You cannot book a return flight if your passport expires before you return!");
window.location="booking-search.html";
}
else {
alert("Passport expiry date is after the flight date - Have a nice flight!");
}
//testing I have the correct vars
//document.write(departDate);
//document.write(returnDate);
//document.write(returnDate);
}
/* end of validator() function */
/* start of disable return datepicker */
(function($) {
$.fn.toggleDisabled = function() {
return this.each(function() {
var $this = $(this);
if ($this.attr('disabled')) $this.removeAttr('disabled');
else $this.attr('disabled', 'disabled');
});
};
})(jQuery);
$(function() {
$('#one_way').click(function() {
$('#to').toggleDisabled();
});
$('#return').click(function() {
$('#to').removeAttr('disabled');
});
});
/* end of disable return datepicker */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment