@@ -50,21 +50,23 @@ var zoom = (function(){
5050 } ) ;
5151
5252 /**
53- * Applies the CSS required to zoom in, prioritizes use of CSS3
53+ * Applies the CSS required to zoom in, prefers the use of CSS3
5454 * transforms but falls back on zoom for IE.
5555 *
56- * @param {Number } x
57- * @param {Number } y
58- * @param {Number } width
59- * @param {Number } height
56+ * @param {Object } rect
6057 * @param {Number } scale
6158 */
62- function magnify ( x , y , width , height , scale ) {
59+ function magnify ( rect , scale ) {
6360
6461 var scrollOffset = getScrollOffset ( ) ;
6562
66- x -= ( window . innerWidth - ( width * scale ) ) / 2 ;
67- y -= ( window . innerHeight - ( height * scale ) ) / 2 ;
63+ // Ensure a width/height is set
64+ rect . width = rect . width || 1 ;
65+ rect . height = rect . height || 1 ;
66+
67+ // Center the rect within the zoomed viewport
68+ rect . x -= ( window . innerWidth - ( rect . width * scale ) ) / 2 ;
69+ rect . y -= ( window . innerHeight - ( rect . height * scale ) ) / 2 ;
6870
6971 if ( supportsTransforms ) {
7072 // Reset
@@ -78,7 +80,7 @@ var zoom = (function(){
7880 // Scale
7981 else {
8082 var origin = scrollOffset . x + 'px ' + scrollOffset . y + 'px' ,
81- transform = 'translate(' + - x + 'px,' + - y + 'px) scale(' + scale + ')' ;
83+ transform = 'translate(' + - rect . x + 'px,' + - rect . y + 'px) scale(' + scale + ')' ;
8284
8385 document . body . style . transformOrigin = origin ;
8486 document . body . style . OTransformOrigin = origin ;
@@ -106,8 +108,8 @@ var zoom = (function(){
106108 // Scale
107109 else {
108110 document . body . style . position = 'relative' ;
109- document . body . style . left = ( - ( scrollOffset . x + x ) / scale ) + 'px' ;
110- document . body . style . top = ( - ( scrollOffset . y + y ) / scale ) + 'px' ;
111+ document . body . style . left = ( - ( scrollOffset . x + rect . x ) / scale ) + 'px' ;
112+ document . body . style . top = ( - ( scrollOffset . y + rect . y ) / scale ) + 'px' ;
111113 document . body . style . width = ( scale * 100 ) + '%' ;
112114 document . body . style . height = ( scale * 100 ) + '%' ;
113115 document . body . style . zoom = scale ;
@@ -165,6 +167,7 @@ var zoom = (function(){
165167 * - scale: can be used instead of width/height to explicitly set scale
166168 */
167169 to : function ( options ) {
170+
168171 // Due to an implementation limitation we can't zoom in
169172 // to another element without zooming out first
170173 if ( level !== 1 ) {
@@ -195,7 +198,7 @@ var zoom = (function(){
195198 options . x *= options . scale ;
196199 options . y *= options . scale ;
197200
198- magnify ( options . x , options . y , options . width || 1 , options . height || 1 , options . scale ) ;
201+ magnify ( options , options . scale ) ;
199202
200203 if ( options . pan !== false ) {
201204
@@ -217,7 +220,7 @@ var zoom = (function(){
217220 clearTimeout ( panEngageTimeout ) ;
218221 clearInterval ( panUpdateInterval ) ;
219222
220- magnify ( 0 , 0 , 1 , 1 , 1 ) ;
223+ magnify ( { x : 0 , y : 0 } , 1 ) ;
221224
222225 level = 1 ;
223226 } ,
0 commit comments