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 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。