Welcome to Geeklog, Anonymous Friday, November 29 2024 @ 10:51 pm EST

Geeklog Forums

How to load javascript (jquery) only once


Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hello,

I would like to load javascript (jquery) only once and use it in more than one plugin.
I could set this in the layout but how to make this possible with multi layout compatibility?

Thanks,

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
This is how I'm doing it with my two jQuery plugins:
in plugin_getheadercode_pluginName
php -
Text Formatted Code

if(!defined('JQUERY')){
    $headerText .= '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>'."\n";
    define('JQUERY', 'true');
}
 


Also we have to use jQuery in compatibility mode especially if we are dealing with mootools as well:
javascript-
Text Formatted Code

if(jQueryNoConflict == undefined){
    jQuery.noConflict();
    var jQueryNoConflict = true;
}
 


If we all do this, our plugins will play well together.

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Thank you, it is a good way.

Could we choose and use a shortcut for all Geeklog plugins
Text Formatted Code
 $j = jQuery.noConflict();

or do we have to use "jQuery" when you do some work with jQuery?

::Ben

I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
Ben,
Part of using jQuery in noConflict mode relinquishes the dollar sign($) so if any other library is using it they don't conflict.

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Yes, so as plugin developpers for Geeklog, we could plan to use a new shortcut as $j or do you prefere to use the complete word "jQuery".
We had to decide it now to armonise each others and to avoid any conflict between our plugins. Then, every new plugin developper for Geeklog will be encourage to use the same shortcut.

Text Formatted Code
        if(!defined('JQUERY')){
        $str .= '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>'. LB;
                $str .= '<script>
    if(jQueryNoConflict == undefined){
    $j = jQuery.noConflict();
    var jQueryNoConflict = true;

    // Use jQuery via $j(...)
    $j(document).ready(function(){
    $j("div#box").hide();
    });

    }
</script>'. LB;
        define('JQUERY', 'true');
    }


Thanks,

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
Let's not re-invent the wheel, jQuery is standard for many developers.
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
OK we will use jQuery.

Thanks,

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EST. The time is now 10:51 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content