Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tommy Pedersen 15 posts 65 karma points
    Aug 16, 2013 @ 12:32
    Tommy Pedersen
    0

    Help inserting richtext/simple editor into javascript variable

    Hello there.

    Im at the moment developing a site where i am using google maps api v3 and im trying to make it posible for the content editor to edit the content of an InfoWindow google.maps.InfoWindow with a richtext/simple editor my problem is when i insert the pagefield to the javascript variable controling the content of the InfoWindow, the content of the richtext editor is something like this <strong>Header</strong>Address field<a href="#">link</a> and i use the insert <br /> at linebreaks but when i insert the pagefield into my JavaScript code like this

    var iContent = "<article id='infoWindow' style='overflow: hidden;'><umbraco:Item field="infoWindow" convertLineBreaks="true" recursive="true" runat="server" /></article>";
    

    the data retrieved from the pagefield named infoWindow breaks out on more lines so the javascript code fails. i can fix this when adding \ to the end of all lines in the editor in the content section of umbraco. but this isn't optimal for the content editor if he wants to have tables/divs/other html stuff or something when he is editing the infowindows throughout the site.

    Result getting atm(here it breaks the lines of output from the pagefield):

    var iContent = "<article id='iWindow' style='overflow: hidden;'><strong>Header</strong><br />
        Knudsminde 7A<br />
        8300 Odder<br />
        <br />
        <a href='#' target='_blank'>Få rutevejledning</a><br /></article>";
    

    wanted result for no javascript error(the html is retrieved in on line of code without line breaks that javascript cant handle):

    var iContent = "<article id='iWindow' style='overflow: hidden;'><strong>Header</strong><br />Knudsminde 7A<br />8300 Odder<br /><br /><a href='#' target='_blank'>Få rutevejledning</a><br /></article>";
    

    hope you understand my problem. and that somebody have a solution for this problem.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Aug 20, 2013 @ 09:54
    Dave Woestenborghs
    0

    Can't you use a function to remove the line breaks ?

  • Tommy Pedersen 15 posts 65 karma points
    Aug 27, 2013 @ 10:10
    Tommy Pedersen
    0

    any suggestions for how that function should be created i've tried to wrap it inside a javascript function which gives the same issue.

    the posted javascript code breaks up like this when inserting it in a javascript function

    var iContent;
    function test(var teststring) {
        iContent = teststring;
    }
    
    test(<umbraco:Item field="infoWindow" convertLineBreaks="true" recursive="true" runat="server" />);
    

    results in

    test(<strong>Header</strong><br />
        Knudsminde 7A<br />
        8300 Odder<br />
        <br />
        <a href='#' target='_blank'>Få rutevejledning</a><br />);
    

    and if i set it on a onload it like this

    <body onload="test(<umbraco:Item field="infoWindow" convertLineBreaks="true" recursive="true" runat="server" />)">
    

    results in

    <body onload="test(<strong>Header</strong><br />
        Knudsminde 7A<br />
        8300 Odder<br />
        <br />
        <a href='#' target='_blank'>Få rutevejledning</a><br />)">
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies