From 336345ee83131931fd7883ee5ae17cae89d0ca6f Mon Sep 17 00:00:00 2001
From: Julian Lam <julian@designcreateplay.com>
Date: Thu, 25 Jul 2013 13:18:55 -0400
Subject: [PATCH] closed #137

---
 public/src/modules/composer.js | 38 ++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js
index fec1ce41c5..1d00f68172 100644
--- a/public/src/modules/composer.js
+++ b/public/src/modules/composer.js
@@ -1,7 +1,7 @@
 define(['taskbar'], function(taskbar) {
 	var composer = {
 			initialized: false,
-			active: 0,
+			active: undefined,
 			taskbar: taskbar,
 			posts: {},
 			postContainer: undefined,
@@ -222,6 +222,9 @@ define(['taskbar'], function(taskbar) {
 					break;
 				}
 			});
+			window.addEventListener('resize', function() {
+				if (composer.active !== undefined) composer.reposition(composer.active);
+			});
 
 			composer.initialized = true;
 		}
@@ -240,23 +243,15 @@ define(['taskbar'], function(taskbar) {
 		var post_data = composer.posts[post_uuid],
 			titleEl = composer.postContainer.querySelector('input'),
 			bodyEl = composer.postContainer.querySelector('textarea'),
-			postWindowEl = composer.postContainer.querySelector('.span5'),
-			taskbarBtn = document.querySelector('#taskbar [data-uuid="' + post_uuid + '"]'),
-			btnRect = taskbarBtn.getBoundingClientRect(),
-			taskbarRect = document.getElementById('taskbar').getBoundingClientRect(),
 			dropDiv = $(composer.postContainer).find('#imagedrop'),
-			imagelist = $(composer.postContainer).find('#imagelist'),
-			windowRect, leftPos;
+			imagelist = $(composer.postContainer).find('#imagelist');
 
 		dropDiv.hide();
 		imagelist.empty();
-		
 
-		composer.postContainer.style.display = 'block';
-		windowRect = postWindowEl.getBoundingClientRect();
-		leftPos = btnRect.left + btnRect.width - windowRect.width;
-		postWindowEl.style.left = (leftPos > 0 ? leftPos : 0) + 'px';
-		composer.postContainer.style.bottom = taskbarRect.height + "px";
+		composer.reposition(post_uuid);
+		composer.active = post_uuid;
+		
 		composer.postContainer.setAttribute('data-uuid', post_uuid);
 		if (parseInt(post_data.tid) > 0) {
 			titleEl.value = 'Replying to: ' + post_data.title;
@@ -271,8 +266,6 @@ define(['taskbar'], function(taskbar) {
 		}
 		bodyEl.value = post_data.body
 
-		
-
 		// Direct user focus to the correct element
 		if ((parseInt(post_data.tid) || parseInt(post_data.pid)) > 0) {
 			bodyEl.focus();
@@ -283,6 +276,20 @@ define(['taskbar'], function(taskbar) {
 		}
 	}
 
+	composer.reposition = function(post_uuid) {
+		var postWindowEl = composer.postContainer.querySelector('.span5'),
+			taskbarBtn = document.querySelector('#taskbar [data-uuid="' + post_uuid + '"]'),
+			btnRect = taskbarBtn.getBoundingClientRect(),
+			taskbarRect = document.getElementById('taskbar').getBoundingClientRect(),
+			windowRect, leftPos;
+
+		composer.postContainer.style.display = 'block';
+		windowRect = postWindowEl.getBoundingClientRect();
+		leftPos = btnRect.left + btnRect.width - windowRect.width;
+		postWindowEl.style.left = (leftPos > 0 ? leftPos : 0) + 'px';
+		composer.postContainer.style.bottom = taskbarRect.height + "px";
+	}
+
 	composer.post = function(post_uuid) {
 		// Check title and post length
 		var	postData = composer.posts[post_uuid],
@@ -349,6 +356,7 @@ define(['taskbar'], function(taskbar) {
 
 	composer.minimize = function(uuid) {
 		composer.postContainer.style.display = 'none';
+		composer.active = undefined;
 		taskbar.minimize('composer', uuid);
 	}