Getting Error in pop up window

2 posts, 0 answers
  1. Amit
    Amit avatar
    12 posts
    Member since:
    Jul 2010

    Posted 01 Sep 2010 Link to this post

    Hi there,

    I am using the RadEditor for Moss 2007 of version 5_8_1.
    i have a Custom button in tool bar. Once the user is selecting anytext in the editor and click on this button i am populating this text to the pop up. In pop up i am getting some text  and i have a Insert Button in the popup. Using this Button i am trying to insert the text in the editor.

    I am using like

    window.opener.RTE_GetSelection("' + editor.get_id() + '").pasteHtml(popup); \n'

    But i am getting error that window.opener.RTE_GetSelection is null. what should i do here to insert the text as html markup in the editor.
    i have attached the full code here. let me know if anyone having anyidea.

    Telerik.Web.UI.Editor.CommandList["CustomCommand1"] = function(commandName, editor, args) {

        //this is the function that generates the "Popup" dialog.

        var selection = editor.getSelection();

        
        //get the selected text:
        var selectedText = selection.getText();
        //get the selected HTML:
        var selectedHTML = selection.getHtml();
        //get the currently selected HTML element
        var selElement = editor.getSelectedElement(); //or selection.getParentElement()
        //alert(editor);
        //alert("The selected text is: " + selectedText + ".\nThe selected HTML is: " + selectedHTML + ".\nThe selected HTML element is " + selElement.tagName + ".");
        //alert(editor.get_id());

        //this is the function that generates the "Popup" dialog.
        //alert("Inside embedPopup");
        // RTE_SaveSelection(editor);
        //var fieldValue = RTE_GetSelection(editor).text;

        var generator = window.open('', 'Parameters', 'height=300,width=300,scrollbar=no,menu=no,toolbar=no,status=no,location=no');
        generator.document.write('<html><head><title>Please input details</title>' +
        '<script type="text/javascript">function insertPopup() { \n' +
        'var popupText = document.getElementById("popupText").value; \n' +
        'var popupHeading = document.getElementById("popupHeading").value; \n' +
        'var popupDescription = document.getElementById("popupDescription").value; \n' +
        'var bValid = true; \n' +
        'var sErrorMessage = ""; \n' +
        'if (popupText == "") { \n' +
        '    sErrorMessage = "No text selected to create popup."; \n' +
        '    bValid = false; \n' +
        '} \n' +
        'else if (popupHeading == "") { \n' +
        '    sErrorMessage = "Please enter a heading for the popup."; \n' +
        '    bValid = false; \n' +
        '} \n' +
        'else if (popupDescription == "") { \n' +
        '    sErrorMessage = "Please enter a description text for the popup."; \n' +
        '    bValid = false; \n' +
        '} \n' +
        'if (sErrorMessage != "") \n' +
        '{ \n' +
        '    alert (sErrorMessage); \n' +
        '} else if (bValid) { \n' +
        '    var popup = "<span class=\\\"ept-contentdetail-body-hover-popup\\\" onmouseover=\\\"showBalloonTip(\'<b>"; \n' +
        '    popup = popup + popupHeading; \n' +
        '    popup = popup + "</b><br />"; \n' +
        '    popup = popup + popupDescription; \n' +
        '    popup = popup + "\',200)\\\" onmouseout=\\\"hideBalloonTip()\\\">"; \n' +
        '    popup = popup + popupText; \n' +
        '    popup = popup + "</span>"; \n' +
        '    if (!window.opener || window.opener.closed) { \n' +
        '        alert("Your popup could not be inserted because the editor page has been closed."); \n' +
        '    } else { \n' +
        '       alert("'+editor.get_id()+'");' +
        '        //window.opener.document.getElementById("' + editor + '_toolbarIframe").focus(); \n' +
        '         window.opener.RTE_GetSelection("' + editor.get_id() + '").pasteHtml(popup); \n' +
        '       //var editor="ctl00_ctloo_PlaceHolderMainParent_PlaceHolderMain_Content_ctl00_RadHtmlField1"; \n' +
        '    } \n' +
        '   alert("outside if");' +
        '    window.opener.RTE_RestoreSelection("' + editor + '"); \n' +
        '    window.close(); \n' +
        '} \n' +
        '}' + "<\/script>" +
        '</head><body style="margin:10px; font-family: verdana; font-size: 10px;">' +
        '<strong>Create Popup For:</strong> <input id="popupText" name="popupText" type="text" value="' + selectedText + '" readonly style="border: 1px black solid; width: 200px; font-family: verdana; font-size: 10px;"/><br/><span style="color: gray">(Hover would be created on this text)</span>' +
        '<br/> <br/>' +
        '<strong>Popup Heading:</strong> <input id="popupHeading" name="popupHeading" type="text" style="border: 1px black solid; width: 200px; font-family: verdana; font-size: 10px;"/><br/><span style="color: gray">(Enter the hover heading here)</span>' +
        '<br/> <br/>' +
        '<strong>Popup Description:</strong><br/>' +
        '<textarea id="popupDescription" name="popupDescription" style="width: 250px; height: 100px; border: 1px black solid; font-family: verdana; font-size: 10px;"></textarea>' +
        '<br/><span style="color: gray">(Enter the hover description here)</span><br/>' +
        '<input type="hidden" id="field" value="' + editor + '">' +
        '<br/> <br/><button style="font-family: verdana; font-size: 10px;" onclick="insertPopup()">Insert</button>' +
        '&nbsp;&nbsp;<button style="font-family: verdana; font-size: 10px;" onclick="window.close()">Close</button>' +
        '</body></html>');

        generator.document.close();


    Thanks
    Amit Kumar
  2. Stanimir
    Admin
    Stanimir avatar
    1653 posts

    Posted 03 Sep 2010 Link to this post

    Hi Amit,

    If you want to paste html code in the editor you need to use the pasteHtml client method. Review the following online help article: http://www.telerik.com/help/aspnet-ajax/editor_pastehtml.html.

    You can find information of how to create custom dialogs for RadEditor in the following online demo http://demos.telerik.com/aspnet-ajax/editor/examples/customdialogs/defaultcs.aspx.

    I hope this helps.

    Kind regards,
    Stanimir
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Back to Top