Skip to content

Instantly share code, notes, and snippets.

@ingdir
Created October 9, 2012 18:40
Show Gist options
  • Save ingdir/3860614 to your computer and use it in GitHub Desktop.
Save ingdir/3860614 to your computer and use it in GitHub Desktop.
_showPreview: function(coords) {
var that = this,
rateW = that._origWidth / that._previewWidth,
coefW = 100 / coords.w * rateW,
rateH = that._origHeight / that._previewHeight,
coefH = 100 / coords.h * rateH,
x, y, x2, y2;
if (!that._preview) return that;
if ((coords.w >= coords.h)) {
x = Math.round(coefW * coords.x / rateW);
y = Math.round(coefW * coords.y / rateW);
x2 = Math.round(coefW * coords.x2 / rateW);
y2 = Math.round(coefW * coords.y2 / rateW);
that._preview.elem('thumbimg').css({
position: 'absolute',
width: Math.round(that._previewWidth * coefW) + 'px',
height: Math.round(that._previewHeight * coefW) + 'px',
clip: 'rect(' + y + 'px ' + x2 + 'px ' + y2 + 'px ' + x + 'px)',
top: '-' + y + 'px',
left: '-' + x + 'px'
});
} else {
x = Math.round(coefH * coords.x / rateH);
y = Math.round(coefH * coords.y / rateH);
x2 = Math.round(coefH * coords.x2 / rateH);
y2 = Math.round(coefH * coords.y2 / rateH);
that._preview.elem('thumbimg').css({
position: 'absolute',
width: Math.round(that._previewWidth * coefH) + 'px',
height: Math.round(that._previewHeight * coefH) + 'px',
clip: 'rect(' + y + 'px ' + x2 + 'px ' + y2 + 'px ' + x + 'px)',
top: '-' + y + 'px',
left: '-' + x + 'px'
});
}
return that;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment