开发者

joomla load mootools and/or jquery on page where needed only

I have a joomla 1.5 site where I use mootools (for chronoforms) and some custom jquery code.

In total there are only 2 pages on the whole site where I need mootools or jquery, but it both loads on all pages.

How can I make Joomla load t开发者_StackOverflow中文版he scripts only on the pages where needed?

Thanks


I think you can put jQuery on and off by using these script to the specific page


$document = &JFactory::getDocument();
$document->addScript( '[path to jquery]' );
$noconflict = 'jQuery.noConflict();';
$document->addScriptDeclaration( $noconflict );

I'm not sure how to turn Mootool off. I afraid it always attach to the system. hope this help.

OK this article http://magazine.joomla.org/issues/Issue-Feb-2011/item/349-removing-mootools show how to remove mootool


You can modify joomla code :

go to :

libraries/joomla/html/html/behaviour.php

Search where the mootools is loaded .

Add an IF/ELSE :

ex:

$component = JRequest::getVar("option");
//xmap does not support Mootools 1.2
if($component == "com_xmap") {
   JHTML::script('jquery.js', 'media/system/js/', false);
 } 


You could use the following code in your template's index.php:

$app      =& JFactory::getApplication();

if ( $app->isSite() ) { // Make changes only on Front-end

    $frontpage = ( isset($this->_metaTags['standard']['title']) && $this->_metaTags['standard']['title'] == "Frontpage")? true : false;
    $com = JRequest::getVar("option");


    // When you need Mootools on frontpage only
    if(!$frontpage) {
       $prohibited = array (
           '/media/system/js/core.js',
           '/media/system/js/mootools-core.js',
           '/media/system/js/mootools-more.js',
           '/media/system/js/caption.js'
        );

 }

    // When you need jQuery, for example in "com_xmap" only
    if( $com != "com_xmap") {
        $prohibited = array (
           'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
        );
     }

    foreach ($this->_scripts as $key => $value) {
        if( in_array($key, $prohibited ) ) {
            unset($this->_scripts[$key]);
        }
     }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜