Всем привет!
В js не селен, груба говоря код украл, но хотелось бы его доработать.
Подскажите как сделать чтобы размер изображения ориентировался на размер окна браузера?
//Template preview functions (begin)
var previewTimeout;
var hintTimeout;
function showPreview(wrapper,heading,title,src,width,height) {
var previewHTML='<img id="templatePreviewImage" height="'+height+'" width="'+width+'" src="'+src+'" alt=""/><div id="templatePreviewProgressBar"></div>';
heading.innerHTML=title;
document.getElementById('templatePreviewBody').innerHTML=previewHTML;
previewProgress = document.getElementById('templatePreviewProgressBar');
previewImage = document.getElementById('templatePreviewImage');
previewImage.onload=function() {previewProgress.style.display='none';}
previewTimeout = setTimeout(function (){wrapper.display='block'},250);
}
function showFLVPreview(wrapper,heading,title,src,width,height) {
var flvBlock = '' +
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="display:block" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '">' +
'<param name="allowScriptAccess" value="sameDomain" />' +
'<param name="allowFullScreen" value="true" />' +
'<param name="quality" value="high">' +
'<param name="menu" value="false">' +
'<param id="nameValueFLV" name="movie" value="/images/popup-player.swf?titleVideo=' + src + '" />' +
'<param name="quality" value="high" />' +
'<param name="bgcolor" value="#010101" />' +
'<embed src="/images/popup-player.swf?titleVideo=' + src + '" quality="high" menu="false" bgcolor="#010101" width="' + width + '" height="' + height + '" name="video" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></embed>' +
'</object>';
jQuery('#templatePreviewBody').prepend(flvBlock);
jQuery('#templatePreviewProgressBar').css('display', 'none');
heading.innerHTML=title;
previewTimeout = setTimeout(function (){wrapper.display='block'},250);
}
function hidePreview(wrapper,heading,image) {
clearTimeout(previewTimeout);
jQuery('#templatePreviewBody').empty();
wrapper.display='none';
}
function previewMouseFollow(event,wrapper,width,height,winWidth,winHeight,topOffset) {
pageX=event.pageX;
pageY=event.pageY;
previewOffsetTop=(winHeight-height)/2;
previewOffsetLeft=(winWidth-width)/2;
correctedTopOffset=previewOffsetTop+topOffset;
offset=30;
centered=false;
if (winHeight > height) {
if (pageY<correctedTopOffset-offset) {pageY=pageY+offset;}
else if (pageY>correctedTopOffset+height+offset) {pageY=pageY-offset-height;}
else {pageY=correctedTopOffset;centered=true;}
}
else {
pageY=topOffset;
centered=true;
}
if (centered) {
if (pageX<winWidth/2) {pageX+=offset;}
else {pageX=pageX-width-offset;}
}
else {
if (pageX<previewOffsetLeft-offset) {pageX=pageX+offset;}
else if (pageX>previewOffsetLeft+width+offset) {pageX=pageX-width-offset;}
else {pageX=previewOffsetLeft;}
}
wrapper.left=pageX+'px';
wrapper.top=pageY+'px';
}
//Top Rollover functions (begin)
function showPopup(popUp,popUpArrow) {
popUp.slideDown(300).data('visible',true);
popUpArrow.addClass('active');
}
function hidePopup(popUp,popUpArrow) {popUp.slideUp(300,function(){
popUp.data('visible',false)});
popUpArrow.removeClass('active');
}
//Price description popup functions (begin)
function showPriceHint(hint,currentElement,hintType) {
var hintValue='';
if (hintType=='price') {
var elemId=currentElement.data('id');
var priceTitle=document.getElementById(elemId);
hintValue=priceTitle.innerHTML;
}
else if (hintType=='type') {
hintValue='<p>'+currentElement.data('alt')+'</p>';
}
hint.innerHTML=hintValue;
hint.style.display='block';
hintTimeout = setTimeout(function (){hint.style.visibility='visible';},250);
}
function hidePriceHint (hint) {
hint.style.display='none';
hint.style.visibility='hidden';
clearTimeout(hintTimeout);
}
function hintMouseFollow(event,priceHint,windowHeight,windowWidth,hintHeight,hintWidth,topOffset) {
var x=event.pageX+15;
var y=event.pageY;
var correctedY=windowHeight-10-hintHeight+topOffset
var correctedX=windowWidth-10-hintWidth;
if (correctedY<y) {y=correctedY;}
if (correctedX<x) {x=x-hintWidth-30}
priceHint.style.left=x+'px';
priceHint.style.top=y+'px';
}
//-----* Events *-----//
jQuery(function() {
var popUp=jQuery('#networkBarPopup');
var popUpArrow=jQuery('#networkBarButtonArrow');
var currentWindow=jQuery(window);
var windowObj = new Object();
windowObj.width = currentWindow.width();
windowObj.height = currentWindow.height();
windowObj.scrollTop = currentWindow.scrollTop();
var previewWrapper=document.getElementById('templatePreviewWrapper').style;
var previewHeading=document.getElementById('templatePreviewHeading');
var previewProgress;
var previewImage;
var priceHint=document.getElementById('altDiv');
var hint = new Object();
//Top Rollover events (begin)
jQuery('#networkBarButton').bind('mouseenter', function() {if (!popUp.data('visible')) {showPopup(popUp,popUpArrow);}});
jQuery('#networkBar').bind('mouseleave', function() {if (popUp.data('visible')) {hidePopup(popUp,popUpArrow);}});
//Template preview events (begin)
currentWindow.resize(function(){windowObj.width=jQuery(this).width();windowObj.height=jQuery(this).height();}).scroll(function(){windowObj.scrollTop=jQuery(this).scrollTop();});
jQuery.each(templatesArray, function(index,value) {
var currentTemplate=jQuery('#'+value.id);
var widthOffset=32;
var heightOffset=53;
var display;
currentTemplate.hover(
function() {
var fileExt = value.src.substr(value.src.length-4, 4).toLowerCase();
switch (fileExt) {
case '.flv':
jQuery('#templatePreviewBody').html('<div id="templatePreviewProgressBar">Loading template preview...</div>');
previewProgress = document.getElementById('templatePreviewProgressBar');
break;
default:
jQuery('#templatePreviewBody').html('<img id="templatePreviewImage" height="" width="" src="" alt=""/><div id="templatePreviewProgressBar">Loading template preview...</div>');
previewProgress = document.getElementById('templatePreviewProgressBar');
previewImage = document.getElementById('templatePreviewImage');
previewImage.onload=function() {previewProgress.style.display='none';}
break;
}
previewProgress.style.display="block";
previewWidth=value.width+widthOffset;
previewHeight=value.height+heightOffset;
if(windowObj.width > previewWidth) {display=true} else {display=false}
if (display) {
switch (fileExt) {
case '.flv':
showFLVPreview(previewWrapper,previewHeading,value.title,value.src,value.width,value.height);
break;
default:
showPreview(previewWrapper,previewHeading,value.title,value.src,value.width,value.height);
break;
}
}
},
function() {
var fileExt = value.src.substr(value.src.length-4, 4).toLowerCase();
hidePreview(previewWrapper,previewHeading);
}
).mousemove(function(event) {if(display){previewMouseFollow(event,previewWrapper,previewWidth,previewHeight,windowObj.width,windowObj.height,windowObj.scrollTop)}});
});
//Price description popup events (begin)
jQuery("span.price-label.altTitle, a.last.altTitle").each(function() {
var currentElement=jQuery(this);
currentElement.data('id',currentElement.attr('title')).attr('title','');
}).hover(function() {
showPriceHint(priceHint,jQuery(this),'price');
hint.height=priceHint.clientHeight;
hint.width=priceHint.clientWidth;
},
function() {
hidePriceHint(priceHint);
}).mousemove(function(event) {
hintMouseFollow(event,priceHint,windowObj.height,windowObj.width,hint.height,hint.width,windowObj.scrollTop);
});
jQuery("a.productType.altTitle").each(function() {
currentElement=jQuery(this);
currentElement.data('alt',currentElement.attr('title')).attr('title','');
}).hover(function() {
if (jQuery(this).data('alt')!='') {
showPriceHint(priceHint,jQuery(this),'type');
hint.height=priceHint.clientHeight;
hint.width=priceHint.clientWidth;
}
},
function() {
hidePriceHint(priceHint);
}).mousemove(function(event) {
hintMouseFollow(event,priceHint,windowObj.height,windowObj.width,hint.height,hint.width,windowObj.scrollTop);
});
});