Jump to content

Using jquery modules


formmailer
 Share

Recommended Posts

Hi,

I don't really understand how to use the jquery modules. Until now I just loaded jquery and fancybox directly from my template, but this might not be the best way to go (although it gives the possibility to combine and compress all .js & .ccs files to improve loading times).

What should I do to load jquerycore and fancybox using the modules?

Thanks in advance!

/Jasper

Link to comment
Share on other sites

Slightly off topic, Why don't you load jQuery from a CDN like they recommend on the Fancybox website? Loading times should be better because tat copy of jQuery may be already cached on the user browser.

Link to comment
Share on other sites

I think you can do something along these lines, not sure though about side effects

<?php
// loads modules, that will add it to the script loading below
$this->modules->get("JqueryCore");
$this->modules->get("JqueryFancybox");
?>
<?php foreach($config->styles->unique() as $file) echo "\n\t<link type='text/css' href='$file' rel='stylesheet' />"; ?>

<?php foreach($config->scripts->unique() as $file) echo "\n\t<script type='text/javascript' src='$file'></script>"; ?>

Of course apeisa and diogo is right, but I just wanted to show it's possible.

Edit: while kinda on topic. Ryan, could we have an updated Fancybox? The current in PW "1.2.6" is way outdated. I always struggle to get iframes working. I could need some of the more advanced features, options in the PW admin. :D

Link to comment
Share on other sites

Slightly off topic, Why don't you load jQuery from a CDN like they recommend on the Fancybox website? Loading times should be better because tat copy of jQuery may be already cached on the user browser.

I actually do. :)

With a fallback, just in case the CDN is unavailable (I believe Google's CDN is blocked in some countries, although I don't expect many visitors from these countries...)

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
  if (typeof jQuery == 'undefined')
  {document.write(unescape("%3Cscript src='http%3A%2F%2Fmydomain.info%2Fjs%2Fjquery.min.1.7.1.js' type='text/javascript'%3E%3C/script%3E"));}
</script>

Those modules are intended for admin usage only. Are you trying to use those on your site or in admin module?

Thanks! That explains a lot. :lol: I assumed that these modules could be used in the site's front-end as well.

/Jasper

Link to comment
Share on other sites

I think they can be used on front-end also, especially if you take some code from admin templates. But that is not recommended or good practice, since you might need/want to use newer version of jQuery in your site than what is tested and shipped with PW admin. Also other way too - you might not want your front-end jQuery version change when you update PW.

Link to comment
Share on other sites

apeisa, it can be used, i posted code above already... :D

but I use it just for admin related tools, prototyping with bootstraping. It wouldn't be recomended using it in front-end production, because of the things apeisa mentioned.

Link to comment
Share on other sites

Slightly off topic, Why don't you load jQuery from a CDN like they recommend on the Fancybox website? Loading times should be better because tat copy of jQuery may be already cached on the user browser.

This is a good thing to do with your own sites, but not a good thing for ProcessWire to do since we can't safely assuming PW is "online". PW is used in some offline contexts. I develop offline too.

Those modules are intended for admin usage only. Are you trying to use those on your site or in admin module?

What Antti said is correct. I recommend including your own jQuery scripts for your site. While you certainly can use PW's jQuery modules, it's best to keep the needs of your site independent from the needs of the admin (to prevent a PW upgrade from breaking something in your site's javascript, for example). jQuery stuff isn't always backwards compatible.

Edit: while kinda on topic. Ryan, could we have an updated Fancybox? The current in PW "1.2.6" is way outdated. I always struggle to get iframes working. I could need some of the more advanced features, options in the PW admin.

I originally used 1.2.6 rather than the newer one, because the newer one was buggy, and having issues with new versions of jQuery. This may have changed in the last year (hopefully anyway). If anyone has a moment to check it out and test, I'll be happy to upgrade it. Otherwise I'll take care of it as soon as there's time to properly test on this end.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...