Welcome to Geeklog, Anonymous Monday, November 10 2025 @ 06:11 pm EST
Geeklog Forums
How to load javascript (jquery) only once
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 -
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-
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
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
27
20
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
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
20
17
Quote
Status: offline
::Ben
Forum User
Full Member
Registered: 01/14/05
Posts: 1582
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.
$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
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
21
21
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
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
20
23
Quote
All times are EST. The time is now 06:11 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