Skip to content

Commit c9971d7

Browse files
committed
Fix bug with IE 11 newline handling.
1 parent 90e9baf commit c9971d7

7 files changed

+49
-34
lines changed

CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Version 1.4.5:
3434
- Thanks to @PyYoshi for translating.
3535
Fixed bug with XHTML plugin stripping iframes.
3636
- Thanks to @tim-se for reporting.
37+
Fixed bug with IE11 newline handling.
3738

3839
Version 1.4.4:
3940
Fixed height auto expanding when resized.

minified/jquery.sceditor.bbcode.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minified/jquery.sceditor.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minified/jquery.sceditor.xhtml.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minified/plugins/bbcode.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.sceditor.js

+28-20
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
* @name jQuery.sceditor
106106
*/
107107
$.sceditor = function (el, options) {
108+
var IE_VER = $.sceditor.ie;
109+
110+
// In IE < 11 a BR at the end of a block level element
111+
// causes a double line break.
112+
var IE_BR_FIX = IE_VER && IE_VER < 11;
113+
108114
/**
109115
* Alias of this
110116
* @private
@@ -365,8 +371,8 @@
365371

366372
// Add IE version to the container to allow IE specific CSS
367373
// fixes without using CSS hacks or conditional comments
368-
if($.sceditor.ie)
369-
$editorContainer.addClass('ie ie' + $.sceditor.ie);
374+
if(IE_VER)
375+
$editorContainer.addClass('ie ie' + IE_VER);
370376

371377
isRequired = !!$original.attr('required');
372378
$original.removeAttr('required');
@@ -474,16 +480,16 @@
474480

475481
// Add IE version class to the HTML element so can apply
476482
// conditional styling without CSS hacks
477-
if($.sceditor.ie)
478-
$wysiwygDoc.find('html').addClass('ie ie' + $.sceditor.ie);
483+
if(IE_VER)
484+
$wysiwygDoc.find('html').addClass('ie ie' + IE_VER);
479485

480486
// iframe overflow fix for iOS, also fixes an IE issue with the
481487
// editor not getting focus when clicking inside
482-
if($.sceditor.ios || $.sceditor.ie)
488+
if($.sceditor.ios || IE_VER)
483489
{
484490
$wysiwygBody.height('100%');
485491

486-
if(!$.sceditor.ie)
492+
if(!IE_VER)
487493
$wysiwygBody.bind('touchend', base.focus);
488494
}
489495

@@ -545,7 +551,7 @@
545551
.bind('blur', valueChangedBlur)
546552
.keyup(valueChangedKeyUp)
547553
.bind('paste', handlePasteEvt)
548-
.bind($.sceditor.ie ? 'selectionchange' : 'keyup focus blur contextmenu mouseup touchend click', checkSelectionChanged)
554+
.bind(IE_VER ? 'selectionchange' : 'keyup focus blur contextmenu mouseup touchend click', checkSelectionChanged)
549555
.bind('keydown keyup keypress focus blur contextmenu', handleEvent);
550556

551557
if(options.emoticonsCompat && window.getSelection)
@@ -560,7 +566,7 @@
560566
$wysiwygDoc
561567
.mousedown(handleMouseDown)
562568
.bind('blur', valueChangedBlur)
563-
.bind($.sceditor.ie ? 'selectionchange' : 'focus blur contextmenu mouseup click', checkSelectionChanged)
569+
.bind(IE_VER ? 'selectionchange' : 'focus blur contextmenu mouseup click', checkSelectionChanged)
564570
.bind('beforedeactivate keyup', saveRange)
565571
.keyup(appendNewLine)
566572
.focus(function() {
@@ -704,7 +710,7 @@
704710
base.dimensions(newWidth, newHeight);
705711

706712
// The resize cover will not fill the container in IE6 unless a height is specified.
707-
if($.sceditor.ie < 7)
713+
if(IE_VER < 7)
708714
$editorContainer.height(newHeight);
709715
}
710716

@@ -745,7 +751,7 @@
745751
$(document).bind('touchend mouseup', mouseUpFunc);
746752

747753
// The resize cover will not fill the container in IE6 unless a height is specified.
748-
if($.sceditor.ie < 7)
754+
if(IE_VER < 7)
749755
$editorContainer.height(startHeight);
750756

751757
e.preventDefault();
@@ -1037,7 +1043,7 @@
10371043
base.dimensions = function(width, height, save) {
10381044
// IE6 & IE7 add 2 pixels to the source mode textarea height which must be ignored.
10391045
// Doesn't seem to be any way to fix it with only CSS
1040-
var ieBorderBox = $.sceditor.ie < 8 || document.documentMode < 8 ? 2 : 0;
1046+
var ieBorderBox = IE_VER < 8 || document.documentMode < 8 ? 2 : 0;
10411047

10421048
// set undefined width/height to boolean false
10431049
width = (!width && width !== 0) ? false : width;
@@ -1178,7 +1184,7 @@
11781184
maximize = !!maximize;
11791185

11801186
// IE 6 fix
1181-
if($.sceditor.ie < 7)
1187+
if(IE_VER < 7)
11821188
$('html, body').toggleClass('sceditor-maximize', maximize);
11831189

11841190
$editorContainer.toggleClass('sceditor-maximize', maximize);
@@ -1916,7 +1922,7 @@
19161922
*/
19171923
base.setWysiwygEditorValue = function (value) {
19181924
if(!value)
1919-
value = '<p>' + ($.sceditor.ie ? '' : '<br />') + '</p>';
1925+
value = '<p>' + (IE_VER ? '' : '<br />') + '</p>';
19201926

19211927
$wysiwygBody[0].innerHTML = value;
19221928
replaceEmoticons($wysiwygBody[0]);
@@ -2146,7 +2152,7 @@
21462152
*/
21472153
saveRange = function () {
21482154
/* this is only needed for IE */
2149-
if($.sceditor.ie)
2155+
if(IE_VER)
21502156
lastRange = rangeHelper.selectedRange();
21512157
};
21522158

@@ -2208,7 +2214,7 @@
22082214

22092215
// In IE, this is only called on the selectionchanged event so no need to
22102216
// limit checking as it should always be valid to do.
2211-
if($.sceditor.ie)
2217+
if(IE_VER)
22122218
check();
22132219
else
22142220
setTimeout(check, 100);
@@ -2377,15 +2383,15 @@
23772383

23782384
// find the last non-empty text node or line break.
23792385
if((node.nodeType === 3 && !/^\s*$/.test(node.nodeValue)) || name === 'br' ||
2380-
($.sceditor.ie && !node.firstChild && !$.sceditor.dom.isInline(node, false)))
2386+
(IE_BR_FIX && !node.firstChild && !$.sceditor.dom.isInline(node, false)))
23812387
{
23822388
// this is the last text or br node, if its in a code or quote tag
23832389
// then add a newline to the end of the editor
23842390
if(requiresNewLine)
23852391
{
23862392
div = $wysiwygBody[0].ownerDocument.createElement('div');
23872393
div.className = 'sceditor-nlf';
2388-
div.innerHTML = !$.sceditor.ie ? '<br />' : '';
2394+
div.innerHTML = !IE_BR_FIX ? '<br />' : '';
23892395
$wysiwygBody[0].appendChild(div);
23902396
}
23912397

@@ -3059,7 +3065,7 @@
30593065
var node, offset, tmpRange, range, parent;
30603066

30613067
// 8 is the backspace key
3062-
if($.sceditor.ie || options.disableBlockRemove || e.which !== 8 || !(range = rangeHelper.selectedRange()))
3068+
if(IE_VER || options.disableBlockRemove || e.which !== 8 || !(range = rangeHelper.selectedRange()))
30633069
return;
30643070

30653071
if(!window.getSelection)
@@ -3814,6 +3820,7 @@
38143820
}, true);
38153821

38163822
content.find('.button').click(function (e) {
3823+
var IE_VER = $.sceditor.ie;
38173824
var rows = content.find('#rows').val() - 0,
38183825
cols = content.find('#cols').val() - 0,
38193826
html = '<table>';
@@ -3825,7 +3832,7 @@
38253832
html += '<tr>';
38263833

38273834
for (var col=0; col < cols; col++)
3828-
html += '<td>' + ($.sceditor.ie ? '' : '<br />') + '</td>';
3835+
html += '<td>' + (IE_VER && IE_VER < 11 ? '' : '<br />') + '</td>';
38293836

38303837
html += '</tr>';
38313838
}
@@ -3989,6 +3996,7 @@
39893996
quote: {
39903997
forceNewLineAfter: ['blockquote'],
39913998
exec: function (caller, html, author) {
3999+
var IE_VER = $.sceditor.ie;
39924000
var before = '<blockquote>',
39934001
end = '</blockquote>';
39944002

@@ -4002,7 +4010,7 @@
40024010
}
40034011
// if not add a newline to the end of the inserted quote
40044012
else if(this.getRangeHelper().selectedHtml() === '')
4005-
end = $.sceditor.ie ? '' : '<br />' + end;
4013+
end = IE_VER && IE_VER < 11 ? '' : '<br />' + end;
40064014

40074015
this.wysiwygEditorInsertHtml(before, end);
40084016
},

src/plugins/bbcode.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
var escapeEntities = $.sceditor.escapeEntities;
2727
var escapeUriScheme = $.sceditor.escapeUriScheme;
2828

29+
var IE_VER = $.sceditor.ie;
30+
31+
// In IE < 11 a BR at the end of a block level element
32+
// causes a double line break.
33+
var IE_BR_FIX = IE_VER && IE_VER < 11;
34+
2935
/**
3036
* SCEditor BBCode parser class
3137
*
@@ -873,7 +879,7 @@
873879
{
874880
// Add placeholder br to end of block level elements in all browsers apart from IE < 9 which
875881
// handle new lines differently and doesn't need one.
876-
if(!$.sceditor.ie)
882+
if(!IE_BR_FIX)
877883
content += '<br />';
878884
}
879885

@@ -910,12 +916,12 @@
910916
// find one.
911917
// Cannot do zoom: 1; or set a height on the div to fix it as that
912918
// causes resize handles to be added to the div when it's clicked on/
913-
if((document.documentMode && document.documentMode < 8) || $.sceditor.ie < 8)
919+
if((document.documentMode && document.documentMode < 8) || IE_VER < 8)
914920
ret.push('\u00a0');
915921
}
916922

917923
// Putting BR in a div in IE causes it to do a double line break.
918-
if(!$.sceditor.ie)
924+
if(!IE_BR_FIX)
919925
ret.push('<br />');
920926

921927
// Normally the div acts as a line-break with by moving whatever comes
@@ -1534,7 +1540,7 @@
15341540
// The last block level as the last block level is collapsed.
15351541
// Is an li element.
15361542
// Is IE and the tag is BR. IE never collapses BR's
1537-
if(parentIsInline || parentLastChild !== element || tag === 'li' || (tag === 'br' && $.sceditor.ie))
1543+
if(parentIsInline || parentLastChild !== element || tag === 'li' || (tag === 'br' && IE_BR_FIX))
15381544
content += '\n';
15391545

15401546
// Check for <div>text<div>This needs a newline prepended</div></div>
@@ -1635,7 +1641,7 @@
16351641
// skip empty nlf elements (new lines automatically added after block level elements like quotes)
16361642
if($node.hasClass('sceditor-nlf'))
16371643
{
1638-
if(!firstChild || (!$.sceditor.ie && node.childNodes.length === 1 && /br/i.test(firstChild.nodeName)))
1644+
if(!firstChild || (!IE_BR_FIX && node.childNodes.length === 1 && /br/i.test(firstChild.nodeName)))
16391645
{
16401646
return;
16411647
}
@@ -1714,7 +1720,7 @@
17141720
if($.sceditor.dom.hasStyling(node))
17151721
return;
17161722

1717-
if($.sceditor.ie || (node.childNodes.length !== 1 || !$(node.firstChild).is('br')))
1723+
if(IE_BR_FIX || (node.childNodes.length !== 1 || !$(node.firstChild).is('br')))
17181724
{
17191725
while((next = node.firstChild))
17201726
output.insertBefore(next, node);

0 commit comments

Comments
 (0)