2

I am using Jquery Cluetip for my tool-tips. The tool-tip content is loaded with the AJAX function in Cluetip. In the loaded content I want to use Javascript to increase usability.

index.html:

<img src="edit.png" title="Test" class="popup" rel="ajax-content.html">

onLoad.js:

$('.popup').cluetip({activation: 'click'});

ajax-content.html:

<script language="javascript" type="text/javascript">
    alert('Hello world!');
</script>
Test content.

The result is a tool-tip appearing on click with the title:'Test', content:'Test content' and no alert saying 'Hello world!'. FireBug doesn't show the script nor console errors.

Any help on this?


Edit:

I figured it out.

Cluetip has a default action on processing ajax:

ajaxProcess: function(data) {
    data = data.replace(/<(script|style|title)[^<]+<\/(script|style|title)>/gm, '').replace(/<(link|meta)[^>]+>/g,'');
    return data;
}

So the fix is:

$('.popup').cluetip({
    activation: 'click'.
    ajaxProcess: function(data) {
        return data;
    }
});

I'm not sure why Cluetip removes all script/style/title, probably to prevent bugs.

Gijs P
  • 1,325
  • 12
  • 28

1 Answers1

1

scripts are generally not loaded via jquery's ajax fetching. You typically have to do this yourself via either $.getScript() or by finding script elements and loading the scripts youself.

I assume that cluetip does not do this for you via its rel loading functionality. Also, this is generally not a good idea, why are you trying to do this?

mkoryak
  • 57,086
  • 61
  • 201
  • 257
  • Cluetip offers these options by default. I am doing this to improve usability of my application (E.G. A datepicker on an input field inside the tooltip). Why wouldn't it be a good idea? – Gijs P Feb 14 '12 at 19:09
  • its usually a bad idea to include js files via ajax and run them, ther e is usually a better way to do this. for example: add a class 'datepicker' to all inputs requiring a datepicker. on the callback provided by cluetip 'ajaxprocess', find '.datepicker' in your newly added html and add datepickers to it. – mkoryak Feb 14 '12 at 20:50