для любопытных про setHeight
setHeight();
var documentHeight = 0;
var curpicker = '';
$(document).ready(function(){
window.setTimeout(function(){setHeight();},3000);
window.scrollTo(0, 0);
OnResizeElement(document.getElementsByClassName('main-element')[0],300);
documentHeight = document.getElementsByClassName('main-element')[0].scrollHeight;
parseDate = function(date) {
var parts;
parts = date.split('.');
return parts[2] + '-' + parts[1] + '-' + parts[0];
};
min_booking_date = function(selectedDate) {
var new_minDate, result;
new_minDate = new Date(parseDate(selectedDate));
new_minDate.setDate(new_minDate.getDate() + 1);
result = new_minDate;
return $.datepicker.formatDate('dd.mm.yy', result);
};
});
window.onresize = function(event) {
var newDocumentHeight = document.getElementsByClassName('main-element')[0].scrollHeight;
var heightDiff = documentHeight - newDocumentHeight;
if ( heightDiff > 10 | heightDiff < -10 ) {
setHeight();
}
}
function closestRestricted(restricted_array, date) {
var i, len, r, result, sorted;
sorted = restricted_array.map(parseDate).sort();
result = null;
for (i = 0, len = sorted.length; i < len; i++) {
r = sorted[i];
if (r >= parseDate(date)) {
r = new Date(r);
r.setDate(r.getDate());
result = r;
break;
}
}
return $.datepicker.formatDate('dd.mm.yy', result);
}
function parseDate(date) {
var parts;
parts = date.split('.');
return parts[2] + '-' + parts[1] + '-' + parts[0];
}
function goDate(selectedDate,c) {
var new_minDate, result;
new_minDate = new Date(parseDate(selectedDate));
new_minDate.setDate(new_minDate.getDate() + c);
result = new_minDate;
return $.datepicker.formatDate('dd.mm.yy', result);
}
function setHeight() {
var documentHeight = document.getElementsByClassName('main-element')[0].scrollHeight
if (documentHeight > 10) {
var message = 'documentHeight:'+documentHeight;
parent.postMessage(message,"*");
}
}
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
eventer(messageEvent,function(e) {
if ( (typeof e.data === 'string') && (e.data.indexOf('scroll') > -1) ) {
var height = e.data.split('scroll:')[1],
height = parseInt(height);
var bh = 0;
if ($('#basketBody').length) {
bh = parseInt($('#basketBody').height());
}
dh = document.getElementsByClassName('main-element')[0].scrollHeight+bh+10;
if (dh < height) {
height= dh;
}
$('.basketItem').animate({top:(height-bh),position:'absolute',left:10,right:10},{duration:100,queue:false,easing:'swing'});
}
if ( (typeof e.data === 'string') && (e.data.indexOf('calendarMonths') > -1) ) {
var months = parseInt(e.data.split(':')[1]);
var date = e.data.split(':')[2];
var mindate = e.data.split(':')[3];
var maxdate = e.data.split(':')[4];
var restricted = jQuery.parseJSON(e.data.split(':')[5]);
if(mindate) {
mindate = min_booking_date(mindate);
}
else mindate='+0d';
$('#datepicker_plain').datepicker({
minDate: mindate,
numberOfMonths: months,
changeMonth: true,
onSelect: function(date){parent.postMessage('setDate:'+date,"*");}
});
$('#datepicker_plain').datepicker("option", "defaultDate",date);
$('#datepicker_plain').datepicker("option","minDate",mindate);
$('#datepicker_plain').datepicker("option","maxDate",maxdate);
$('#datepicker_plain').datepicker("option","beforeShowDay", function(date) {
if (restricted && restricted.indexOf($.datepicker.formatDate('dd.mm.yy', date)) !== -1) {
return [false, 'booked_day', 'Забронировано'];
} else {
return [true];
}
});
}
if ( (typeof e.data === 'string') && (e.data.indexOf('setDate') > -1) && curpicker) {
$('.'+curpicker+'_datepicker_frame').val(e.data.split('setDate:')[1]);
if (curpicker=='from') {
$('.to_datepicker_frame').click();
}
}
},false);
function OnResizeElement(element, time){
var id = null;
var _constructor = function(){
var HEIGHT = element.scrollHeight;
id = setInterval(function(){
if(HEIGHT != element.scrollHeight){
HEIGHT = element.scrollHeight;
setHeight();
};
}, time);
};
var _destructor = function(){
clearInterval(id);
};
this.Destroy = function(){
_destructor();
};
_constructor();
};