[25794] | 1 | function rvas_get_scaled_size(d, available) { |
---|
| 2 | var ratio_w = d.w / available.w |
---|
| 3 | , ratio_h = d.h / available.h; |
---|
| 4 | if (ratio_w>1 || ratio_h>1) { |
---|
| 5 | if (ratio_w>ratio_h) |
---|
| 6 | return {w: available.w / available.dpr, h: Math.floor(d.h / ratio_w / available.dpr)}; |
---|
| 7 | else |
---|
| 8 | return {w: Math.floor(d.w / ratio_h / available.dpr), h: available.h / available.dpr}; |
---|
| 9 | } |
---|
| 10 | return {w: Math.round(d.w / available.dpr), h: Math.round(d.h / available.dpr)}; |
---|
| 11 | } |
---|
| 12 | |
---|
| 13 | function rvas_get_available_size(){ |
---|
| 14 | var width = $("#theImage").width(), |
---|
| 15 | zoom = 1, |
---|
| 16 | docHeight; |
---|
| 17 | |
---|
| 18 | if ("innerHeight" in window) { |
---|
| 19 | docHeight = window.innerHeight; |
---|
| 20 | if (document.documentElement.clientWidth > window.innerWidth && window.innerWidth) |
---|
| 21 | zoom = document.documentElement.clientWidth / window.innerWidth; |
---|
| 22 | docHeight = Math.floor(docHeight*zoom); |
---|
| 23 | } |
---|
| 24 | else |
---|
| 25 | docHeight = document.documentElement.offsetHeight; |
---|
| 26 | var height = docHeight - Math.ceil($("#theImage").offset().top); |
---|
| 27 | |
---|
| 28 | var dpr = window.devicePixelRatio && window.devicePixelRatio>1 ? window.devicePixelRatio : 1; |
---|
| 29 | width = Math.floor(width*dpr); height = Math.floor(height*dpr); |
---|
| 30 | |
---|
| 31 | document.cookie= 'phavsz='+width+'x'+height+'x'+dpr+';path='+RVAS.cp; |
---|
| 32 | return {w:width, h:height, dpr:dpr, zoom:zoom}; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | function rvas_choose(relaxed){ |
---|
| 36 | var best, |
---|
| 37 | available = rvas_get_available_size(), |
---|
| 38 | $img = $("#theMainImage"), |
---|
| 39 | changed = true; |
---|
| 40 | for (var i=0; i<RVAS.derivatives.length; i++){ |
---|
| 41 | var d = RVAS.derivatives[i]; |
---|
| 42 | if (d.w > available.w*available.zoom || d.h > available.h*available.zoom){ |
---|
| 43 | if (available.dpr>1 || !best) |
---|
| 44 | best = d; |
---|
| 45 | break; |
---|
| 46 | } |
---|
| 47 | else |
---|
| 48 | best = d; |
---|
| 49 | } |
---|
| 50 | if (best) { |
---|
| 51 | if (available.dpr > 1) { |
---|
| 52 | var rescaled = rvas_get_scaled_size(best, available); |
---|
| 53 | if ($img.attr("width") && available.zoom==1) { |
---|
| 54 | var changeRatio = rescaled.h / $img.height() |
---|
| 55 | , limit = relaxed ? 1.25 : 1.15; |
---|
| 56 | if (changeRatio>=1 && changeRatio<limit |
---|
| 57 | || (changeRatio<1 && changeRatio>1/limit && $img.width()<available.w/available.dpr) ) |
---|
| 58 | return; |
---|
| 59 | } |
---|
| 60 | if (!$img.data("natural-w") || $img.data("natural-w") < best.w) { |
---|
| 61 | $img.attr("width", rescaled.w).attr("height", rescaled.h) |
---|
| 62 | .attr("src", best.url) |
---|
| 63 | .removeAttr("usemap") |
---|
| 64 | .data("natural-w", best.w); |
---|
| 65 | } |
---|
| 66 | else { |
---|
| 67 | $img.attr("width", rescaled.w).attr("height", rescaled.h); |
---|
| 68 | changed = false; |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | else { |
---|
| 72 | if ($img.attr("width")) { |
---|
| 73 | var changeRatio = best.h / $img.height() |
---|
| 74 | , limit = relaxed ? 2 : 1.15; |
---|
| 75 | if (changeRatio>=1 && changeRatio<limit |
---|
| 76 | || (changeRatio<1 && changeRatio>1/limit && $img.width()<available.w) ) |
---|
| 77 | return; |
---|
| 78 | } |
---|
| 79 | $img |
---|
| 80 | .attr("width", best.w).attr("height", best.h) |
---|
| 81 | .attr("src", best.url) |
---|
| 82 | .attr("usemap", "#map"+best.type); |
---|
| 83 | } |
---|
| 84 | if (changed) { |
---|
| 85 | $('#derivativeSwitchBox .switchCheck').css('visibility','hidden'); |
---|
| 86 | $('#derivativeChecked'+best.type).css('visibility','visible'); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | $(document).ready( function() { |
---|
| 92 | |
---|
| 93 | if (window.changeImgSrc) { |
---|
| 94 | RVAS.changeImgSrcOrig = changeImgSrc; |
---|
| 95 | changeImgSrc = function() { |
---|
| 96 | RVAS.disable = 1; |
---|
| 97 | RVAS.changeImgSrcOrig.apply(undefined, arguments); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | $(window).resize(function() { |
---|
| 102 | var w = $("body").width(), |
---|
| 103 | de = $(document.documentElement); |
---|
| 104 | if (document.location.search.indexOf("slideshow")==-1) { |
---|
| 105 | if (w<1262) |
---|
| 106 | de.removeClass("wide"); |
---|
| 107 | else |
---|
| 108 | de.addClass("wide"); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if (RVAS.disable) |
---|
| 112 | rvas_get_available_size(); |
---|
| 113 | else |
---|
| 114 | rvas_choose(); |
---|
| 115 | }); |
---|
| 116 | |
---|
| 117 | $("#theMainImage").click( function(e) { |
---|
| 118 | if (!$(this).attr("usemap") && e.clientY) { |
---|
| 119 | var pct = (e.pageX - $(this).offset().left) / $(this).width() |
---|
| 120 | , clientY = e.pageY - $(this).offset().top; |
---|
| 121 | if (pct < 0.3) { |
---|
| 122 | if ($("#linkPrev").length && clientY>15) |
---|
| 123 | window.location = $("#linkPrev").attr("href"); |
---|
| 124 | } |
---|
| 125 | else if (pct > 0.7 ) { |
---|
| 126 | if ($("#linkNext").length && clientY>15) |
---|
| 127 | window.location = $("#linkNext").attr("href"); |
---|
| 128 | } |
---|
| 129 | else if (clientY/$(this).height() < 0.5 && clientY>15) { |
---|
| 130 | var href = $(".pwg-icon-arrow-n").parent("a").attr("href"); |
---|
| 131 | if (href) |
---|
| 132 | window.location = href; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | }); |
---|
| 136 | }); |
---|