From e1ff3deaf09b9101ef469a6880e13969e9f532a1 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 1 Apr 2015 17:23:54 -0400 Subject: [PATCH] move preview toggle function into composer/preview.js --- public/src/modules/composer.js | 25 +++---------------------- public/src/modules/composer/preview.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index f6dc3b9b31..106ee6a8b6 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -382,15 +382,17 @@ define('composer', [ }); bodyEl.val(draft ? draft : postData.body); + preview.render(postContainer, function() { preview.matchScroll(postContainer); }); + preview.handleToggler(postContainer); + drafts.init(postContainer, postData); resize.handleResize(postContainer); handleHelp(postContainer); - handleTogglePreview(postContainer); $(window).trigger('action:composer.loaded', { post_uuid: post_uuid @@ -419,27 +421,6 @@ define('composer', [ }); } - function handleTogglePreview(postContainer) { - var showBtn = postContainer.find('.write-container .toggle-preview'), - hideBtn = postContainer.find('.preview-container .toggle-preview'); - - hideBtn.on('click', function() { - $('.preview-container').addClass('hide'); - $('.write-container').addClass('maximized'); - showBtn.removeClass('hide'); - - $('.write').focus(); - }); - - showBtn.on('click', function() { - $('.preview-container').removeClass('hide'); - $('.write-container').removeClass('maximized'); - showBtn.addClass('hide'); - - $('.write').focus(); - }); - } - function updateTitle(postData, postContainer) { var titleEl = postContainer.find('.title'); diff --git a/public/src/modules/composer/preview.js b/public/src/modules/composer/preview.js index 7efadc28c6..5c2361cfa6 100644 --- a/public/src/modules/composer/preview.js +++ b/public/src/modules/composer/preview.js @@ -44,5 +44,26 @@ define('composer/preview', function() { preview.scrollTop(Math.max(preview[0].scrollHeight - preview.height(), 0) * scrollPercent); }; + preview.handleToggler = function(postContainer) { + var showBtn = postContainer.find('.write-container .toggle-preview'), + hideBtn = postContainer.find('.preview-container .toggle-preview'); + + hideBtn.on('click', function() { + $('.preview-container').addClass('hide'); + $('.write-container').addClass('maximized'); + showBtn.removeClass('hide'); + + $('.write').focus(); + }); + + showBtn.on('click', function() { + $('.preview-container').removeClass('hide'); + $('.write-container').removeClass('maximized'); + showBtn.addClass('hide'); + + $('.write').focus(); + }); + }; + return preview; }); \ No newline at end of file