2012-03-19 1 views
4

무들의 (e- 러닝)에서 tinyMCE를 커스터마이징하고 있습니다. 텍스트 영역에 포커스를 설정하고 두 개의 달러 기호를 추가하는 툴바 버튼을 추가했습니다. 내가 필요한 것은 사용자가 그 사이에 타이핑을 시작할 수 있도록 해당 기호 사이에 커서를 놓는 것입니다. 아마도 가장 좋은 방법은 왼쪽 화살표를 programaticlly 누르는 것입니다. 그렇지 않습니까? 그러나 나는 그것을하는 방법을 이해할 수 없다. 코드는 다음과 같습니다.tinyMce의 keyPressEvent 발생

tinyMCE.init({ 
mode : "textareas", 
theme : "advanced", 
theme_advanced_buttons1 : "mybutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink", 
theme_advanced_buttons2 : "", 
theme_advanced_buttons3 : "", 
theme_advanced_toolbar_location : "top", 
theme_advanced_toolbar_align : "left", 
theme_advanced_statusbar_location : "bottom", 
plugins : 'inlinepopups', 
setup : function(ed) { 
    // Add a custom button 
    ed.addButton('mybutton', { 
     title : 'My button', 
     image : 'img/example.gif', 
     onclick : function() { 
      ed.focus(); 
      ed.selection.setContent('$$'); 
     } 
    }); 
} 

}); 감사합니다.

+0

+1 좋은 질문은 무에서 TinyMCE에 초기화 기능을 찾을 않았다 – Thariama

+0

? 자신의 init 함수를 만들었습니까? – glarkou

답변

1

이 당신이 원하는 일을해야 같은 수 있습니다 :

ed.addButton('mybutton', { 
    title : 'My button', 
    image : 'img/example.gif', 
    onclick : function() { 
     ed.focus(); 
     ed.selection.setContent('$<span id="my_marker">\u200b</span>$'); 
     var $marker = $(ed.getBody()).find('#my_marker'); 
     ed.selection.select($marker.get(0)); 
     $marker.remove(); 
    } 
}); 
+0

Thariama, 고맙습니다. – MartinM

+0

도움이 된 것을 기쁘게 생각합니다. – Thariama

0

다음 스 니펫을 사용하여 키 누르기 이벤트를 시작할 수 있습니다.

var e = jQuery.Event('keypress'); 
e.keyCode = 37; //Left arrow keycode 
$(document).trigger(e); 

사용은

onclick : function() { 
    ed.focus(); 
    ed.selection.setContent('$$'); 
    var e = jQuery.Event('keypress'); 
    e.keyCode = 37; //Left arrow keycode 
    $(document).trigger(e); 
} 
+0

좋은 생각이지만 IE에서는 작동하지 않습니다 – Thariama

관련 문제