From b2f7c8b23921b949d8ac76f92e45fbe153c18d77 Mon Sep 17 00:00:00 2001 From: mconaway Date: Fri, 31 Jul 2015 10:30:53 -0400 Subject: [PATCH] feature(option): maintain aspect ratio change gridster constructor to accept a new parameter 'maintain_aspect_ratio:boolean' that defaults to false and modify method 'on_resize' to force aspect ratio if feature is enabled Closes #530 --- src/jquery.gridster.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index 7bac9118..93464f35 100755 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -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, @@ -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; @@ -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) {