Skip to content

Commit

Permalink
Added initialZoom option
Browse files Browse the repository at this point in the history
When set to 'min', image is zoomed to the smallest when loaded. When set
to 'image', image is zoomed to 1 when loaded.

Default is 'min'.
  • Loading branch information
Scott Cheng committed Jun 20, 2015
1 parent 869a63e commit cee44a7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
12 changes: 10 additions & 2 deletions dist/jquery.cropit.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ return /******/ (function(modules) { // webpackBootstrap
});
}

this.initialZoom = 0;
if (this.options.initialZoom === 'min') {
this.initialZoom = 0; // Will be fixed when image loads
} else if (this.options.initialZoom === 'image') {
this.initialZoom = 1;
} else {
this.initialZoom = 0;
}

this.imageLoaded = false;

this.moveContinue = false;
Expand Down Expand Up @@ -899,8 +906,9 @@ return /******/ (function(modules) { // webpackBootstrap
imageState: null,
allowDragNDrop: true,
freeMove: false,
minZoom: 'fill',
maxZoom: 1,
minZoom: 'fill',
initialZoom: 'min',
rejectSmallImage: false
};

Expand Down
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export const DEFAULTS = {
imageState: null,
allowDragNDrop: true,
freeMove: false,
minZoom: 'fill',
maxZoom: 1,
minZoom: 'fill',
initialZoom: 'min',
rejectSmallImage: false,
};

Expand Down
11 changes: 10 additions & 1 deletion src/cropit.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ class Cropit {
});
}

this.initialZoom = 0;
if (this.options.initialZoom === 'min') {
this.initialZoom = 0; // Will be fixed when image loads
}
else if (this.options.initialZoom === 'image') {
this.initialZoom = 1;
}
else {
this.initialZoom = 0;
}

this.imageLoaded = false;

this.moveContinue = false;
Expand Down
12 changes: 12 additions & 0 deletions test/cropit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ describe('Cropit', () => {
expect(cropit.options.imageState).toBe(null);
expect(cropit.options.allowDragNDrop).toBe(true);
expect(cropit.options.freeMove).toBe(false);
expect(cropit.options.maxZoom).toBe(1);
expect(cropit.options.minZoom).toBe('fill');
expect(cropit.options.initialZoom).toBe('min');
expect(cropit.options.rejectSmallImage).toBe(false);
});

Expand Down Expand Up @@ -81,6 +83,16 @@ describe('Cropit', () => {
expect(cropit.centerImage).toHaveBeenCalled();
});

it('sets zoom to 1 if initialZoom is image', () => {
cropit = newCropit({ initialZoom: 'image' });
expect(cropit.zoom).not.toBe(1);

cropit.image = { width: 2, height: 2 };
cropit.previewSize = { w: 1, h: 1 };
cropit.onImageLoaded();
expect(cropit.zoom).toBe(1);
});

describe('rejectSmallImage set to true', () => {
beforeEach(() => {
cropit = newCropit({ rejectSmallImage: true });
Expand Down

0 comments on commit cee44a7

Please sign in to comment.