2010-12-19 3 views
1

다음과 같은 HTML 고려 : 나는 캐럿이 텍스트 사업부에있을 원하는TinyMCE에 설정 초점

<div id="block-container"> 
    <div id="some-background"></div> 
    <div id="text-div">Focus should be here when this HTML goes into the editor</div> 
</div> 

을 - 더 정확하게 첫 번째 텍스트 요소에 -는 TinyMCE에 편집기에서 열 때.

".default-focused"같은 클래스를 이러한 요소에 추가하고 클래스를 기반으로 포커스를 설정할 수있는 방법이있을 수 있습니다. 이것을 달성하는 다른 (일반화 된) 방법이 있습니까?

나는 ".DEFAULT에 초점을 맞춘"방법을 갈 수없는 이유 : 더 중요한 것은, 사용자가 변경할 수 있습니다 2. 내가 가지고있는 데이터와 의 양을 고려 클래스를 추가하는 큰 작업이 될 수 1 HTML 및 클래스를 제거 할 수 있습니다. 당신이 알고있는 경우

답변

1

글쎄, 어떤 요소에 캐럿이 짧은 기능을

// sets the cursor to the specified element, ed ist the editor instance 
// start defines if the cursor is to be set at the start or at the end 
setCursor: function (ed, element, start) { 

    var doc = ed.getDoc(); 
    if (typeof doc.createRange != "undefined") { 
     var range = doc.createRange(); 
     range.selectNodeContents(element); 
     range.collapse(start); 
     var win = doc.defaultView || doc.parentWindow; 
     var sel = win.getSelection(); 
     sel.removeAllRanges(); 
     sel.addRange(range); 
    } else if (typeof doc.body.createTextRange != "undefined") { 
     var textRange = doc.body.createTextRange(); 
     textRange.moveToElementText(element); 
     textRange.collapse(start); 
     textRange.select(); 
    } 
}, 
+0

감사를 사용할 수 있습니다 배치하는 것입니다. 포커스를 설정해야하는 요소를 모르는 경우 다른 솔루션? – Saim

+0

아니요.하지만 요소를 가져올 수없는 시나리오의 이름을 지정 하시겠습니까? – Thariama