Jump to content


Photo

Using jquery modules

jquery module

  • Please log in to reply
8 replies to this topic

#1 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 29

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 31 January 2012 - 02:43 PM

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

#2 diogo

diogo

    Hero Member

  • Moderators
  • 2,068 posts
  • 1179

  • LocationPorto, Portugal

Posted 31 January 2012 - 02:59 PM

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.

#3 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,586 posts
  • 906

  • LocationVihti, Finland

Posted 31 January 2012 - 03:00 PM

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

#4 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 31 January 2012 - 03:01 PM

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

@somartist | modules created | support me, flattr my work flattr.com


#5 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 29

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 31 January 2012 - 03:13 PM

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

#6 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,586 posts
  • 906

  • LocationVihti, Finland

Posted 31 January 2012 - 03:21 PM

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.

#7 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 31 January 2012 - 03:26 PM

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.

@somartist | modules created | support me, flattr my work flattr.com


#8 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 245 posts
  • 29

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 01 February 2012 - 02:28 AM

Thanks for the code Soma, but after reading the previous I'll stick to having a seperate (CDN hosted) jquery on the frontend. :)

/Jasåer

#9 ryan

ryan

    Hero Member

  • Administrators
  • 5,985 posts
  • 3386

  • LocationAtlanta, GA

Posted 01 February 2012 - 11:45 AM

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.





Also tagged with one or more of these keywords: jquery, module

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users