I am trying to prevent nyroModal from loading more than once and have not
been successful using the same method I am using for other jQuery plugins.
Below is what I am trying to do.
if(!jQuery().nyroModalDebug){
jQuery("head").append('<scr' + 'ipt type="text/javascript"
src="<%=response.encodeURL(cntxPath +
"/js/nyroModal-1.5.2/js/jquery.nyroModal-1.5.2.min.js")%>"></scr' + 'ipt>');
jQuery("head").append('<link rel="stylesheet"
href="<%=response.encodeURL(cntxPath +
"/js/nyroModal-1.5.2/styles/nyroModal.css")%>" type="text/css" />');
console.log("loaded nyromodal plugin and css");
}
I have tried checking for jQuery().nyroModal, jQuery().nyroModalManual and
jQuery().nyroModalDebug, none of which work, as the script is still loading
multiple times (this is in a portal environment where each portlet contains
the above code).
I guess I could check for the existence of one of the main variables, like
modal, but that does not seem as safe and checking for a properly
namespaced function.
Any ideas as to how I can safely and effectively check to see if the
nyroModal plugin has already been loaded?
The nyroModalDebug function is not defined inside the jQuery object. Using jQuery().nyroModal might work. If not (as you said), you could test it with: if(!jQuery.fn.nyroModal){ // not loaded yet }