-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditorbuttons.php
executable file
·48 lines (44 loc) · 1.46 KB
/
editorbuttons.php
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
<?php
$formats = array('Bold','Italic','URL','Teletype','Code');
foreach ($formats as $format) echo '<button class="formatbutton" type="button" onclick="doFormat' . $format . '()">' . $format . '</button>';
?>
<script type="text/javascript">
function surroundSelection(pre,post) {
var ta = document.getElementById("commentfield");
if (ta != null) {
var txt = ta.value, ss = ta.selectionStart, se = ta.selectionEnd;
ta.value = txt.substr(0,ss) + pre + txt.substring(ss,se) + post + txt.substr(se);
ta.selectionEnd = se + pre.length;
ta.selectionStart = ss + pre.length;
ta.focus();
}
}
function doFormatBold() {
surroundSelection("**","**");
return false;
}
function doFormatItalic() {
surroundSelection("*","*");
return false;
}
function doFormatURL() {
var ta = document.getElementById("commentfield");
if (ta != null) {
var txt = ta.value, ss = ta.selectionStart, se = ta.selectionEnd;
var url = prompt("Enter the URL to point to:", "www.google.com");
var pgname = (ss != se)? txt.substring(ss,se): prompt("Enter the text to display for this link", url);
ta.value = txt.substr(0,ss) + "[" + pgname + "](" + url + ")" + txt.substr(se);
ta.selectionStart = ss + 1;
ta.selectionEnd = ta.selectionStart + pgname.length;
ta.focus();
}
return false;
}
function doFormatTeletype() {
surroundSelection("`","`");
return false;
}
function doFormatCode() {
surroundSelection("```C++\n", "\n```");
}
</script>