first line problem in nicedit ?
Hello i have small problem with nicedit editor
the problem is
the first line is can not be affected !
example :
i writed ( asdad ) in the first line of the textarea box
i marked it and clicked on ( center align )
it's should go to the center of the box
see this picture
this problem is only in first line ..
others is work fine
The problem is only in firefox !
i am using firefox 3..... and i see this problem !
my code is
<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>
<textarea cols=40 rows=10></textar开发者_如何学Pythonea>
Thank you !
I also had that problem. And we are not alone:) It is nicEditor's bug http://nicedit.com/forums/viewtopic.php?f=4&t=364&p=848&#p848. And looks like it isn't fixed yet.
I've solved this bug by using TinyMCE-editor :) And if you are not tied with nicEditor I would suggest to look on TinyMCE.
I hope it will be helpfull.
I have developed a solution for this. The problem is the first line that is not in a div. This will fix it
$(document).ready(function () {
$('.nicEdit-main').bind('DOMSubtreeModified',function(){
nicEditFirstLinePatch();
});
});
and
function nicEditFirstLinePatch(){
function placeCaretAtEnd(el) {
el.focus();
if (typeof window.getSelection != "undefined"
&& typeof document.createRange != "undefined") {
var range = document.createRange();
range.selectNodeContents(el);
range.collapse(false);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.body.createTextRange != "undefined") {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}
}
textNode=$('.nicEdit-main').contents().filter(function(){
return this.nodeType == 3;
})[0];
$('.nicEdit-main').attr('id','toHandle');
if(textNode){
var newNode = document.createElement('div');
var newNodeContent = document.createTextNode(textNode.nodeValue);
newNode.appendChild(newNodeContent);
var parentNode=document.getElementById('toHandle');
parentNode.replaceChild(newNode,textNode);
var range = document.createRange();
range.setStart(newNode,0);
}
if(document.getElementById('toHandle').children.length==1){
placeCaretAtEnd(document.getElementById("toHandle"));
}
}
It works fine on Chrome 55.0.2883.87. I think it's crossbrowser but I'm not sure. however it is a good start :)
精彩评论