Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   open source javascript project - trouble with document.getElementById (http://www.velocityreviews.com/forums/t877847-open-source-javascript-project-trouble-with-document-getelementbyid.html)

lawrence 06-11-2004 03:05 AM

open source javascript project - trouble with document.getElementById
 
This PHP function prints out a bunch of Javascript (as you can see).
This is all part of the open source weblog software of PDS
(www.publicdomainsoftware.org). We had this javascript stuff working,
but it only worked for IE. You can see a working version here:

http://www.publicpen.com/designer/mcControlPanel.php
username: designer
password: designer123

However, I've tried to rewrite this so it would work in all browsers,
and now it is broken and working in none. I don't know much about
Javascript, but if any of the gurus here would like to donate some
time to an open source project, we could use the help. Can you tell me
what here is generating an error?









function elementsAdminShowFormattingButtons($id=false) {
// 05-04-04 - we want to print out some Javascript and some buttons.
// 06-10-04 - I've modified the functions so, hopefully, they will
work with
// more than just the InternetExplorer browser. I'm new to
Javascript, so
// it's a gamble.

$controllerForAll = & getController();
$config = getConfig();
$path = $config["imagesFolder"];

echo "
<script language=\"javascript\">
function insertAtCursor(myField) {
var imageName;
var path;
var myValue;
var status;
var myField;

myField = document.getElementById['inputId3'];
imageName = document.getElementById['imagesToInsert'].value;

path = '$path';
myValue = path+imageName;

status = myValue + ' - ' + myField;
window.status= status;

//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
} else if (myField.selectionStart || myField.selectionStart ==
'0') {
//MOZILLA/NETSCAPE support
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) + myValue +
myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}

function wrapSelectionBold (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<b>' + range.text + '<\/b>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<b>' + previousText +
'<\/b>';
alert('We did not find any selected text (only possible in some
browsers). We made all the text bold.');
}
}
function wrapSelectionItalic (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<i>' + range.text + '<\/i>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<i>' + previousText +
'<\/i>';
alert('We did not find any selected text (only possible in some
browsers). We made all the text italic');
}
}
function wrapSelectionBlockQuote (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<blockquote>' + range.text + '<\/blockquote>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<blockquote>' +
previousText + '<\/blockquote>';
alert('We did not find any selected text (only possible in some
browsers). We wrapped all the text in a block quote');
}
}
function wrapSelectionBigHeadline (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<h1>' + range.text + '<\/h1>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<h1>' + previousText +
'<\/h1>';
alert('We did not find any selected text (only possible in some
browsers). We wrapped all the text in a big headline');
}
}
function wrapSelectionSmallHeadline (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<h4>' + range.text + '<\/h4>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<h4>' + previousText +
'<\/h4>';
alert('We did not find any selected text (only possible in some
browsers). We wrapped all the text in a small headline');
}
}
function wrapSelectionAllowFileLists (element) {
var range = document.selection.createRange();
var address;
// 06-10-04 - this next bit is to avoid tripping the PHP parser.
Potential PHP bug.
address = '<';
address += '?php showFileInfoLists(); ?';
address += '>';
if (range.parentElement() == element) {
range.text = range.text + address;
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = range.text + address;
alert('We did not find any selected text (only possible in some
browsers). We added the special code to the end of the text.');
}
}
function wrapSelectionAllowImageLists (element) {
var range = document.selection.createRange();
var address;
// 06-10-04 - this next bit is to avoid tripping the PHP parser.
Potential PHP bug.
address = '<';
address += '?php showImageInfoLists(); ?';
address += '>';
if (range.parentElement() == element) {
range.text = range.text + address;
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = range.text + address;
alert('We did not find any selected text (only possible in some
browsers). We added the special code to the end of the text.');
}
}
function wrapSelectionMakeALink (element) {
var range = document.selection.createRange();
address = prompt('What address?', '');
address = '<a href=\\\"' + address + '\\\">';
if (range.parentElement() == element) {
range.text = address + range.text + '<\/a>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = address + 'See the
page<\/a>' + previousText;
alert('We did not find any selected text (only possible in some
browsers). We added the link to the beginning of the text.');
}
}
function wrapSelectionInsertImage (element) {
var range = document.selection.createRange();
address = prompt('Add address for image. If the image is on your
site, look in Image Info.', '');
address = '<img src=\\\"' + address + '\\\">';
if (range.parentElement() == element) {
range.text = address + range.text;
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = address + previousText;
alert('We did not find any selected text (only possible in some
browsers). We added the image to the beginning of the text');
}
}
</script>
";

echo "<input type=\"button\" value=\"bold\"
onclick=\"wrapSelectionBold(this.form.inputId".$id .")\" /> \n";
echo "<input type=\"button\" value=\"italic\"
onclick=\"wrapSelectionItalic(this.form.inputId".$ id.")\" /> \n";
echo "<input type=\"button\" value=\"block indent\"
onclick=\"wrapSelectionBlockQuote(this.form.inputI d".$id.")\" /> \n";
echo "<input type=\"button\" value=\"big headline\"
onclick=\"wrapSelectionBigHeadline(this.form.input Id".$id.")\" /> \n";
echo "<input type=\"button\" value=\"small headline\"
onclick=\"wrapSelectionSmallHeadline(this.form.inp utId".$id.")\" />
\n";
echo "<input type=\"button\" value=\"allow image lists\"
onclick=\"wrapSelectionAllowImageLists(this.form.i nputId".$id.")\" />
\n";
echo "<input type=\"button\" value=\"allow file lists\"
onclick=\"wrapSelectionAllowFileLists(this.form.in putId".$id.")\" />
\n";
echo "<input type=\"button\" value=\"make a link\"
onclick=\"wrapSelectionMakeALink(this.form.inputId ".$id.")\" /> \n";
flush();

$controllerForAll = & getController();
$forms = & $controllerForAll->getObject("McFormsGetImages", " in
elementsAdminEditImage01().");
$arrangementObject = & $controllerForAll->getObject("McArrangements",
" in elementsAdminEditImage01().");

$controlPanelCbId = $GLOBALS["controlPanelCbId"];
$cbId = $controlPanelCbId;
if (!$cbId) {
$cbId = $arrangementObject->getControlPanelCbId();
}

$forms->getChoicesForInput();
$forms->setChoicesIntoArray();


$field = $forms->returnCurrentValueForThisField($cbId,
"cbModifier01");
$visible = $field;
$value = $field;

$forms->setValueForCurrentField($visible, $value);
$forms->putIntoArrayForJavascriptInsert();
echo " <br>Insert an image: ";
$forms->printSelect();


}





?>

Vincent van Beveren 06-11-2004 07:29 AM

Re: open source javascript project - trouble with document.getElementById
 
> However, I've tried to rewrite this so it would work in all browsers,
> and now it is broken and working in none. I don't know much about
> Javascript, but if any of the gurus here would like to donate some
> time to an open source project, we could use the help. Can you tell me
> what here is generating an error?


I took a peek at it, and I did find one problem

location = document.body.scrollTop;
if (location == 0) location = document.documentElement.scrollTop;
if (location == 0) location = window.pageYOffset;
document.getElementById('scrollmenu').style.pixelT op = location;

'location' is a name of the location object. Modifiying it will
cause it to attempt to go to that location. Renaming location
to another name will cause Netscape 6 & 7 not to jump to
designer/0 all the time. The rest looks good to me, but I haven't
been able to test it much yet. What goes wrong in IE, cause thats
working for me too.

good luck,
Vincent



All times are GMT. The time now is 06:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.