From 9dce40f3afe925ccf4d6cca08160d106ab4e0113 Mon Sep 17 00:00:00 2001 From: Pierre Bondoerffer Date: Thu, 10 Aug 2017 14:34:48 +0200 Subject: [PATCH] only add the splitter once --- www/code/main.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/www/code/main.js b/www/code/main.js index 44cab6d36..ebdd52ede 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -388,30 +388,32 @@ define([ }); // add the splitter - var $preview = $iframe.find('#previewContainer'); - var splitter = $('
', { - 'class': 'cp-splitter' - }).appendTo($preview); - - $preview.on('scroll', function() { - splitter.css('top', $preview.scrollTop() + 'px'); - }); + if (!$iframe.has('.cp-splitter').length) { + var $preview = $iframe.find('#previewContainer'); + var splitter = $('
', { + 'class': 'cp-splitter' + }).appendTo($preview); + + $preview.on('scroll', function() { + splitter.css('top', $preview.scrollTop() + 'px'); + }); - var $target = $iframe.find('.CodeMirror'); + var $target = $iframe.find('.CodeMirror'); - splitter.on('mousedown', function (e) { - e.preventDefault(); - var x = e.pageX; - var w = $target.width(); + splitter.on('mousedown', function (e) { + e.preventDefault(); + var x = e.pageX; + var w = $target.width(); - $iframe.on('mouseup mousemove', function handler(evt) { - if (evt.type === 'mouseup') { - $iframe.off('mouseup mousemove', handler); - return; - } - $target.css('width', (w - x + evt.pageX) + 'px'); + $iframe.on('mouseup mousemove', function handler(evt) { + if (evt.type === 'mouseup') { + $iframe.off('mouseup mousemove', handler); + return; + } + $target.css('width', (w - x + evt.pageX) + 'px'); + }); }); - }); + } Cryptpad.removeLoadingScreen(); setEditable(true);