为wordpress添加coolcode插件的quicktag

修改 wp-includes/js/quicktags.js 文件

1. 找到

  1. edButtons[edButtons.length] =
  2. new edButton('ed_code'
  3. ,'code'
  4. ,'<code>'
  5. ,'</code>'
  6. ,'c'
  7. );

在后面添加

  1. edButtons[edButtons.length] =
  2. new edButton('ed_coolcode'
  3. ,'coolcode'
  4. ,''
  5. ,'</coolcode>'
  6. ,'x'
  7. );

2. 找到

  1. else if (button.id == 'ed_link') {
  2.         document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
  3.     }

在后面添加

  1. else if (button.id == 'ed_coolcode') {
  2.         document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertCoolcode(edCanvas, ' + i + ');" value="' + button.display + '" />');
  3.     }

3. 在文件末尾添加

  1. function edInsertCoolcode(myField, i, defaultLang, defaultLine) {
  2.     if (!defaultLang) {
  3.         defaultLang = 'php';
  4.     }
  5.     if (!defaultLine) {
  6.         defaultLine = 'off';
  7.     }
  8.     if (!edCheckOpenTags(i)) {
  9.         var codeLang = prompt('输入需要加亮的程序语言', defaultLang);
  10.         var codeLine = prompt('是否显示行号(on, off)', defaultLine);
  11.         edButtons[i].tagStart = '<' + 'coolcode';
  12.         if (codeLang) {
  13.             edButtons[i].tagStart = edButtons[i].tagStart + ' lang="' 
  14.                                     + codeLang + '"'
  15.         }
  16.         if (codeLine) {
  17.             edButtons[i].tagStart = edButtons[i].tagStart + ' linenum="' 
  18.                                     + codeLine + '"';
  19.         }
  20.         edButtons[i].tagStart = edButtons[i].tagStart + '>';
  21.         edInsertTag(myField, i);
  22.     }
  23.     else {
  24.         edInsertTag(myField, i);
  25.     }
  26. }
Tags: coolcode, plugins, quicktags, wordpress

相关日志

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

还没有评论。

发表评论

(必填)

(必填)


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comment moderation is enabled. Your comment may take some time to appear.