Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > open source javascript project - trouble with document.getElementById

Reply
Thread Tools

open source javascript project - trouble with document.getElementById

 
 
lawrence
Guest
Posts: n/a
 
      06-11-2004
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();


}





?>
 
Reply With Quote
 
 
 
 
Vincent van Beveren
Guest
Posts: n/a
 
      06-11-2004
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you open a Java open source project in an IDE Sathyaish Java 3 01-11-2007 12:19 PM
Open Source Conference in Japan: Open Source Realize Forum 2005 pat eyler Ruby 1 03-05-2005 03:50 AM
Adding a web application project to source control (Visual Source Safe) ~~~ .NET Ed ~~~ ASP .Net 1 02-26-2005 02:20 PM
open source project desperate for Javascript volunteer lawrence Javascript 0 09-27-2004 01:20 AM
Even open source has its trouble Dean Palladino Computer Security 3 08-29-2003 03:39 AM



Advertisments