selection to node

Last post 01-10-2014, 11:24 AM by marvin. 4 replies.
Sort Posts: Previous Next
  •  01-07-2014, 9:59 AM 78703

    selection to node

    Is it possible to get the first node from editor.GetRangePreviewHTML(); or get the selected node from the editor.
    I have made a custom element so to speak and I want to check the selection so that when you select this element you still get the same dialog but you edit the node instead of wrap it with the same node.

     

    For example I have a button wich changes selected text into:

    1. <footnote data-somevar="dialog value">selected text</footnote>  

    If you press the button again if you select the footnode or focus inside it you will get something like :&

    1. <footnote data-somevar="dialog value">
    2.     <footnote data-somevar="dialog value">selected text</footnote>
    3. </footnote>   
     And I don't want that.

  •  01-07-2014, 8:48 PM 78710 in reply to 78703

    Re: selection to node

    Dear marvin,

     

    Can you paste your code here? 

     

    Regards,

    Jeff 

  •  01-08-2014, 9:50 AM 78720 in reply to 78710

    Re: selection to node

    I'll do the custom Mark function, this opens a dialog wich allows you to mark the word you selected for later indexing and add a description.

    This is the one with the least amount of javascript.

    I still have to replace the handwritten html with "

    var element = editor.GetFrame().contentDocument.createElement("mark"); 

    " . But I first want the right functionality.

    1. var editor;  
    2. function RichTextEditor_OnLoad(rteeditor) {  
    3.     editor = rteeditor;  
    4.     editor.AttachEvent("ExecUICommand", CaptureSaveEvent);  
    5. }  
    6. function CaptureSaveEvent(rteeditor, info) {  
    7.     if (!rteeditor) return;  
    8.     if (!info || !info.Arguments || !info.Arguments[1]) return;  
    9.   
    10.     if (info.Arguments[1] == "DoMark") {  
    11.         // Todo edit if mark selected  
    12.   
    13.         var oldvalue = editor.GetRangePreviewHTML();  
    14.         editor.ShowXmlDialog("/richtexteditor/dialogs/mark.xml", {  
    15.             value: oldvalue,  
    16.             confirm: function (markvalue) {  
    17.                 if (!!markvalue && markvalue.trim() != "") {  
    18.                     var newvalue = "<mark data-value=\"" + markvalue + "\">" + oldvalue + "</mark>";  
    19.                     var insert = editor.InsertHTML(newvalue, true);  
    20.                     insert[0].Ox13.focus(0);  
    21.                     insert[0].Ox13.selectionStart = 0;  
    22.                     insert[0].Ox13.selectionEnd = 0;  
    23.                     editor.ExecCommand("CleanCode");  
    24.                 }  
    25.             }  
    26.         });  
    27.     }             
    28. }  
  •  01-09-2014, 11:18 PM 78732 in reply to 78720

    Re: selection to node

    Dear Marvin,

     

    I write a demo with mark

     

    1. if (info.Arguments[1] == "DoMark") {  
    2.     var nodes = editor.ExtractRangeNodes(false);  
    3.     var pointnode = editor.GetPointNode();  
    4.     if (nodes.length == 0) 
    5.        return; 
    6.     var root = pointnode;  
    7.     if (!root.Contains(nodes[0]))  
    8.         root = root.GetParent();  
    9.     if (nodes.length == 1) {  
    10.         //select 1 node  
    11.         if (nodes[0].GetName() == "mark" || (root.GetName() == "mark" && root.GetChildCount() == 1)) {  
    12.             //self is mark node  
    13.             alert(root.GetName() == "mark" ? root.GetAttribute("data-value") : nodes[0].GetAttribute("data-value"));  
    14.         }  
    15.         else {  
    16.             var mark = editor.ParseHtmlCode("<mark data-value=\"1\"></mark>")[0];  
    17.             editor.SurroundNode(mark);  
    18.             editor.Focus();  
    19.         }  
    20.     }  
    21.     else {  
    22.         //select multiple nodes  
    23.         if (root.GetName() == "mark" && root.GetChildCount() <= nodes.length) {  
    24.             //surround with mark node  
    25.             alert(root.GetAttribute("data-value"));  
    26.         }  
    27.         else {  
    28.             var html = editor.ExtractRangeHTML(true);  
    29.             var mark = "<mark data-value=\"2\">" + html + "</mark>";  
    30.             editor.InsertHTML(mark);  
    31.             editor.Focus();  
    32.         }  
    33.     }  
    34. }  
     

     

    Regards,

    Jeff 

  •  01-10-2014, 11:24 AM 78736 in reply to 78732

    Re: selection to node

    Thank you very much!
    I've made some modifications so it erases all the mark's inside if you select multiple mark's and you can now edit them.
    It's probably not the most efficient way to go but I'm still learning the editors API. 

     

    With kind regards,

    Marvin Brouwer. 

View as RSS news feed in XML