Correct appendText bug in destroy

Tidy if statements
This commit is contained in:
Keith Wood 2008-06-11 10:48:17 +00:00
parent 36dd1c8cb1
commit a3bd7194fb

View File

@ -182,7 +182,8 @@ $.extend(Datepicker.prototype, {
.unbind('keypress', this._doKeyPress); .unbind('keypress', this._doKeyPress);
var wrapper = $target.parents('.ui-datepicker-wrap'); var wrapper = $target.parents('.ui-datepicker-wrap');
if (wrapper) if (wrapper)
wrapper.replaceWith(wrapper.html()); wrapper.siblings('.ui-datepicker-append').replaceWith('').end()
.replaceWith(wrapper.html());
} else if (nodeName == 'div' || nodeName == 'span') } else if (nodeName == 'div' || nodeName == 'span')
$target.removeClass(this.markerClassName).empty(); $target.removeClass(this.markerClassName).empty();
if ($('input[_calId=' + calId + ']').length == 0) if ($('input[_calId=' + calId + ']').length == 0)
@ -258,9 +259,8 @@ $.extend(Datepicker.prototype, {
Date[2] - the current dates for a range */ Date[2] - the current dates for a range */
_getDateDatepicker: function(target) { _getDateDatepicker: function(target) {
var inst = this._getInst(target._calId); var inst = this._getInst(target._calId);
if (inst) { if (inst)
inst._setDateFromField($(target)); inst._setDateFromField($(target));
}
return (inst ? inst._getDate() : null); return (inst ? inst._getDate() : null);
}, },
@ -488,10 +488,9 @@ $.extend(Datepicker.prototype, {
_afterShow: function(inst) { _afterShow: function(inst) {
var numMonths = inst._getNumberOfMonths(); // fix width for dynamic number of date pickers var numMonths = inst._getNumberOfMonths(); // fix width for dynamic number of date pickers
inst._datepickerDiv.width(numMonths[1] * $('.ui-datepicker', inst._datepickerDiv[0])[0].offsetWidth); inst._datepickerDiv.width(numMonths[1] * $('.ui-datepicker', inst._datepickerDiv[0])[0].offsetWidth);
if ($.browser.msie && parseInt($.browser.version) < 7) { // fix IE < 7 select problems if ($.browser.msie && parseInt($.browser.version) < 7) // fix IE < 7 select problems
$('iframe.ui-datepicker-cover').css({width: inst._datepickerDiv.width() + 4, $('iframe.ui-datepicker-cover').css({width: inst._datepickerDiv.width() + 4,
height: inst._datepickerDiv.height() + 4}); height: inst._datepickerDiv.height() + 4});
}
// re-position on screen if necessary // re-position on screen if necessary
var isFixed = inst._datepickerDiv.css('position') == 'fixed'; var isFixed = inst._datepickerDiv.css('position') == 'fixed';
var pos = inst._input ? $.datepicker._findPos(inst._input[0]) : null; var pos = inst._input ? $.datepicker._findPos(inst._input[0]) : null;
@ -502,19 +501,17 @@ $.extend(Datepicker.prototype, {
// reposition date picker horizontally if outside the browser window // reposition date picker horizontally if outside the browser window
if ((inst._datepickerDiv.offset().left + inst._datepickerDiv.width() - if ((inst._datepickerDiv.offset().left + inst._datepickerDiv.width() -
(isFixed && $.browser.msie ? document.documentElement.scrollLeft : 0)) > (isFixed && $.browser.msie ? document.documentElement.scrollLeft : 0)) >
(browserWidth + scrollX)) { (browserWidth + scrollX))
inst._datepickerDiv.css('left', Math.max(scrollX, inst._datepickerDiv.css('left', Math.max(scrollX,
pos[0] + (inst._input ? $(inst._input[0]).width() : null) - inst._datepickerDiv.width() - pos[0] + (inst._input ? $(inst._input[0]).width() : null) - inst._datepickerDiv.width() -
(isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0)) + 'px'); (isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0)) + 'px');
}
// reposition date picker vertically if outside the browser window // reposition date picker vertically if outside the browser window
if ((inst._datepickerDiv.offset().top + inst._datepickerDiv.height() - if ((inst._datepickerDiv.offset().top + inst._datepickerDiv.height() -
(isFixed && $.browser.msie ? document.documentElement.scrollTop : 0)) > (isFixed && $.browser.msie ? document.documentElement.scrollTop : 0)) >
(browserHeight + scrollY) ) { (browserHeight + scrollY))
inst._datepickerDiv.css('top', Math.max(scrollY, inst._datepickerDiv.css('top', Math.max(scrollY,
pos[1] - (this._inDialog ? 0 : inst._datepickerDiv.height()) - pos[1] - (this._inDialog ? 0 : inst._datepickerDiv.height()) -
(isFixed && $.browser.opera ? document.documentElement.scrollTop : 0)) + 'px'); (isFixed && $.browser.opera ? document.documentElement.scrollTop : 0)) + 'px');
}
}, },
/* Find an object's position on the screen. */ /* Find an object's position on the screen. */
@ -534,10 +531,9 @@ $.extend(Datepicker.prototype, {
if (!inst) if (!inst)
return; return;
var rangeSelect = inst._get('rangeSelect'); var rangeSelect = inst._get('rangeSelect');
if (rangeSelect && this._stayOpen) { if (rangeSelect && this._stayOpen)
this._selectDate(inst, inst._formatDate( this._selectDate(inst, inst._formatDate(
inst._currentDay, inst._currentMonth, inst._currentYear)); inst._currentDay, inst._currentMonth, inst._currentYear));
}
this._stayOpen = false; this._stayOpen = false;
if (this._datepickerShowing) { if (this._datepickerShowing) {
speed = (speed != null ? speed : inst._get('speed')); speed = (speed != null ? speed : inst._get('speed'));
@ -549,10 +545,9 @@ $.extend(Datepicker.prototype, {
if (speed == '') if (speed == '')
this._tidyDialog(inst); this._tidyDialog(inst);
var onClose = inst._get('onClose'); var onClose = inst._get('onClose');
if (onClose) { if (onClose)
onClose.apply((inst._input ? inst._input[0] : null), onClose.apply((inst._input ? inst._input[0] : null),
[inst._getDate(), inst]); // trigger custom callback [inst._getDate(), inst]); // trigger custom callback
}
this._datepickerShowing = false; this._datepickerShowing = false;
this._lastInput = null; this._lastInput = null;
inst._settings.prompt = null; inst._settings.prompt = null;
@ -582,9 +577,8 @@ $.extend(Datepicker.prototype, {
if (($target.parents("#ui-datepicker-div").length == 0) && if (($target.parents("#ui-datepicker-div").length == 0) &&
!$target.hasClass('hasDatepicker') && !$target.hasClass('hasDatepicker') &&
!$target.hasClass('ui-datepicker-trigger') && !$target.hasClass('ui-datepicker-trigger') &&
$.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI)) { $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI))
$.datepicker._hideDatepicker(null, ''); $.datepicker._hideDatepicker(null, '');
}
}, },
/* Adjust one of the date sub-fields. */ /* Adjust one of the date sub-fields. */
@ -852,14 +846,12 @@ $.extend(Datepicker.prototype, {
checkLiteral(); checkLiteral();
} }
} }
if (year < 100) { if (year < 100)
year += new Date().getFullYear() - new Date().getFullYear() % 100 + year += new Date().getFullYear() - new Date().getFullYear() % 100 +
(year <= shortYearCutoff ? 0 : -100); (year <= shortYearCutoff ? 0 : -100);
}
var date = new Date(year, month - 1, day); var date = new Date(year, month - 1, day);
if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) { if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
throw 'Invalid date'; // E.g. 31/02/* throw 'Invalid date'; // E.g. 31/02/*
}
return date; return date;
}, },
@ -910,7 +902,7 @@ $.extend(Datepicker.prototype, {
}; };
var output = ''; var output = '';
var literal = false; var literal = false;
if (date) { if (date)
for (var iFormat = 0; iFormat < format.length; iFormat++) { for (var iFormat = 0; iFormat < format.length; iFormat++) {
if (literal) if (literal)
if (format.charAt(iFormat) == "'" && !lookAhead("'")) if (format.charAt(iFormat) == "'" && !lookAhead("'"))
@ -945,7 +937,6 @@ $.extend(Datepicker.prototype, {
output += format.charAt(iFormat); output += format.charAt(iFormat);
} }
} }
}
return output; return output;
}, },
@ -1196,9 +1187,8 @@ $.extend(DatepickerInstance.prototype, {
} }
html += '</tr></thead><tbody>'; html += '</tr></thead><tbody>';
var daysInMonth = this._getDaysInMonth(drawYear, drawMonth); var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
if (drawYear == this._selectedYear && drawMonth == this._selectedMonth) { if (drawYear == this._selectedYear && drawMonth == this._selectedMonth)
this._selectedDay = Math.min(this._selectedDay, daysInMonth); this._selectedDay = Math.min(this._selectedDay, daysInMonth);
}
var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7; var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
var currentDate = (!this._currentDay ? new Date(9999, 9, 9) : var currentDate = (!this._currentDay ? new Date(9999, 9, 9) :
new Date(this._currentYear, this._currentMonth, this._currentDay)); new Date(this._currentYear, this._currentMonth, this._currentDay));
@ -1267,7 +1257,6 @@ $.extend(DatepickerInstance.prototype, {
var monthNames = this._get('monthNames'); var monthNames = this._get('monthNames');
if (secondary || !this._get('changeMonth')) if (secondary || !this._get('changeMonth'))
html += monthNames[drawMonth] + '&#xa0;'; html += monthNames[drawMonth] + '&#xa0;';
else { else {
var inMinYear = (minDate && minDate.getFullYear() == drawYear); var inMinYear = (minDate && minDate.getFullYear() == drawYear);
var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear); var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
@ -1277,12 +1266,11 @@ $.extend(DatepickerInstance.prototype, {
(showStatus ? this._addStatus(this._get('monthStatus') || '&#xa0;') : '') + '>'; (showStatus ? this._addStatus(this._get('monthStatus') || '&#xa0;') : '') + '>';
for (var month = 0; month < 12; month++) { for (var month = 0; month < 12; month++) {
if ((!inMinYear || month >= minDate.getMonth()) && if ((!inMinYear || month >= minDate.getMonth()) &&
(!inMaxYear || month <= maxDate.getMonth())) { (!inMaxYear || month <= maxDate.getMonth()))
html += '<option value="' + month + '"' + html += '<option value="' + month + '"' +
(month == drawMonth ? ' selected="selected"' : '') + (month == drawMonth ? ' selected="selected"' : '') +
'>' + monthNames[month] + '</option>'; '>' + monthNames[month] + '</option>';
} }
}
html += '</select>'; html += '</select>';
} }
// year selection // year selection
@ -1297,8 +1285,9 @@ $.extend(DatepickerInstance.prototype, {
year = drawYear - 10; year = drawYear - 10;
endYear = drawYear + 10; endYear = drawYear + 10;
} else if (years[0].charAt(0) == '+' || years[0].charAt(0) == '-') { } else if (years[0].charAt(0) == '+' || years[0].charAt(0) == '-') {
year = new Date().getFullYear() + parseInt(years[0], 10); year = endYear = new Date().getFullYear();
endYear = new Date().getFullYear() + parseInt(years[1], 10); year += parseInt(years[0], 10);
endYear += parseInt(years[1], 10);
} else { } else {
year = parseInt(years[0], 10); year = parseInt(years[0], 10);
endYear = parseInt(years[1], 10); endYear = parseInt(years[1], 10);
@ -1418,8 +1407,8 @@ $.extend(DatepickerInstance.prototype, {
function extendRemove(target, props) { function extendRemove(target, props) {
$.extend(target, props); $.extend(target, props);
for (var name in props) for (var name in props)
if (props[name] == null) if (props[name] == null || props[name] == undefined)
target[name] = null; target[name] = props[name];
return target; return target;
}; };
@ -1429,9 +1418,8 @@ function extendRemove(target, props) {
@return jQuery object */ @return jQuery object */
$.fn.datepicker = function(options){ $.fn.datepicker = function(options){
var otherArgs = Array.prototype.slice.call(arguments, 1); var otherArgs = Array.prototype.slice.call(arguments, 1);
if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate')) { if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate'))
return $.datepicker['_' + options + 'Datepicker'].apply($.datepicker, [this[0]].concat(otherArgs)); return $.datepicker['_' + options + 'Datepicker'].apply($.datepicker, [this[0]].concat(otherArgs));
}
return this.each(function() { return this.each(function() {
typeof options == 'string' ? typeof options == 'string' ?
$.datepicker['_' + options + 'Datepicker'].apply($.datepicker, [this].concat(otherArgs)) : $.datepicker['_' + options + 'Datepicker'].apply($.datepicker, [this].concat(otherArgs)) :
@ -1443,8 +1431,8 @@ $.datepicker = new Datepicker(); // singleton instance
/* Initialise the date picker. */ /* Initialise the date picker. */
$(document).ready(function() { $(document).ready(function() {
$(document.body).append($.datepicker._datepickerDiv) $(document.body).append($.datepicker._datepickerDiv).
.mousedown($.datepicker._checkExternalClick); mousedown($.datepicker._checkExternalClick);
}); });
})(jQuery); })(jQuery);