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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么