1

We are building a website and for that we need to include an image map from a country and when you highlight a provence it needs to show some content below the map.

For this we are using jquery mapster (I'm not really a jquery programmer, so maybe you could help).

All works with the code below, but only when the content is on 1 line.

For example groningen: "<h1>Groningen</h1><p>test</test>", <-- This works

For example

groningen: "<h1>Groningen</h1>
<p>test</test>",

This does not work.

Below you will find my jquery code

<script type="text/javascript">
var $s = jQuery.noConflict(); 
$s(document).ready(function () {
       var image = $s('img');
       var data = {
            groningen: "<h1>Groningen</h1>
<p>test</test>",
            friesland: "<?php echo $extrafields[10];?>",
       };
       var defaultDipTooltip = 'I know you want the dip. But it\'s loaded with saturated fat, just skip it and enjoy as many delicious, crisp vegetables as you can eat.';

       image.mapster(
       {
            fillOpacity: 1,
            fillColor: "ff2d52",
            strokeColor: "ff2d52",
            strokeOpacity: 0.8,
            strokeWidth: 1,
            stroke: true,
            isSelectable: true,
            singleSelect: true,
            mapKey: 'name',
            listKey: 'name',
            onClick: function (e) {
                var newToolTip = defaultDipTooltip;
                $s('#selections').html(data[e.key]);
                if (e.key==='asparagus') {
                    newToolTip = "OK. I know I have come down on the dip before, but let's be real. Raw asparagus without any of that " +
                            "delicious ranch and onion dressing slathered all over it is not so good.";
                }
                image.mapster('set_options',{areas: [{
                    key: "dip",
                    toolTip: newToolTip
                    }]
                });
            },
            showToolTip: true,
            toolTipClose: ["tooltip-click", "area-click"],
            areas: [
                {
                    key: "groningen",
                    fillColor: "ff2d52",
                    toolTip: defaultDipTooltip
                },
                {
                    key: "friesland",
                    fillColor: "ff2d52"
                }
                ]
        });
      });
      </script>

Output

var data = {
    groningen: "<h1>Groningen</h1><p>test</test>",
    friesland: "<p>Scholen in de regio Groningen</p>
    \n<ul>
    \n<li>AOC Terra, Groene school<br />Adres<br />Winsum<br />Telefoonnummer<br />Naam directeur</li>
    \n<li>De Bolster<br />Adres<br />Groningen<br />Telefoonnummer<br />Naam directeur</li>
    \n<li>De Catamaran, School voor Praktijkonderwijs<br />Adres<br />Stadskanaal<br />telefoonnummer<br />Naam directeur</li>
    \n<li>Dollard College locatie De Flint</li>
    \n</ul>",
    }; 
WNR Design
  • 105
  • 1
  • 2
  • 13

1 Answers1

0

Javascript and by extension jQuery strings cannot go over a line boundry, you need to either add 2 strings together with a + or replace newlines with \n

Do some manipulation of your php array so each newline is replaced with \n

$UpdatedString = str_replace("\n", '\\n', $FieldValue);
Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • Could you explain how I can replace the newlines in my code? to \n. Because the data is generated from a CMS system. – WNR Design Dec 05 '12 at 22:54
  • Unfortunatly: I've updated the code, but the map doesn't respond on it. This is my php code: `item->extra_fields as $item) { $extrafields[$item->id] = $item->value; } $friesland = str_replace("\n", '\\n', $extrafields[9]); ?>` – WNR Design Dec 05 '12 at 23:04
  • so what do the strings look like when you view source – Toby Allen Dec 05 '12 at 23:05
  • `friesland: "

    Scholen in de regio Groningen

    \n
      \n
    • AOC Terra, Groene school
      Adres
      Winsum
      Telefoonnummer
      Naam directeur
    • \n
    • De Bolster
      Adres
      Groningen
      Telefoonnummer
      Naam directeur
    • \n
    • De Catamaran, School voor Praktijkonderwijs
      Adres
      Stadskanaal
      telefoonnummer
      Naam directeur
    • \n
    • Dollard College locatie De Flint
    • \n
    ", }; `
    – WNR Design Dec 05 '12 at 23:08
  • I cant see there, is it all on one line in your source code? If so then your problem is solved. For your next problem have you opened the chrome debugger to see what error javascript is throwing? – Toby Allen Dec 05 '12 at 23:10
  • No, everytime the \n is involved it startes on a new line (ive updated the code above so you can see it more clearly – WNR Design Dec 05 '12 at 23:13
  • use a test page until your php is outputting what you want then put it into your javascript and it should work. good Luck – Toby Allen Dec 05 '12 at 23:15