jp_AddButtons
2010年7月11日
記事編集時のボタンを追加するプラグイン、jp_AddButtonsを作成。

「<」を押すと、「<」と「>」が「<」と「>」に変更される。「>」ボタンは、その逆。「code」を押すと、変更した後に、前後に<pre class="code">と</pre>を追加する。
今のところ、他のタイプのボタンを追加する場合、ソースコードを変更する必要有り。このあたりの機能アップなどは、後ほど行いたい。
ソースコードは以下の通り。ただし、Jeansのバージョンを、SVN238かそれ以降にする必要有り。

「<」を押すと、「<」と「>」が「<」と「>」に変更される。「>」ボタンは、その逆。「code」を押すと、変更した後に、前後に<pre class="code">と</pre>を追加する。
今のところ、他のタイプのボタンを追加する場合、ソースコードを変更する必要有り。このあたりの機能アップなどは、後ほど行いたい。
ソースコードは以下の通り。ただし、Jeansのバージョンを、SVN238かそれ以降にする必要有り。
<?php
class jp_AddButtons extends plugin{
static public function name(){
return 'Add Button Plugin';
}
static public function author(){
return 'Katsumi';
}
static public function url(){
return 'http://jeanscms.sourceforge.jp/';
}
static public function desc(){
return 'This is to add buttons to edditing item page.';
}
static public function version(){
return '0.1';
}
static public function events(){
return array('pre_parse_ribbon');
}
static public function event_pre_parse_ribbon(&$array){
$ribbon=&$array['ribbon'];
//print_r($ribbon);
$ribbon[]=array(
'name'=>'htmlspecialchars',
'desc'=>'htmlspecialchars',
'script'=>'
var selection=jeans_edititem_selection(0)+"";
selection=selection.replace(/&/g,"&");
selection=selection.replace(/</g,"<");
selection=selection.replace(/>/g,">");
jeans_edititem_clear_around_cursor(0);
jeans_edititem_add_at_cursor(0,selection);
',
'type'=>'text',
'text'=>'<',
);
$ribbon[]=array(
'name'=>'htmlspecialchars_decode',
'desc'=>'htmlspecialchars_decode',
'script'=>'
var selection=jeans_edititem_selection(0)+"";
selection=selection.replace(/</g,"<");
selection=selection.replace(/>/g,">");
selection=selection.replace(/&/g,"&");
jeans_edititem_clear_around_cursor(0);
jeans_edititem_add_at_cursor(0,selection);
',
'type'=>'text',
'text'=>'>',
);
$ribbon[]=array(
'name'=>'code',
'desc'=>'pre class="code"',
'script'=>'
var selection=jeans_edititem_selection(0)+"";
selection=selection.replace(/&/g,"&");
selection=selection.replace(/</g,"<");
selection=selection.replace(/>/g,">");
selection="<pre class=\"code\">"+selection+"</pre>";
jeans_edititem_clear_around_cursor(0);
jeans_edititem_add_at_cursor(0,selection);
',
'type'=>'text',
'text'=>'code',
);
}
}