duanhuiqing9528 2009-07-13 21:07
浏览 39
已采纳

从Joomla中调用MooTools JS代码的正确方法是什么?

I wrote some MooTools code that reads from YouTube's API in JSON and I want to execute it from within a custom component.

I've been reading about the js.php file, but I'm unclear on the best approach. I was just going to output js in my component directly, and then i realized that the MooTools library isn't being loaded unless a component specifically requests it.

Furthermore, part of my code was to dynamically load a remote JS Library, and then to remove it from the DOM when I needed. Can all this be done within Joomla's Framework?

Can someone help?

  • 写回答

1条回答 默认 最新

  • duanpo1498 2009-07-16 06:36
    关注

    So it appears, there is a command in the framework that instantiates mootools, and several other commands for loading scripts into the DOM:

    JHTML::_('behavior.mootools');
    
    $doc = JFactory::getDocument()
    $doc->addScript($scriptURL);
    

    or a shortcut(from API docs):

    JHTML::script(string $filename, [boolean $path = 'media/system/js/'], [ $mootools = true]) 
    

    The thing is Joomla1.5 uses an older version of MooTools (1.1), and the next version that's going to be released is 2.0, so it's pretty far behind.

    There are some interesting built-in features with the JHTML class, but I'm opting to use JQuery for most everything at this point - as updating MooTools will actually break many features in Joomla, and jQuery is much more lightweight.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备