2013-03-02 45 views
4

我正在合并Foundation 4Bones以创建WP Starter主题。我从Foundation 3的JS中都能正常工作,但现在我试图实现Foundation 4 JS,我遇到了一些问题。获得基金会4 JS在WP中工作的问题

我遵循Foundation 4 JS Documentation中找到的步骤,但仍然没有运气。这里是我直接放置在结束标记之前的代码(我知道正确的方法是排队脚本,但对于测试我只是把它粘贴直接结束标记以上):

<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>  

我试图打开this page上的模式,但正如您所看到的,当您单击该链接时,该模式不会触发。我注意到了Javascript控制台中的一些错误,但是我仍然对JS很陌生,所以他们有点过头了。

正如我前面提到的,基金会3 JS的工作很好,它不需要调用初始化函数 - 它似乎工作。不知道这是否有很大的不同,但是我注意到与Foundation 3 JS相比,Foundation 4 JS的文档有所不同。

任何人都可以让我指出正确的方向吗?

回答

1

它看起来像浏览器找不到Zepto(至少铬不能)。

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

确保你有你的图书馆在适当的目录设置!

+0

感谢您的支持!我加入了绝对链接,我仍然有一些问题。但是,错误控制台中的错误较少。我使用新代码编辑原始帖子。 – JeremyE 2013-03-03 03:35:46

+0

嗯,这很奇怪。我不知道为什么会发生这种情况,但是我发现你在html中进一步加载jquery 1.8.3,也许尝试删除它并将document.write放在其他js文件声明之前? – 2013-03-03 04:10:17

+0

我删除了额外的jQuery调用,甚至尝试将代码移动到头文件中,仍然没有运气。 (所以我把所有的东西都移回到了页脚,以便弄清楚这一点)。我非常感谢你的帮助 - 我们从8-9错误变为3,所以我们越来越近了! :) – JeremyE 2013-03-03 21:09:12

0

很好,我评论后,我得到它的工作哈哈。也许这会帮助你或其他人。

它看起来像文件有点混乱,我只能从这个序列中加载基金会/ 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(); 
});