// Quicktags.js // by Alex King // http://www.alexking.org/ // Modified by Mike Cherim // http://green-beast.com/ var edButtons = new Array(); var edLinks = new Array(); var edOpenTags = new Array(); function edButton(id, display, tagStart, tagEnd, access, open) { 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 } function zeroise(number, threshold) { // FIXME: or we could use an implementation of printf in js here var str = number.toString(); if (number < 0) { str = str.substr(1, str.length) } while (str.length < threshold) { str = "0" + str } if (number < 0) { str = '-' + str } return str; } var now = new Date(); var datetime = now.getUTCFullYear() + '-' + zeroise(now.getUTCMonth() + 1, 2) + '-' + zeroise(now.getUTCDate(), 2) + 'T' + zeroise(now.getUTCHours(), 2) + ':' + zeroise(now.getUTCMinutes(), 2) + ':' + zeroise(now.getUTCSeconds() ,2) + '+00:00'; edButtons[edButtons.length] = new edButton('ed_strong' ,'strong' ,'' ,'' ,'a' ); edButtons[edButtons.length] = new edButton('ed_em' ,'emphasis' ,'' ,'' ,'b' ); edButtons[edButtons.length] = new edButton('ed_ital' ,'italic' ,'' ,'' ,'c' ); edButtons[edButtons.length] = new edButton('ed_link' ,'anchor' ,'' ,'' ,'d' ); // special case edButtons[edButtons.length] = new edButton('ed_img' ,'img' ,'' ,'' ,'s' ,-1 ); // special case edButtons[edButtons.length] = new edButton('ed_h1' ,'h1' ,'\n
\n' ,'\n\n' ,'l' ); edButtons[edButtons.length] = new edButton('ed_cite' ,'cite' ,'--- ' ,'' ,'m' ); edButtons[edButtons.length] = new edButton('ed_abbr' ,'abbr' ,'' ,'' ,'n' ); edButtons[edButtons.length] = new edButton('ed_acro' ,'acronym' ,'' ,'' ,'o' ); edButtons[edButtons.length] = new edButton('ed_span' ,'span' ,'' ,'' ,'p' ); edButtons[edButtons.length] = new edButton('ed_del' ,'del' ,'
\n' ,'\n\n' ,'4' ); edButtons[edButtons.length] = new edButton('ed_code' ,'code' ,'
'
,'
'
,'5'
);
edButtons[edButtons.length] =
new edButton('ed_amp'
,'&'
,'&'
,''
,'6'
);
edButtons[edButtons.length] =
new edButton('ed_leadcarr'
,'<'
,'<'
,''
,'7'
);
edButtons[edButtons.length] =
new edButton('ed_endcarr'
,'>'
,'>'
,''
,'8'
);
edButtons[edButtons.length] =
new edButton('ed_quot'
,'"'
,'"'
,''
,'9'
);
edButtons[edButtons.length] =
new edButton('ed_apos'
,'''
,'''
,''
,'['
);
edButtons[edButtons.length] =
new edButton('ed_dash'
,'-'
,'-'
,''
,']'
);
edButtons[edButtons.length] =
new edButton('ed_comment'
,''
,''
,'\\'
);
edButtons[edButtons.length] =
new edButton('ed_php'
,'php'
,'<?php'
,'?>'
,'`'
);
/*
edButtons[edButtons.length] =
new edButton('ed_more'
,'more'
,''
,''
,''
,-1
);
*/
/*
edButtons[edButtons.length] =
new edButton('ed_next'
,'page'
,''
,''
,''
,-1
);
*/
function edLink() {
this.display = '';
this.URL = '';
this.newWin = 0;
}
edLinks[edLinks.length] = new edLink('WordPress'
,'http://wordpress.org/'
);
edLinks[edLinks.length] = new edLink('alexking.org'
,'http://www.alexking.org/'
);
function edShowButton(button, i) {
if (button.id == 'ed_img') {
document.write('');
}
else if (button.id == 'ed_link') {
document.write('');
}
else {
document.write('');
}
}
function edShowLinks() {
var tempStr = '';
document.write(tempStr);
}
function edAddTag(button) {
if (edButtons[button].tagEnd != '') {
edOpenTags[edOpenTags.length] = button;
document.getElementById(edButtons[button].id).value = '/' + document.getElementById(edButtons[button].id).value;
}
}
function edRemoveTag(button) {
for (i = 0; i < edOpenTags.length; i++) {
if (edOpenTags[i] == button) {
edOpenTags.splice(i, 1);
document.getElementById(edButtons[button].id).value = document.getElementById(edButtons[button].id).value.replace('/', '');
}
}
}
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() {
var count = edOpenTags.length;
for (o = 0; o < count; o++) {
edInsertTag(edCanvas, edOpenTags[edOpenTags.length - 1]);
}
}
function edQuickLink(i, thisSelect) {
if (i > -1) {
var newWin = '';
if (edLinks[i].newWin == 1) {
newWin = ' target="_blank"';
}
var tempStr = ''
+ edLinks[i].display
+ '';
thisSelect.selectedIndex = 0;
edInsertContent(edCanvas, tempStr);
}
else {
thisSelect.selectedIndex = 0;
}
}
function edSpell(myField) {
var word = '';
if (document.selection) {
myField.focus();
var sel = document.selection.createRange();
if (sel.text.length > 0) {
word = sel.text;
}
}
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
if (startPos != endPos) {
word = myField.value.substring(startPos, endPos);
}
}
if (word == '') {
word = prompt('Enter a word to look up:', '');
}
if (word !== null && /^\w[\w ]*$/.test(word)) {
window.open('http://www.answers.com/' + escape(word));
}
}
function edToolbar() {
document.write('