Skip to content
This repository has been archived by the owner on Dec 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #135 from alkzoupas/zoom_update
Browse files Browse the repository at this point in the history
make Mobile Safari interactions snappier
  • Loading branch information
cin210 committed May 1, 2015
2 parents 2b15f3f + 0f0ff63 commit 5ad72fc
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/zoom.js
Expand Up @@ -47,7 +47,7 @@ interactions.zoom = function ( fragment, options ) {
this.transform3d = custom3d != "disabled";
else if ("transform3d" in options)
this.transform3d = options.transform3d;

if (zoomer.transform3d) {
translatePrefix = "translate3d(";
translateSuffix = ",0)";
Expand Down Expand Up @@ -129,23 +129,23 @@ interactions.zoom = function ( fragment, options ) {

function initialize() {
$container.attr("data-ur-transform3d", zoomer.transform3d ? "enabled" : "disabled");

canvasWidth = canvasWidth || $img.parent().outerWidth();
canvasHeight = canvasHeight || $img.parent().outerHeight();
width = width || parseInt($img.attr("width")) || parseInt($img.css("width")) || $img[0].width;
height = height || parseInt($img.attr("height")) || parseInt($img.css("height")) || $img[0].height;

bigWidth = parseInt($img.attr("data-ur-width")) || $img[0].naturalWidth;
bigHeight = parseInt($img.attr("data-ur-height")) || $img[0].naturalHeight;

if (!$img.attr("data-ur-src"))
$img.attr("data-ur-src", $img.attr("src"));

if (($img.attr("data-ur-width") && $img.attr("data-ur-height")) || $img.attr("src") == $img.attr("data-ur-src"))
prescale = true;

imgRatio = bigWidth/width;

var xb = (bigWidth - canvasWidth)/2; // horizonal translation to show left side of image
var yb = (bigHeight - canvasHeight)/2; // vertical translation to show left top side of image
currentBounds = bigBounds = { x: [-xb, xb], y: [-yb, yb] };
Expand Down Expand Up @@ -186,7 +186,7 @@ interactions.zoom = function ( fragment, options ) {
if (event.timeStamp < time2 + 50)
slide();
}

function slide() {
setState("enabled-slide");
var ddx = dx2 - dx1, ddy = dy2 - dy1;
Expand Down Expand Up @@ -244,7 +244,7 @@ interactions.zoom = function ( fragment, options ) {
t = translatePrefix + x + "px, " + y + "px" + translateSuffix;
if (scale != null)
t += scalePrefix + scale + ", " + scale + scaleSuffix;

return $img.css({ webkitTransform: t, msTransform: t, transform: t });
}

Expand Down Expand Up @@ -280,7 +280,7 @@ interactions.zoom = function ( fragment, options ) {

if (!width)
initialize();

if (prescale) {
currentBounds = bigBounds;
var trX = 0, trY = 0; // relative to center of image
Expand Down Expand Up @@ -332,6 +332,7 @@ interactions.zoom = function ( fragment, options ) {
x: ((rel.x + rel.x2)/2 + transXY.x)/initScale,
y: ((rel.y + rel.y2)/2 + transXY.y)/initScale
};
initAbsCoords = absCoords;
}
else {
clickFlag = true;
Expand Down

0 comments on commit 5ad72fc

Please sign in to comment.