From 948fd40ccdca048ad9bc8342a31bd2061f0707fd Mon Sep 17 00:00:00 2001
From: Mike Greiling <mike@pixelcog.com>
Date: Sun, 11 Dec 2016 21:48:49 -0600
Subject: [PATCH] add loading class to preview element and check it to prevent
 multiple ajax requests

---
 app/assets/javascripts/preview_markdown.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/assets/javascripts/preview_markdown.js b/app/assets/javascripts/preview_markdown.js
index bbdb1c10f33..b1a29b46133 100644
--- a/app/assets/javascripts/preview_markdown.js
+++ b/app/assets/javascripts/preview_markdown.js
@@ -23,10 +23,10 @@
       if (mdText.trim().length === 0) {
         preview.text('Nothing to preview.');
         this.hideReferencedUsers($form);
-      } else {
-        preview.text('Loading...');
+      } else if (!preview.hasClass('md-preview-loading')) {
+        preview.addClass('md-preview-loading').text('Loading...');
         this.fetchMarkdownPreview(mdText, (function(response) {
-          preview.html(response.body);
+          preview.removeClass('md-preview-loading').html(response.body);
           preview.renderGFM();
           this.renderReferencedUsers(response.references.users, $form);
         }).bind(this));
-- 
GitLab