Created
May 17, 2010 19:57
-
-
Save ixti/404161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* maxRange extension for $.datepick of Keith Wood (kbwood{at}iinet.com.au) | |
* http://keith-wood.name/datepick.html | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* License: GNU/GPLv3 or higher (http://www.gnu.org/lisenses/gpl.txt) | |
* | |
* Copyright (c) 2010 Aleksey V. Zapparov (ixti{at}member.fsf.org) | |
* http://www.ixti.ru | |
* | |
* Date: Mon May 17 21:45:01 CEST 2010 | |
*/ | |
;(function($) { | |
$.extend($.datepick, { | |
limitMaxRange: function(dates) { | |
var inst = $.data(this, $.datepick.dataName), | |
days = (inst.settings.maxRange || 0) - 1, | |
max = null; | |
// skip if maxRange was not specified or was less or equal 0 | |
if (0 > days) { return; } | |
// first run. preserve default maxDate | |
if (undefined === inst.defaultMaxDate) { | |
inst.defaultMaxDate = inst.get('maxDate'); | |
} | |
// reset maxDate with datepicker on cleaning | |
if (0 === dates.length) { | |
$(this).datepick('option', 'maxDate', inst.defaultMaxDate); | |
return; | |
} | |
// calculate maxDate if range picker was initiated | |
if (inst.pickingRange) { | |
max = new Date(dates[0].getTime() + (days*24*3600000)); | |
// dissallow new maxDate overlap default if it exists | |
if ((null !== inst.defaultMaxDate) | |
&& (0 < (max.getTime() - inst.defaultMaxDate.getTime()))) { | |
max = null; | |
} | |
} | |
inst.settings.maxDate = max || inst.defaultMaxDate; | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment