Fix queet box behaviour (around newlines) in firefox

This commit is contained in:
Takuma YOSHIOKA 2017-07-05 01:10:58 +09:00
parent a9e3c718b7
commit 6866a32026
No known key found for this signature in database
GPG Key ID: C36E8DCEA77569E5

View File

@ -2848,8 +2848,11 @@ $('body').on('click', '.queet-toolbar button',function () {
var queetBoxID = queetBox.attr('id'); var queetBoxID = queetBox.attr('id');
// jquery's .text() function is not consistent in converting <br>:s to \n:s, // jquery's .text() function is not consistent in converting <br>:s to \n:s,
// so we do this detour to make sure line breaks are preserved // so we do this detour to make sure line breaks are preserved.
queetBox.html(queetBox.html().replace(/<br>/g, '{{{lb}}}')); // In firefox (and maybe some other browsers), queetBox.html() may have <div>s
// and may or may not have <br> in them.
// To deal with this, remove any <br>s right before </div> and then add ones.
queetBox.html(queetBox.html().replace(/(<br>)*<\/div>/g, '<br></div>').replace(/<br>/g, '{{{lb}}}'));
var queetText = $.trim(queetBox.text().replace(/^\s+|\s+$/g, '').replace(/\n/g, '')); var queetText = $.trim(queetBox.text().replace(/^\s+|\s+$/g, '').replace(/\n/g, ''));
queetText = queetText.replace(/{{{lb}}}/g, "\n"); queetText = queetText.replace(/{{{lb}}}/g, "\n");