2013-09-23 3 views
3

플러그인 개발을 위해 TinyMCE에 관한 문서에 문제가 있습니다. 단순히 내부 링크/외부 링크 중에서 선택할 수있는 팝업을 표시 한 다음 사이트의 다른 페이지를 선택하거나 사용자가 외부 링크를 삽입하도록합니다.TinyMCE : 팝업에서 정보 가져 오기

나는 다음과 같은 코드를 사용하고 창을 시작하려면 : 창 내부에로드되는

tinymce.PluginManager.add('insumolinks', function(editor, url) { 
    // Add a button that opens a window 
    editor.addButton('insumolinks', { 
     text: 'Link', 
     icon: false, 
     onclick: function() { 
      // Open window 
      editor.windowManager.open({ 
       title: 'Insert Link', 
       url: '/admin/pages/add_link', 
       onsubmit: function(e) { 
        // Insert content when the window form is submitted 
        // editor.insertContent('<a href="#">' + editor.selection.getContent() + '</a>'); 
        console.log(e.data);      
       } 
      }); 
     } 
    }); 
}); 

페이지는 다음과 같습니다

<div> 
    <select name="link_type" class="link_type" style="margin-top: 20px;"> 
    <option value="none">No Link</option> 
    <option value="other-page">Other Page</option> 
    <option value="external-link">External Link</option> 
</select> 
</div> 

<div> 
    <select name="link" class="resource-link" style="display: none;"> 
    <?php foreach($pages as $page) : ?> 
     <option value="<?= $page->id ?>" data-url="<?= $page->url ?>"> 
     <?= $page->title ?> 
    </option> 
    <?php endforeach; ?> 
</select> 
</div> 

<div> 
    <input type="text" name="link" class="resource-link" value="http://" style="display: none;"> 
</div> 

<div> 
<button type="submit" class="btn btn-primary">Add Link</button> 
</div> 
내가 보낼 실행해야 할 어떤 코드

연결 값은 onsubmit 호출을 통해?

문서에서 그들은 페이지를 만들기 위해 WindowManager를 사용하지만 다른 요소를 만드는 방법에 대한 많은 정보를 찾을 수 없습니다.

미리 감사드립니다.

+0

좋은 질문 :

나는 나의 초기화 섹션에서 외부

tinymce.init({ selector: "textarea.tinymce", external_plugins: { 'myplugin': 'url-to-my-plugin' } }); 

플러그인을 포함, 내 JS 플러그인을 만들었습니다. 나는 똑같이 이해하려고 노력하고있다. – TheTC

답변

5

이전 질문이지만 여전히 관련이 있습니다.

다음은 내가 한 일입니다. 나는 tinymce v4를 사용하고 있습니다.

jQuery에서 팝업/iframe을 찾고 있지만 바닐라 JS에서 쉽게 할 수 있습니다.

tinymce.PluginManager.add('myplugin', function(editor, url) { 
    // Adds a menu item to the tools menu 
    editor.addMenuItem('myplugin', { 
     id: 'myPluginId', 
     text: 'My Plugin Menu Title', 
     context: 'insert', 
     onclick: function() { 
     editor.windowManager.open({ 
      title: 'Title Of My Plugin', 
      url: 'myplugin.html', 
      //we create the submit buttons here instead of in our HTML page 
      buttons: [{ 
        text: 'Submit', 
        onclick: 'submit' 
       }, { 
        text: 'Cancel', 
        onclick: 'close' 
       }], 
      width: 500, 
      height: 325, 
      onsubmit: function(e) { 
       //find the popup, get the iframe contents and find the HTML form in the iFrame 
       form = $('#myPluginId iframe').contents().find('form'); 

       //once you have the form, you can do whatever you like with the data from here 
      } 
     }); 
     } 
    }); 
});