From 30dc9d3dba5cdd35f7e02ae45658db59db3b35f0 Mon Sep 17 00:00:00 2001 From: Ruslan Ismagilov Date: Wed, 12 Mar 2014 23:52:08 +0400 Subject: [PATCH 1/2] feat: add startX & startY options --- jquery.jWindowCrop.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/jquery.jWindowCrop.js b/jquery.jWindowCrop.js index a2f85d4..0953451 100644 --- a/jquery.jWindowCrop.js +++ b/jquery.jWindowCrop.js @@ -82,6 +82,9 @@ base.setZoom(base.workingPercent-zoomIncrement); return false; }; + base.setFocus = function (x, y) { + base.$image.css({'left' : (x*-1*base.workingPercent.toString()+'px'), 'top' : (y*-1*base.workingPercent.toString()+'px')}); + }; function initializeDimensions() { if(base.originalWidth == 0) { @@ -108,9 +111,13 @@ base.focalPoint = {'x': Math.round(x), 'y': Math.round(y)}; } function focusOnCenter() { - var left = fillContainer((Math.round((base.focalPoint.x*base.workingPercent) - base.options.targetWidth/2)*-1), base.$image.width(), base.options.targetWidth); - var top = fillContainer((Math.round((base.focalPoint.y*base.workingPercent) - base.options.targetHeight/2)*-1), base.$image.height(), base.options.targetHeight); - base.$image.css({'left': (left.toString()+'px'), 'top': (top.toString()+'px')}) + if ( typeof base.options.startX != null && typeof base.options.startY != null ) { + base.setFocus( base.options.startX, base.options.startY ); + } else { + var left = fillContainer((Math.round((base.focalPoint.x*base.workingPercent) - base.options.targetWidth/2)*-1), base.$image.width(), base.options.targetWidth); + var top = fillContainer((Math.round((base.focalPoint.y*base.workingPercent) - base.options.targetHeight/2)*-1), base.$image.height(), base.options.targetHeight); + base.$image.css({'left': (left.toString()+'px'), 'top': (top.toString()+'px')}); + } storeFocalPoint(); } function updateResult() { From 3458e34ee1052571d01ddf59f7c2f898aae5a54e Mon Sep 17 00:00:00 2001 From: Ruslan Ismagilov Date: Wed, 12 Mar 2014 23:56:09 +0400 Subject: [PATCH 2/2] Update readme --- README.markdown | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.markdown b/README.markdown index 4698f85..960189b 100644 --- a/README.markdown +++ b/README.markdown @@ -39,6 +39,14 @@ Options targetHeightinteger180no Height in pixels of the cropping window + + startXintegernullno + Set start image position on X axis. + + + startYintegernullno + Set start image position on Y axis. + onChangefunctionfunction(){}no Callback function that gets called whenever the values change. cropX, cropY, cropW, cropH, mustStretch (boolean) values are passed to this function in a hash. Use the this keyword in the function for a reference to the element that was updated.