Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(option): maintain aspect ratio #531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/jquery.gridster.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
min_rows: 15,
max_size_x: false,
autogrow_cols: false,
maintain_aspect_ratio: false,
autogenerate_stylesheet: true,
avoid_overlapped_widgets: true,
auto_init: true,
Expand Down Expand Up @@ -1332,6 +1333,7 @@
var max_size_y = this.resize_max_size_y;
var min_size_y = this.resize_min_size_y;
var autogrow = this.options.autogrow_cols;
var maintainAspect = this.options.maintain_aspect_ratio;
var width;
var max_width = Infinity;
var max_height = Infinity;
Expand All @@ -1356,6 +1358,12 @@
max_height = (max_size_y * wbd_y) + ((size_y - 1) * margin_y * 2);
min_height = (min_size_y * wbd_y) + ((size_y - 1) * margin_y * 2);

if(maintainAspect)
{
var ratio = this.resize_initial_sizex / this.resize_initial_sizey;
size_y > size_x ? (size_x = size_y / ratio) : (size_y = size_x / ratio);
}

if (this.resize_dir.right) {
size_y = this.resize_initial_sizey;
} else if (this.resize_dir.bottom) {
Expand Down