forked from tdiary/tdiary-core
/
hiki_help4plugin.rb
103 lines (74 loc) · 2.27 KB
/
hiki_help4plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
def help_pluginhelp_label
'プラグイン支援'
end
def help_plugin_label
'プラグイン'
end
def hiki_help4plugin
help = <<END_HELP
<script type="text/javascript"><!--
var pluginhelp_label = "#{help_pluginhelp_label}";
var plugin_label = "#{help_plugin_label}";
function add_pbttn( txt, tps, pre, suf ) {
add_bttn( ptlbr, txt, tps, pre, suf );
}
function add_ptxt( txt ) {
add_txt( ptlbr, txt );
}
END_HELP
help << <<'END_HELP'
function set_ptlbr() {
add_ptxt( "[" );
add_pbttn( plugin_label, "{{TEXT}}", "{{", "}}" );
add_ptxt( "]" );
}
END_HELP
help << <<END_HELP
tlbr_ids.push( "plugin_help" );
set_showbttn( pluginhelp_label, "plugin_help" );
var ptlbr = document.createElement( "div" );
ptlbr.id = "plugin_help";
ptlbr.style.display = "none";
set_ptlbr();
ins_tlbr( ptlbr );
// --></script>
END_HELP
help
end
# main
add_edit_proc do |date|
hiki_help4plugin
end
# オリジナルプラグイン用ボタン追加関数
def help_add_pbttn( help_txt, help_tps, help_pre, help_suf )
add_edit_proc do |date|
help = <<END_HELP
<script type="text/javascript"><!--
var txt = "#{help_txt}";
var tps = "#{help_tps}";
var pre = "#{help_pre}";
var suf = "#{help_suf}";
add_ptxt( "[" );
add_pbttn( txt, tps, pre, suf );
add_ptxt( "]" );
// --></script>
END_HELP
help
end
end
# 関数 help_add_pbttn( help_txt, help_tps, help_pre, help_suf ) の引数は
#
# help_txt : ボタンに表示されるテキスト
# help_tps : マウスをボタンの上に置いたとき表示されるテキスト
# help_pre : 選択している文字の前に追加するテキスト
# help_suf : 選択している文字の後に追加するテキスト
#
# help_tps で,改行は「\\n」,「'」は「\\'」,「"」は「\\\"」
# help_pre と help_suf ,で改行は「\\\\n」,「'」は「\\\\'」,「"」は「\\\"」
# と記述するとうまくいくようです。
#
# 使用例
#
# help_add_pbttn( "脚注", "{{fn\( \\'TEXT\\'\, \\'MARK\\' \)}}", "{{fn\( \\\\'", "\\\\'\\, \\\\'*\\\\' )}}" )
help_add_pbttn( "isbn_detail", "{{isbn_detail \\'TEXT\\'}}","{{isbn_detail \\\\'", "\\\\'}}" )
help_add_pbttn( "bq", "{{bq <<EOS, \\'TITLE\\', \\'URL\\'\\\\nEOS\\\\n}}","{{bq <<EOS, \\\\'", "\\\\', \\\\'\\\\'\\\\n\\\\nEOS\\\\n}}" )