var edButtons = new Array();
var edOpenTags = new Array();
var edCanvas = new Array();
function edButton(id, display, tagStart, tagEnd, access, open, location) {
this.id = id; // used to name the toolbar button
this.display = display; // label on button
this.tagStart = tagStart; // open tag
this.tagEnd = tagEnd; // close tag
this.access = access; // access key
this.open = open; // set to -1 if tag does not need to be closed
this.location = location
}
edButtons[edButtons.length] = new edButton('ed_italic','kursywa','','','i');
edButtons[edButtons.length] = new edButton('ed_bold','pogrubienie','','','b');
edButtons[edButtons.length] = new edButton('ed_quote','cytat','
','
','c');
edButtons[edButtons.length] = new edButton('ed_list','lista','','l');
edButtons[edButtons.length] = new edButton('ed_number','lista numerowana','','
','n');
edButtons[edButtons.length] = new edButton('ed_element','element listy','','','e');
edButtons[edButtons.length] = new edButton('ed_link','link','','','l','0','edInsertLink');
edButtons[edButtons.length] = new edButton('ed_break','przerwa','','','t','-1');
edButtons[edButtons.length] = new edButton('ed_note','notka',' ',' ','n');
function edShowButton(button, i, id) {
if (button.location) {
document.write('');
}
else {
document.write('');
}
}
function edAddTag(button) {
if (edButtons[button].tagEnd != '') {
edOpenTags[edOpenTags.length] = button;
document.getElementById(edButtons[button].id).alt = '/' + document.getElementById(edButtons[button].id).alt;
document.getElementById(edButtons[button].id).style.border = 'solid red 1px';
}
}
function edRemoveTag(button) {
for (i = 0; i < edOpenTags.length; i++) {
if (edOpenTags[i] == button) {
edOpenTags.splice(i, 1);
document.getElementById(edButtons[button].id).alt = document.getElementById(edButtons[button].id).alt.replace('/', '');
document.getElementById(edButtons[button].id).style.border = '';
}
}
}
function edCheckOpenTags(button) {
var tag = 0;
for (i = 0; i < edOpenTags.length; i++) {
if (edOpenTags[i] == button) {
tag++;
}
}
if (tag > 0) {
return true; // tag found
}
else {
return false; // tag not found
}
}
function edCloseAllTags(id) {
var count = edOpenTags.length;
for (o = 0; o < count; o++) {
edInsertTag(edCanvas[id], edOpenTags[edOpenTags.length - 1]);
}
}
function edToolbar(id) {
document.write('');
}
// insertion code
function edInsertTag(myField, i) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
if (sel.text.length > 0) {
sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
}
else {
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
sel.text = edButtons[i].tagStart;
edAddTag(i);
}
else {
sel.text = edButtons[i].tagEnd;
edRemoveTag(i);
}
}
myField.focus();
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
var cursorPos = endPos;
if (startPos != endPos) {
myField.value = myField.value.substring(0, startPos)
+ edButtons[i].tagStart
+ myField.value.substring(startPos, endPos)
+ edButtons[i].tagEnd
+ myField.value.substring(endPos, myField.value.length);
cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
}
else {
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
myField.value = myField.value.substring(0, startPos)
+ edButtons[i].tagStart
+ myField.value.substring(endPos, myField.value.length);
edAddTag(i);
cursorPos = startPos + edButtons[i].tagStart.length;
}
else {
myField.value = myField.value.substring(0, startPos)
+ edButtons[i].tagEnd
+ myField.value.substring(endPos, myField.value.length);
edRemoveTag(i);
cursorPos = startPos + edButtons[i].tagEnd.length;
}
}
myField.focus();
myField.selectionStart = cursorPos;
myField.selectionEnd = cursorPos;
}
else {
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
myField.value += edButtons[i].tagStart;
edAddTag(i);
}
else {
myField.value += edButtons[i].tagEnd;
edRemoveTag(i);
}
myField.focus();
}
}
function edInsertContent(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
myField.focus();
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
myField.focus();
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
} else {
myField.value += myValue;
myField.focus();
}
}
function edInsertLink(myField, i, defaultValue) {
if (!defaultValue) {
defaultValue = 'http://';
}
if (!edCheckOpenTags(i)) {
var URL = prompt('Podaj URL' ,defaultValue);
if (URL) {
edButtons[i].tagStart = '';
edButtons[i].tagEnd = '';
edInsertTag(myField, i);
}
}
else {
edInsertTag(myField, i);
}
}
function edInsertFilm(myField, i, defaultValue) {
if (!defaultValue) {
defaultValue = '';
}
if (!edCheckOpenTags(i)) {
var URL = prompt('Podaj link do pliku FLV' ,defaultValue);
if (URL) {
edButtons[i].tagStart = "This text will be replaced
";
edInsertTag(myField, i);
}
}
else {
edInsertTag(myField, i);
}
}