Hi,
Right. But perhaps I have no explained the issue clearly enough. The issue comes that ' is still rendered as a single quotation mark in the browser. Thus, the caption parameter in the markup is still interrupted by this ‘, which creates the JS error.
The code above replaces the simple ' with \', which is rendered with \’ so that the single quotation mark is escaped and the JS parameter is not broken.
If I var_dump the string as it return from the shortcode, you can see it is this:
<a onclick="javascript: mg_image_carousel_open_lightbox('PATH_TO_IMAGE', 'on', '307', 'NAME on know Princeton's campus in New Jersey.');
That’s all well and good, but the browser interprets it as follows:
<a onclick="javascript: mg_image_carousel_open_lightbox('PATH_TO_IMAGE', 'on', '307', 'NAME on Princeton's campus in New Jersey.'); return false;"><img src="PATH_TO_IMAGE" alt="" title=""></a>
There’s the obvious problem that this string ‘NAME on Princeton’s campus in New Jersey.’ is broken by ‘ in Princeton’s. When clicking, this generates the following JS error since the string parameter is incorrect:
Uncaught SyntaxError: missing ) after argument list
since the string is now broken.
It should be as follows:
<a onclick="javascript: mg_image_carousel_open_lightbox('PATH_TO_IMAGE', 'on', '307', 'NAME on Princeton\'s campus in New Jersey.'); return false;"><img src="PATH_TO_IMAGE" alt="" title=""></a>
.
If you add a \ before ' within JS string parameters, it avoids this error. The code in my original post replaces ' with \ ' so that the single quotation mark is escaped in the browser.
I’m re-opening this issue.