First, you have to clone the object $.datepicker which is an instance of Datepicker (Private class in jQuery code). otherwise, you would only do a copy, and you write the same method.
Second, you have to copy the code of $.fn.datepicker, because it internally calls the instance of $.datepicker.
Code:
(function($, window, undefined) {
$.datepickerExt = jQuery.extend({}, $.datepicker);
var datepickerOldHTML = $.datepicker._generateHTML;
$.datepickerExt._generateHTML = function(inst) {
var generatedHTML = datepickerOldHTML.apply(this, arguments);
return "<div style='text-align:center'>header</div>" + generatedHTML;
};
$.fn.datepickerExt = function(options) {
/* Verify an empty collection wasn't passed - Fixes #6976 */
if (!this.length) {
return this;
}
/* Initialise the date picker. */
if (!$.datepickerExt.initialized) {
$(document).mousedown($.datepickerExt._checkExternalClick).
find('body').append($.datepickerExt.dpDiv);
$.datepickerExt.initialized = true;
}
var otherArgs = Array.prototype.slice.call(arguments, 1);
if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget')) return $.datepickerExt['_' + options + 'Datepicker'].apply($.datepickerExt, [this[0]].concat(otherArgs));
if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string') return $.datepickerExt['_' + options + 'Datepicker'].apply($.datepickerExt, [this[0]].concat(otherArgs));
return this.each(function() {
typeof options == 'string' ? $.datepickerExt['_' + options + 'Datepicker'].
apply($.datepickerExt, [this].concat(otherArgs)) : $.datepickerExt._attachDatepicker(this, options);
});
};
}());
run