2013-04-26 52 views
3

我们正在用Chaplin的底层构建一个Trigger应用程序。对于开发的目的,如果我们可以使用我们资产的绝对路径,那将会很不错,如果我们可以使用我们资产的绝对路径,那么在触发器中可以这么做吗?Trigger.io资源的绝对路径?

回答

3

不幸的是,不同的平台在触发器上有不同的URL(由于它们有自己的特性和限制)。

如果你想获得绝对路径,你可以使用文件模块和做线沿线的东西:

forge.file.getLocal("js/app.js", function (file) { 
    forge.file.URL(file, function (url) { 
     $('body').append('<script src="'+url+'"></script>'); 
    }); 
}); 

我不知道为什么绝对路径虽然有用,我只会使用建议导航到新页面的一个HTML页面(index.html)比使用JavaScript更改dom更慢。在这种情况下,所有的相对路径应该始终相同。

1

最简单的事情可能是检测是否伪造出现在您的index.html,并相应地加载JavaScript:

<script type="text/javascript"> 
    function addScript(src, callback) { 
    var tag = document.createElement('script'); 
    tag.type = 'text/javascript'; 
    tag.src = src; 

    tag.onload = callback; 

    document.getElementsByTagName('head')[0].appendChild(tag); 
    } 


    var vendor = "javascripts/vendor.js"; 
    var app = "javascripts/app.js"; 

    if(window.forge === undefined) { 
    vendor = "/"+vendor; 
    app = "/"+app; 
    } 

    addScript(vendor, function() { 
    addScript(app, function() { 
     require('initialize'); 
    }); 
    }); 
</script>