자바 스크립트로 Wordpress 편집기에 드롭 다운 선택 및 코드 버튼을 추가하려고합니다.자바 스크립트 기능에 기능 추가
나는 이미이 코드를 수정하려고 시도한이 사이트를 발견했습니다. 내가 여기서 말하는 내용을 볼 수 있으며, 드롭 다운에서 언어를 선택한 다음 해당 사이트의 코드 버튼을 클릭 할 수 있습니다.
http://bililite.com/blog/blogfiles/customeditor.html
jQuery(function ($) {
edButtons.forEach(function (button, index) {
if (button.display == 'code') {
// add language pull down menu
edButtons[index + 1] = { // insert right after the code button
html: function (idPrefix) {
return '<select id="' + idPrefix + 'code_language" data-code-target="' + index + '">' + '<option></option>' + // include a blank option
'<option>' + languages.join('</option><option>') + '</option>' + '</select>';
}
};
}
});
var languages = ['html', 'javascript', 'lisp', 'pdf', 'php', 'vb'];
$('body').on('change', 'select[data-code-target]', function() {
var lang = $(this).val();
// edButtons[$(this).data('code-target')].tagStart = lang ? '<code class="language-' + lang + '" >' : '<code>';
edButtons[$(this).data('code-target')].tagStart = lang ? '<pre><code data-language="' + lang + '">' : '<pre><code>';
});
});
이 어떤 언어가 dropdwon에서 선택하지 않은처럼이 코드는 현재 코드를 삽입 ...
<code></code>
그리고이 언어가 seleected 있습니다 ...
<code data-language="php"></code>
내가해야 할 일은 <pre> the above code here </pre>
태그로 마무리하는 것입니다. 위의 코드에서 시작 태그를 쉽게 추가 할 수 있지만 닫는 태그를 추가 할 수 없습니다. Javascript를 더 잘 아는 사람의 도움을받을 수 있습니다.
저것은 나에게 그것에, 이렇게 고맙게 여겨야한다! – JasonDavis