Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Cursor position in designMode IFrame

  1. #11
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    So, are there any alternatives, then? Or is it impossible to do?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I already mentioned:

    http://www.mozilla.org/editor/ie2midas.html

    And, if I recall correctly, someone else in this thread already suggested the use of a textarea on the iframe page.

    I did play around a bit with your code, I noticed that it outputted:

    Code:
    [b]Some initial text that's going to be bold[/b]
    to the iframe. And that in IE nothing was required to get the insertion point to automatically move to the end of the text inserted onload, but that in FF nothing (of the code used in your example) seemed able to do so.

    Anyways, if all you are trying to output is text, a textarea would be ideal.

    Just exactly what are you trying to do? DD's rich text editor is very good for what it does.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #13
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Ah, I see where the confusion is, now. It's a little complicated, but I will do my best to explain.

    The IFrame takes in custom PHPBB tags and formats them in real time to XHTML. While it does this, it also simultaniously captures the PHPBB portion of the code to a textarea (I will do this part on my own later, as I already know what to do for it-- or so I think). The PHPBB system that I am using is highly customized-- I created it myself specifically for my client-- so a normal editor won't work the way I want it to.

    The reason the [b] tags show up is because I took out the formattext() function and simply returned the string. The functions is very long and not really relevant to the problem I am facing. Suffice it to say that it changes the tags into valid XHTML.

    The trouble is that, when the IFrame's body's innerHTML is chaged, the curser moves to the end (in IE) or the beginning (in FF) rather than staying put. I understand why that is, but I don't know how to fix it. I also need to know how to insert PHPBB style tags into the editor when a user clicks a button.

    I am starting to doubt the possibility of creating such a JavaScript. The IFrame in designMode seems like it lacks some of the necessary features that I would need.

    Thanks, and let me know if that makes sense.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  4. #14
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi, i already finish my Rich Text Editor, but now i'm adding smilers, but also need to store the cursor position... i'll keep searching all about range objects etc

  5. #15
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I recently responded to another post that is somewhat related:

    http://www.dynamicdrive.com/forums/s...ad.php?t=35220

    There I show a way, at least with textarea, to store the cursor position (actually a position in the textarea's value's length that you want to reference later). If it isn't completely clear from that code, what you need to do is find the spot where the cursor is. This generally can be calculated if you know where it is in relation to the text already in the textarea, armed with that information, you can calculate the length of the value of the textarea up to that point.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #16
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    So I take it that what I am looking to accomplish is impossible with JavaScript?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. #17
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it can be done as most WYSIWYG's can do it, FCKEditor, tinyMCE and openwysiwyg but trying to look through there codes for answers is a pain in the rear end, I am also looking for the answer for to this question, when/if I figure it out I will post it here

  8. #18
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I found the answer, all along it was sat in a book on my shelf, o well use something like
    Code:
    insertSmilie: function(editorid,code){
      this.getEditor(editorid).contentWindow.focus();
      var emot = this.getEmot(code);
      var selection = null, range = null;
      var iframeWindow = document.getElementById('wysiwyg_'+editorid).contentWindow;
      var iframeDocument = iframeWindow.document;
      if(typeof iframeWindow.getSelection != 'undefined'){
        selection = iframeWindow.getSelection();
        if(typeof selection.getRangeAt != 'undefined')
          range = selection.getRangeAt(0);
        else if(typeof selection.baseNode != 'undefined'){
          range = iframeDocument.createRange();
          range.setStart(selection.baseNode,selection.baseOffset);
          range.setEnd(selection.extentNode,selection.extentOffset);
          if(range.collapsed){
            range.setStart(selection.extentNode,selection.extentOffset);
            range.setEnd(selection.baseNode,selection.baseOffset);
          }
        }
        var rangecopy = range.cloneRange();
        var newimg = iframeDocument.createElement('img');
        newimg.alt = emot[1];
        newimg.src = emot[2];
    		
        rangecopy.collapse(true);
        range.deleteContents();
        rangecopy.insertNode(newimg);
        //selection.collapse(newimg,newimg.length);
      } else if(typeof iframeDocument.selection != 'undefined'){
        selection = iframeDocument.selection;
        range = selection.createRange();
        range.pasteHTML('<img src="'+emot[2]+'" alt="'+emot[1]+'" />');
      } else {
        return false;
      }
      iframeWindow.focus();
      return true;
    },
    but unfortunately in my IE7 it seems to add the emot to the main window rather than the iframe, any ideas on how to fix that?
    Last edited by Chippo; 09-24-2008 at 07:09 PM.

  9. #19
    Join Date
    May 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    you may find the solution for this in http://samindaw.wordpress.com/2009/0...de-on-firefox/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •