| 1 |
var edButtons = new Array();
|
| 2 |
var edOpenTags = new Array();
|
| 3 |
var edCanvas = new Array();
|
| 4 |
|
| 5 |
function edButton(id, display, tagStart, tagEnd, access, open, location, icon) {
|
| 6 |
this.id = id; // used to name the toolbar button
|
| 7 |
this.display = display; // label on button
|
| 8 |
this.tagStart = tagStart; // open tag
|
| 9 |
this.tagEnd = tagEnd; // close tag
|
| 10 |
this.access = access; // access key
|
| 11 |
this.open = open; // set to -1 if tag does not need to be closed
|
| 12 |
this.location = location;
|
| 13 |
this.icon = icon;
|
| 14 |
}
|
| 15 |
|
| 16 |
function edAddTag(button) {
|
| 17 |
if (edButtons[button].tagEnd != '') {
|
| 18 |
edOpenTags[edOpenTags.length] = button;
|
| 19 |
document.getElementById(edButtons[button].id).alt = '/' + document.getElementById(edButtons[button].id).alt;
|
| 20 |
document.getElementById(edButtons[button].id).style.border = 'solid red 1px';
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
function edRemoveTag(button) {
|
| 25 |
for (i = 0; i < edOpenTags.length; i++) {
|
| 26 |
if (edOpenTags[i] == button) {
|
| 27 |
edOpenTags.splice(i, 1);
|
| 28 |
document.getElementById(edButtons[button].id).alt = document.getElementById(edButtons[button].id).alt.replace('/', '');
|
| 29 |
document.getElementById(edButtons[button].id).style.border = '';
|
| 30 |
}
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
function edCheckOpenTags(button) {
|
| 35 |
var tag = 0;
|
| 36 |
for (i = 0; i < edOpenTags.length; i++) {
|
| 37 |
if (edOpenTags[i] == button) {
|
| 38 |
tag++;
|
| 39 |
}
|
| 40 |
}
|
| 41 |
if (tag > 0) {
|
| 42 |
return true; // tag found
|
| 43 |
}
|
| 44 |
else {
|
| 45 |
return false; // tag not found
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
| 49 |
function edCloseAllTags(id) {
|
| 50 |
var count = edOpenTags.length;
|
| 51 |
for (o = 0; o < count; o++) {
|
| 52 |
edInsertTag(edCanvas[id], edOpenTags[edOpenTags.length - 1]);
|
| 53 |
}
|
| 54 |
}
|
| 55 |
|
| 56 |
// insertion code
|
| 57 |
function edInsertTag(myField, i) {
|
| 58 |
prevTop = myField.scrollTop;
|
| 59 |
//IE support
|
| 60 |
if (document.selection) {
|
| 61 |
myField.focus();
|
| 62 |
sel = document.selection.createRange();
|
| 63 |
if (sel.text.length > 0) {
|
| 64 |
sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
|
| 65 |
}
|
| 66 |
else {
|
| 67 |
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
|
| 68 |
sel.text = edButtons[i].tagStart;
|
| 69 |
edAddTag(i);
|
| 70 |
}
|
| 71 |
else {
|
| 72 |
sel.text = edButtons[i].tagEnd;
|
| 73 |
edRemoveTag(i);
|
| 74 |
}
|
| 75 |
}
|
| 76 |
myField.focus();
|
| 77 |
}
|
| 78 |
//MOZILLA/NETSCAPE support
|
| 79 |
else if (myField.selectionStart || myField.selectionStart == '0') {
|
| 80 |
var startPos = myField.selectionStart;
|
| 81 |
var endPos = myField.selectionEnd;
|
| 82 |
var cursorPos = endPos;
|
| 83 |
if (startPos != endPos) {
|
| 84 |
myField.value = myField.value.substring(0, startPos)
|
| 85 |
+ edButtons[i].tagStart
|
| 86 |
+ myField.value.substring(startPos, endPos)
|
| 87 |
+ edButtons[i].tagEnd
|
| 88 |
+ myField.value.substring(endPos, myField.value.length);
|
| 89 |
cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
|
| 90 |
}
|
| 91 |
else {
|
| 92 |
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
|
| 93 |
myField.value = myField.value.substring(0, startPos)
|
| 94 |
+ edButtons[i].tagStart
|
| 95 |
+ myField.value.substring(endPos, myField.value.length);
|
| 96 |
edAddTag(i);
|
| 97 |
cursorPos = startPos + edButtons[i].tagStart.length;
|
| 98 |
}
|
| 99 |
else {
|
| 100 |
myField.value = myField.value.substring(0, startPos)
|
| 101 |
+ edButtons[i].tagEnd
|
| 102 |
+ myField.value.substring(endPos, myField.value.length);
|
| 103 |
edRemoveTag(i);
|
| 104 |
cursorPos = startPos + edButtons[i].tagEnd.length;
|
| 105 |
}
|
| 106 |
}
|
| 107 |
myField.focus();
|
| 108 |
myField.selectionStart = cursorPos;
|
| 109 |
myField.selectionEnd = cursorPos;
|
| 110 |
}
|
| 111 |
else {
|
| 112 |
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
|
| 113 |
myField.value += edButtons[i].tagStart;
|
| 114 |
edAddTag(i);
|
| 115 |
}
|
| 116 |
else {
|
| 117 |
myField.value += edButtons[i].tagEnd;
|
| 118 |
edRemoveTag(i);
|
| 119 |
}
|
| 120 |
myField.focus();
|
| 121 |
}
|
| 122 |
myField.scrollTop = prevTop;
|
| 123 |
}
|
| 124 |
|
| 125 |
function edInsertContent(myField, myValue) {
|
| 126 |
prevTop = myField.scrollTop;
|
| 127 |
//IE support
|
| 128 |
if (document.selection) {
|
| 129 |
myField.focus();
|
| 130 |
sel = document.selection.createRange();
|
| 131 |
sel.text = myValue;
|
| 132 |
myField.focus();
|
| 133 |
}
|
| 134 |
//MOZILLA/NETSCAPE support
|
| 135 |
else if (myField.selectionStart || myField.selectionStart == '0') {
|
| 136 |
var startPos = myField.selectionStart;
|
| 137 |
var endPos = myField.selectionEnd;
|
| 138 |
myField.value = myField.value.substring(0, startPos)
|
| 139 |
+ myValue
|
| 140 |
+ myField.value.substring(endPos, myField.value.length);
|
| 141 |
myField.focus();
|
| 142 |
myField.selectionStart = startPos + myValue.length;
|
| 143 |
myField.selectionEnd = startPos + myValue.length;
|
| 144 |
} else {
|
| 145 |
myField.value += myValue;
|
| 146 |
myField.focus();
|
| 147 |
}
|
| 148 |
myField.scrollTop = prevTop;
|
| 149 |
}
|
| 150 |
|
| 151 |
|
| 152 |
function edShowButton(button, i, id) {
|
| 153 |
if (button.location) {
|
| 154 |
document.write('<a href="javascript:'+button.location+'(edCanvas[' + id + '], ' + i + ');" accesskey="' + button.access + '"><img src="' + button.icon + '" id="' + button.id + '" class="ed_button" alt="' + button.display + '" title="' + button.display + ' ('+ button.access +')"/></a>');
|
| 155 |
}
|
| 156 |
else {
|
| 157 |
document.write('<a href="javascript:edInsertTag(edCanvas['+ id +'], '+ i +');" accesskey="' + button.access + '"><img src="' + button.icon + '" id="' + button.id + '" class="ed_button" alt="' + button.display + '" title="' + button.display + ' ('+ button.access +')"/></a>');
|
| 158 |
}
|
| 159 |
}
|