4

我正在将Foundation 4Bones合并以创建 WP Starter 主题。我使用 Foundation 3 中的 JS 一切正常,但现在我正在尝试实现 Foundation 4 JS,我遇到了一些问题。

我按照Foundation 4 JS 文档中的步骤进行操作,但仍然没有运气。这是我直接放在结束正文标记之前的代码(我知道正确的方法是将脚本排入队列,但为了测试我只是将它直接粘贴在结束正文标记上方):

<script>
document.write('<script src=http://mcfaddengavender.net/jeremy/wp-content/themes/bones-master/library/js/vendor/'
+ ('__proto__' in {} ? 'zepto' : 'jquery')
+ '.js><\/script>');
</script>   

<script src="http://mcfaddengavender.net/jeremy/wp-content/themes/bones-master/library/js/foundation.min.js"></script>

<script>
$(document).foundation();
</script>    

我正在尝试在此页面上打开一个模式,但如您所见,当您单击链接时,模式永远不会触发。我注意到 Javascript 控制台中有一些错误,但我对 JS 还是很陌生,所以它们有点让我头疼。

正如我之前提到的,Foundation 3 JS 运行良好,不需要调用来初始化函数——它似乎可以正常工作。不确定这是否有很大的不同,但我注意到 Foundation 4 JS 的文档与 Foundation 3 JS 的文档不同。

谁能让我指出正确的方向?

4

2 回答 2

1

看起来浏览器找不到 Zepto(至少 chrome 找不到)。

它在这里寻找它:http: //mcfaddengavender.net/library/js/vendor/zepto.js但它返回 404

确保您的库设置在适当的目录中!

于 2013-03-03T02:06:38.063 回答
0

在我发表评论之后,我让它工作了大声笑。也许这会对您或其他人有所帮助。

似乎文档有点混乱,我只能通过按此顺序加载foundation/foundation.js和foundation-whatever-plugin.js来获得插件功能-仅加载foundation.js对我不起作用。

我正在使用 requirejs 来加载,所以我不必担心路径,但为了您的目的,只需确保您没有任何路径问题并且此加载顺序应该有效。出于故障排除的目的,我绕过了modernizr / zepto检测器并直接加载jquery。

 requirejs.config({

 baseUrl: "/path/to/scripts",
 paths:{
  jquery: 'vendor/jquery/jquery.min',
 },
 shim: {

    'foundation/foundation': { deps: ['jquery'] },
    'foundation/foundation.alerts': { deps: ['jquery'] },
    'foundation/foundation.clearing': { deps: ['jquery'] },
    'foundation/foundation.cookie': { deps: ['jquery'] },
    'foundation/foundation.dropdown': { deps: ['jquery'] },
    'foundation/foundation.forms': { deps: ['jquery'] },
    'foundation/foundation.joyride': { deps: ['jquery'] },
    'foundation/foundation.magellan': { deps: ['jquery'] },
    'foundation/foundation.orbit': { deps: ['jquery'] },
    'foundation/foundation.placeholder': { deps: ['jquery'] },
    'foundation/foundation.reveal': { deps: ['jquery'] },
    'foundation/foundation.section': { deps: ['jquery'] },
    'foundation/foundation.tooltips': { deps: ['jquery'] },
    'foundation/foundation.topbar': { deps: ['jquery'] },
    'vendor/jquery.maskedinput/jquery.maskedinput.min': { deps: ['jquery']},
    'vendor/chosen/chosen/chosen.jquery': { deps: ['jquery']},
    'vendor/tablesorter/js/jquery.tablesorter.min': { deps: ['jquery']},
    'vendor/tablesorter/addons/pager/jquery.tablesorter.pager.min': {
      deps: [
      'jquery', 
      'vendor/tablesorter/js/jquery.tablesorter.min'
      ]
    },
    'vendor/redactor-js/redactor/redactor.min': { deps: ['jquery']},
    'lib/jquery.passwordstrength': { deps: ['jquery']}

}

});

require(["jquery",
"foundation/foundation",
"foundation/foundation.alerts",
"foundation/foundation.clearing",
"foundation/foundation.cookie",
"foundation/foundation.dropdown",
"foundation/foundation.forms",
"foundation/foundation.joyride",
"foundation/foundation.magellan",
"foundation/foundation.orbit",
"foundation/foundation.placeholder",
"foundation/foundation.reveal",
"foundation/foundation.section",
"foundation/foundation.tooltips",
"foundation/foundation.topbar"
], function ($) {
  $(document).foundation();
});
于 2013-03-17T23:47:28.627 回答