From 2f05ec7de014303d97559d858a7ed37cd3c97dc0 Mon Sep 17 00:00:00 2001
From: psychobunny <psycho.bunny@hotmail.com>
Date: Thu, 12 Mar 2015 12:30:00 -0400
Subject: [PATCH] closes #2839 and #2840

---
 public/src/modules/composer/resize.js | 43 ++++++++++++++++-----------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/public/src/modules/composer/resize.js b/public/src/modules/composer/resize.js
index 8f37b0f76e..e353971e2f 100644
--- a/public/src/modules/composer/resize.js
+++ b/public/src/modules/composer/resize.js
@@ -19,11 +19,13 @@ define('composer/resize', ['autosize'], function(autosize) {
 			env = utils.findBootstrapEnvironment();
 		}
 
-		postContainer.percentage = percentage;
-
 		if (percentage) {
+			var max = getMaximumPercentage();
+
 			if (percentage < 0.25) {
 				percentage = 0.25;
+			} else if (percentage > max) {
+				percentage = max;
 			}
 
 			if (env === 'md' || env === 'lg') {
@@ -31,6 +33,8 @@ define('composer/resize', ['autosize'], function(autosize) {
 			}
 		}
 
+		postContainer.percentage = percentage;
+
 		// todo, lump in browsers that don't support transform (ie8) here
 		// at this point we should use modernizr
 		if (env === 'sm' || env === 'xs' || window.innerHeight < 480) {
@@ -94,7 +98,7 @@ define('composer/resize', ['autosize'], function(autosize) {
 
 		function toggleMaximize(e) {
 			if (e.clientY - resizeDown === 0 || snapToTop) {
-				var newPercentage = ($(window).height() - $('#header-menu').height() - 1) / $(window).height();
+				var newPercentage = getMaximumPercentage();
 
 				if (!postContainer.hasClass('maximized') || !snapToTop) {
 					oldPercentage = postContainer.percentage;
@@ -132,8 +136,9 @@ define('composer/resize', ['autosize'], function(autosize) {
 		}
 
 		function resizeSavePosition(px) {
-			var	percentage = px / $(window).height();
-			localStorage.setItem('composer:resizePercentage', percentage);
+			var	percentage = px / $(window).height(),
+				max = getMaximumPercentage();
+			localStorage.setItem('composer:resizePercentage', percentage < max ? percentage : max);
 		}
 
 		var	resizeActive = false,
@@ -142,23 +147,27 @@ define('composer/resize', ['autosize'], function(autosize) {
             snapToTop = false,
 			resizeEl = postContainer.find('.resizer');
 
-		resizeEl.on('mousedown', resizeStart);
-
-		resizeEl.on('touchstart', function(e) {
-			e.preventDefault();
-			resizeStart(e.touches[0]);
-		});
-
-		resizeEl.on('touchend', function(e) {
-			e.preventDefault();
-			resizeStop();
-		});
+		resizeEl
+			.on('mousedown', resizeStart)
+			.on('touchstart', function(e) {
+				e.preventDefault();
+				resizeStart(e.touches[0]);
+			})
+			.on('touchend', function(e) {
+				e.preventDefault();
+				resizeStop();
+			});
 	};
 
+	function getMaximumPercentage() {
+		return ($(window).height() - $('#header-menu').height() - 1) / $(window).height();
+	}
 
 	function resizeWritePreview(postContainer) {
 		var total = getFormattingHeight(postContainer);
-		postContainer.find('.write-preview-container').css('height', postContainer.percentage * $(window).height() - $('#header-menu').height() - total);
+		postContainer
+			.find('.write-preview-container')
+			.css('height', postContainer.percentage * $(window).height() - $('#header-menu').height() - total);
 	}
 
 	function getFormattingHeight(postContainer) {