views:

53

answers:

2

Hello Stack geniuses!

I have one jQuery plugin (colorbox) that loads a modal popup window (with an external html file). <-- works perfectly by itself. I have another jQuery plugin (jScrollPane) that loads custom scroll bars for divs. <-- it too works perfectly by itself. Both have a JS component and a CSS component.

My process thus far:

  1. I tried to load and initialize the scroll bar jQuery and CSS from the eternal html (popup) and my div disappeared.
  2. Then I tried to load the scroll bar jQuery in the parent window and initialize it in the colorbox callback...this time my div didn't disappear but the scroll bar and arrows (even OS standard arrows) did disappear.
  3. Finally, I put the scroll bar CSS in <style> tags and shoved it inside the eternal html file's <body> tags. That works on all major browsers, however, now you can't exit the popup window. Arg!

So I think my question is: how do you get jQuery plugins and their CSS files to initialize on dynamically loaded content? What goes where (incl. the jQuery library itself)?

Thanks!

A: 

If you are using the "window.open" type of popup, then I would say make it a little simpler and bring it into your page as a JQueryUI Dialog box that pulls in your external html file are the content, loading it in the DIV and accessible within the general page context, inheriting the JQuery and CSS as well. The simple form of this should be like:

$("#id").load(url).dialog(); 

Where #id is the DIV that is hidden and will contain your dialog data, and URL is the external url to the html file in your popup.

REW
unfortunately it's a modal, in-window popup...much like the JQueryUI Dialogue but a different plugin. And I have set it up much like you've suggested.
Emile
Maybe you could post a sample of the code for us to look?
REW
Hi REW...I just figured it out! I used iframes since my plugin was only pulling info out of the body tags (and thus not loading the required CSS for the other plugin to load). Thanks for your time in considering my issue!
Emile
Oh I see. What I was suggesting was to load the jScrollPane and colorbox plugins in the calling page, and the DIV would be inheriting the full scope of the base document.
REW
A: 

Found the solution....

My question was specifically on integrating colorbox (a jQuery lightbox plugin) with jScrollPane (a jQuery custom scrollbar plugin). My ajax call to load content with the colorbox worked, however, the jScrollPane could not initiate because the required wasn't loaded (because the ajax call didn't pull any info from the head tags).

If other Stack Overflowers stumble across a similar issue this is what I did to solve it: used iframes instead of an ajax call. Ooops. duh.

I don't know if colorbox is the only plugin that pulls info only from body tags and not the head but I imagine many plugins work this way when working with external files. If this is your problem, use iframes to ensure that the data in your head tag is pulled.

Thanks Stack Overflow anyhoo! I still love you.

Emile