Well, it's easy to detect whether jQuery is loaded using plain
javascript, but once you've determined that it's not loaded, getting
it loaded in the correct order (particularly so that you can still use
document.ready()) gets tricky. You could create a custom version of
jquery.js that looks like this:

try{ jQuery } catch(err){ ...the rest of the jQuery code... }

That would partially solve your problem. Unfortunately, the browser
would still be loading multiple copies of the same script.

We use a server-side variable to register all the needed script paths,
and a separate routine includes them for us at the end of the page.
This way nothing gets duplicated. If you can't get the portal manager
to make any concessions for you, you might still be able to manage
this on the server side if you can control the order that your
portlets are loaded -- you'd just have to make sure a "utility
portlet" gets loaded as well. Far from elegant, but it might be your
best bet.

HTH,
Jason







On May 18, 11:17 pm, Shelane <[EMAIL PROTECTED]> wrote:
> Hey Jason,
>
> I thought it made sense too - the explanation of why it happens.
>
> Yes, it would be ideal if jquery were just added to the portal
> templates.  However, the developers don't have control over the portal
> templates.  They are strictly locked down, and there is no way the
> manager of the portal will put it in.  So we need to come up with
> another way of either dynamically adding the plugin, then using it, or
> detecting if jquery is already called before calling it again.  Of
> course, that last one would require that all developers do that, which
> may not happen.  It would be awesome if jquery itself would know that
> it's already been declared and not override itself if it was.
>
> On May 18, 7:42 pm, Jason Huck <[EMAIL PROTECTED]> wrote:
>
> > That makes sense. jQuery is loaded, then extended by loading a plugin,
> > but then replaced with a fresh, unaltered copy of jQuery, all of which
> > takes place before document.ready(), where the (by then nonexistent)
> > plugin is finally called.
>
> > I would consider including the base jQuery file via a stub or template
> > so that it's available on any/all pages in the system, then use
> > something like one of the .require() plugins to manage the loading of
> > additional plugins from within individual portlets. That's if you're
> > looking for a pure Javascript solution. You could do something similar
> > on the server side to prevent scripts from being loaded multiple
> > times.
>
> > - jason
>
> > On May 18, 9:33 pm, Shelane <[EMAIL PROTECTED]> wrote:
>
> > > if you have this in this order, the plugin call won't work.  it will
> > > give an error that the plugin function is not defined
>
> > > <script type="text/javascript" src="/scripts/jquery.pack.js"></script>
>
> > > <script type="text/javascript" src="/scripts/jquery.corner.js"></
> > > script>
>
> > > $(function(){
> > > $('#bodyframe').corner('tr');
>
> > > });
>
> > > <script type="text/javascript" src="/scripts/jquery.pack.js"></script>
>
> > > Since this is a portal, I may not know if the jquery was already
> > > included and I can't stop it being included in another portlet.

Reply via email to