2016-09-08 7 views
2

현재 summernote 0.8.2를 사용하고 있으며 텍스트가 사전로드 된 메모를 사용하고 있습니다. 텍스트가로드되면 초점을 맞추고 싶지만 줄의 끝에 초점을 맞추고 싶습니다. 나는 API을 기반으로 초점을 맞추려고했습니다. 그러나 초점을 맞추었지만 줄의 끝에서 시작하지 않습니다. 다음은 this 질문을 기반으로 한 작업의 예입니다. 도와주세요. Summernote 텍스트 끝 부분에 초점 맞추는 방법

$("#myNote").summernote({ 
 
      toolbar: [ 
 
       ['para', ['ul']] 
 
      ], 
 
      focus: true 
 
     }); 
 
$('.note-editor [data-event="insertUnorderedList"]').tooltip('disable'); 
 

 
$('.note-btn.btn.btn-default.btn-sm').attr('data-original-title',''); 
 

 

 
var html = "<ul><li>item 1</li><li>item 2<br></li></ul>"; 
 
$("#myNote").summernote('code',html); 
 
$("#myNote").focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script> 
 
<script> 
 
$(document).ready(function() { 
 
    $.fn.extend({ 
 
     placeCursorAtEnd: function() { 
 
      // Places the cursor at the end of a contenteditable container (should also work for textarea/input) 
 
      if (this.length === 0) { 
 
       throw new Error("Cannot manipulate an element if there is no element!"); 
 
      } 
 
      var el = this[0]; 
 
      var range = document.createRange(); 
 
      var sel = window.getSelection(); 
 
      var childLength = el.childNodes.length; 
 
      if (childLength > 0) { 
 
       var lastNode = el.childNodes[childLength - 1]; 
 
       var lastNodeChildren = lastNode.childNodes.length; 
 
       range.setStart(lastNode, lastNodeChildren); 
 
       range.collapse(true); 
 
       sel.removeAllRanges(); 
 
       sel.addRange(range); 
 
      } 
 
      return this; 
 
     } 
 
    }); 
 
}); 
 
</script> 
 
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet"/> 
 
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script> 
 
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet"/> 
 

 

 
<div id="myNote"></div>

답변

0

대신 초기화 Summernote 편집기에 초점 메소드를 호출은 사용자에게 jQuery를 방법 placeCursorAtEnd 대신를 호출하려고 (I 후 "항목이"커서가되고 싶습니다).

나 자신이 라인을 따라 뭔가를하고 있어요 : this.advancedEditor는 옵션입니다

var $el = this.$el; 
$el.find('.inline-preview .component-text-editor') 
    .summernote(this.advancedEditor) 

$el.find('[contenteditable]').placeCursorAtEnd(); 

우리 summernote 초기화 메서드에 전달되는 객체.

관련 문제