open source javascript project - trouble with document.getElementById

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    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:


    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 elementsAdminSh owFormattingBut tons($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 InternetExplore r browser. I'm new to
    Javascript, so
    // it's a gamble.

    $controllerForA ll = & getController() ;
    $config = getConfig();
    $path = $config["imagesFold er"];

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

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

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

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

    //IE support
    if (document.selec tion) {
    myField.focus() ;
    sel = document.select ion.createRange ();
    sel.text = myValue;
    } else if (myField.select ionStart || myField.selecti onStart ==
    '0') {
    //MOZILLA/NETSCAPE support
    var startPos = myField.selecti onStart;
    var endPos = myField.selecti onEnd;
    myField.value = myField.value.s ubstring(0, startPos) + myValue +
    myField.value.s ubstring(endPos , myField.value.l ength);
    } else {
    myField.value += myValue;
    }
    }

    function wrapSelectionBo ld (element) {
    var range = document.select ion.createRange ();
    if (range.parentEl ement() == element) {
    range.text = '<b>' + range.text + '<\/b>';
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionIt alic (element) {
    var range = document.select ion.createRange ();
    if (range.parentEl ement() == element) {
    range.text = '<i>' + range.text + '<\/i>';
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionBl ockQuote (element) {
    var range = document.select ion.createRange ();
    if (range.parentEl ement() == element) {
    range.text = '<blockquote>' + range.text + '<\/blockquote>';
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionBi gHeadline (element) {
    var range = document.select ion.createRange ();
    if (range.parentEl ement() == element) {
    range.text = '<h1>' + range.text + '<\/h1>';
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionSm allHeadline (element) {
    var range = document.select ion.createRange ();
    if (range.parentEl ement() == element) {
    range.text = '<h4>' + range.text + '<\/h4>';
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionAl lowFileLists (element) {
    var range = document.select ion.createRange ();
    var address;
    // 06-10-04 - this next bit is to avoid tripping the PHP parser.
    Potential PHP bug.
    address = '<';
    address += '?php showFileInfoLis ts(); ?';
    address += '>';
    if (range.parentEl ement() == element) {
    range.text = range.text + address;
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionAl lowImageLists (element) {
    var range = document.select ion.createRange ();
    var address;
    // 06-10-04 - this next bit is to avoid tripping the PHP parser.
    Potential PHP bug.
    address = '<';
    address += '?php showImageInfoLi sts(); ?';
    address += '>';
    if (range.parentEl ement() == element) {
    range.text = range.text + address;
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionMa keALink (element) {
    var range = document.select ion.createRange ();
    address = prompt('What address?', '');
    address = '<a href=\\\"' + address + '\\\">';
    if (range.parentEl ement() == element) {
    range.text = address + range.text + '<\/a>';
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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 wrapSelectionIn sertImage (element) {
    var range = document.select ion.createRange ();
    address = prompt('Add address for image. If the image is on your
    site, look in Image Info.', '');
    address = '<img src=\\\"' + address + '\\\">';
    if (range.parentEl ement() == element) {
    range.text = address + range.text;
    } else {
    var previousText;
    previousText = document.getEle mentById[element].value;
    document.getEle mentById[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=\"wrapS electionBold(th is.form.inputId ".$id.")\" /> \n";
    echo "<input type=\"button\" value=\"italic\ "
    onclick=\"wrapS electionItalic( this.form.input Id".$id.")\" /> \n";
    echo "<input type=\"button\" value=\"block indent\"
    onclick=\"wrapS electionBlockQu ote(this.form.i nputId".$id.")\ " /> \n";
    echo "<input type=\"button\" value=\"big headline\"
    onclick=\"wrapS electionBigHead line(this.form. inputId".$id.") \" /> \n";
    echo "<input type=\"button\" value=\"small headline\"
    onclick=\"wrapS electionSmallHe adline(this.for m.inputId".$id. ")\" />
    \n";
    echo "<input type=\"button\" value=\"allow image lists\"
    onclick=\"wrapS electionAllowIm ageLists(this.f orm.inputId".$i d.")\" />
    \n";
    echo "<input type=\"button\" value=\"allow file lists\"
    onclick=\"wrapS electionAllowFi leLists(this.fo rm.inputId".$id .")\" />
    \n";
    echo "<input type=\"button\" value=\"make a link\"
    onclick=\"wrapS electionMakeALi nk(this.form.in putId".$id.")\" /> \n";
    flush();

    $controllerForA ll = & getController() ;
    $forms = & $controllerForA ll->getObject("McF ormsGetImages", " in
    elementsAdminEd itImage01().");
    $arrangementObj ect = & $controllerForA ll->getObject("McA rrangements",
    " in elementsAdminEd itImage01().");

    $controlPanelCb Id = $GLOBALS["controlPanelCb Id"];
    $cbId = $controlPanelCb Id;
    if (!$cbId) {
    $cbId = $arrangementObj ect->getControlPane lCbId();
    }

    $forms->getChoicesForI nput();
    $forms->setChoicesInto Array();


    $field = $forms->returnCurrentV alueForThisFiel d($cbId,
    "cbModifier01") ;
    $visible = $field;
    $value = $field;

    $forms->setValueForCur rentField($visi ble, $value);
    $forms->putIntoArrayFo rJavascriptInse rt();
    echo " <br>Insert an image: ";
    $forms->printSelect( );


    }





    ?>
  • Vincent van Beveren

    #2
    Re: open source javascript project - trouble with document.getEle mentById

    > However, I've tried to rewrite this so it would work in all browsers,[color=blue]
    > 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?[/color]

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

    location = document.body.s crollTop;
    if (location == 0) location = document.docume ntElement.scrol lTop;
    if (location == 0) location = window.pageYOff set;
    document.getEle mentById('scrol lmenu').style.p ixelTop = 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

    Comment

    Working...