2014-09-21 13 views
1

嗨,尤其是我很努力,以防止允許坑多於3圖片在文本中,所以我想聽從按鈕圖像從插件tinymce是點擊,然後我可以防止默認過程如果超過2圖片已經在文本中,請如果任何人知道如何做到這一點?如何聽如果從tinymce工具欄中的按鈕是單擊,並防止默認功能,如果需要

我試着在

tinymce.init({ 

setup : function(editor) { 


editor.on('click', function(e) { 
        console.log(e); 
}); 
} 
}); 

但不是當我點擊圖片插件按鈕任何評論消防

謝謝

回答

0

爲什麼不能創建自己的插件?

我用WordPress管理內將以下代碼通過靶向上傳媒體彈出:

// Init tinyMCE 
tinymce.init({ 
    editor_selector: 'nwac_editor_' + nextPlusSignId, 
    mode: "specific_textareas", 
    media_buttons: false, 
    menubar: false, 
    relative_urls: false, 
    toolbar: 'undo redo formatselect bold italic alignleft aligncenter alignright alignjustify bullist numlist outdent indent plusimage', 
    setup: function(editor) { 
     editor.addButton('plusimage', { 
      icon: 'image', 
      tooltip: 'Insert/edit image', 
      onclick: function() { 

      // If the media frame already exists, reopen it. 
      if (file_frame) { 
       file_frame.open(); 
       return; 
      } 

      // Create the media frame. 
      file_frame = wp.media.frames.file_frame = wp.media({ 
       title: 'Choose an image for the plus sign', 
       button: { 
        text: 'Insert selected', 
       }, 
       multiple: false // Set to true to allow multiple files to be selected 
      }); 

      // When an image is selected, run a callback. 
      file_frame.on('select', function() { 
       // We set multiple to false so only get one image from the uploader 
       attachment = file_frame.state().get('selection').first().toJSON(); 

       //console.log(attachment); 

       editor.insertContent('<img src="' + attachment.url + '" data-mce-src="' + attachment.url + '" alt="' + attachment.alt + '">'); 

       return; 
      }); 

      // Finally, open the modal 
      file_frame.open(); 
      } 
     }); 
    }, 
    content_css: nw.baseurl + '/skins/wordpress/wp-content.css', 
    body_class: 'mce-content-body nwac_plus_signs_' + nextPlusSignId + '_template post-type-products post-status-publish mceContentBody webkit wp-editor wp-autoresize html4-captions has-focus', 

}); 
相關問題