I'm loading jQuery embedded into RichFaces with:
<a4j:loadScript src="resource://jquery.js"/>
Next, I'm loading the FancyBox jQuery plugin with:
<script type="text/javascript" src="/App/fancybox/jquery.fancybox-1.3.4.pack.js"/>
The plugin works ok when the page is first loaded, however after executing an ajax call with
<a4j:jsFunction name="myMethod" data="#{myController.jsonDataToReturn}" action="#{myController.doSomething()}" oncomplete="populateData(data);">
<a4j:actionparam name="selectedTag" assignTo="#{myController.selectedTag}"/>
</a4j:jsFunction>
the plugin stops working. Tests show that the a4j:loadScript
tag is reloaded on every ajax call, thereby reloading the jQuery variable which loses the attached plugin.
The current workaround is to load jQuery by putting a <rich:jQuery query="fn" />
tag somewhere in the page. It does nothing besides forcing jQuery to load, but because it doesn't use a4j, jQuery isn't reloaded on ajax calls.
Still, is there a clean solution for this? I'm using RichFaces 3.3.3 which includes jQuery 1.3.2.
Update:
FancyBox is loaded with:
jQuery(document).ready( function(){
jQuery('.fancyboxLink').live('click',aclick);
});
function aclick(){
jQuery.fancybox({
href: '#{facesContext.externalContext.requestContextPath}/webpage.xhtml',
type:'iframe',
width:710,
height:510,
padding:0,
margin:0,
hideOnOverlayClick:false,
overlayColor:'#000'
});
return false;
}
After the first ajax call, jQuery no longer contains fancybox.