简体   繁体   English

Jive主题中的JSZip

[英]JSZip in Jive theme

Has anyone had any success in implementing JSZip within their Jive theme? 是否有人在其Jive主题中实现JSZip取得了成功? I am having trouble instantiating the JSZip object. 我在实例化JSZip对象时遇到了麻烦。 Here is the setup: I have a Jive theme that has some custom JS files within a script folder. 设置如下:我有一个Jive主题,在脚本文件夹中有一些自定义JS文件。 The JS files are included via script tags in the javascript.soy template like this: JS文件通过javascript.soy模板中的脚本标签包括在内,如下所示:

/*javascript.soy*/ <script src="{themeUrl('/scripts/carousel.js')}"></script> <script src="{themeUrl('/scripts/jszip.min.js')}"></script> <script src="{themeUrl('/scripts/our-theme.js')}"></script>

our-theme.js attempts to instantiate a new instance of JSZip like this: our-theme.js尝试实例化JSZip的新实例,如下所示:

var zip = new JSZip();

The browser throws an error (visible in firebug or Chrome Developer Console) of "ReferenceError: JSZip is not defined". 浏览器抛出“ ReferenceError:未定义JSZip”错误(在firebug或Chrome开发者控制台中可见)。 This is strange because I can view the script file via Firebug or by clicking "View Page Source" I can verify that the proper script tag for jszip.min.js which has the JSZip definition, has been generated and is accessible. 这很奇怪,因为我可以通过Firebug或单击“查看页面源代码”来查看脚本文件,可以验证是否已生成具有JSZip定义的jszip.min.js正确的脚本标签,并且可以访问。

I am able to call functions in other external JS files so the only thing I can think of is that I am instantiating this object incorrectly. 我能够在其他外部JS文件中调用函数,所以我唯一想到的就是我错误地实例化了该对象。 Per the JSZip documentation: 根据JSZip文档:

For a browser, there are two interesting files : dist/jszip.js and dist/jszip.min.js (include just one). 对于浏览器,有两个有趣的文件:dist / jszip.js和dist / jszip.min.js(仅包含一个)。 If you use an AMD loader (RequireJS for example) JSZip will register itself : you just have to put the js file at the right place, or configure the loader (see here for RequireJS). 如果您使用AMD加载程序(例如,RequireJS),JSZip会自行注册:您只需要将js文件放在正确的位置,或配置加载程序(请参阅此处以查看RequireJS)。 Without any loader, JSZip will declare in the global scope a variable named JSZip. 没有任何加载程序,JSZip将在全局范围内声明一个名为JSZip的变量。

I am not using RequireJS. 我没有使用RequireJS。 So JSZip should be registered as a global variable but I cant access it and down see it in the window collection. 因此,JSZip应该被注册为全局变量,但是我无法访问它并且无法在窗口集合中看到它。

I looked through the community but couldnt see anyone else that used JSZip with Jive but I figure it doesn't hurt to try:) 我浏览了整个社区,但看不到其他在Jive中使用JSZip的人,但我认为尝试使用它不会有任何伤害:)

JSZip uses browserify to generate the dist/ files with an UMD definition. JSZip使用browserify生成具有UMD定义的dist/文件。 If the UMD code detects an AMD environment (a define function with an amd attribute exists) or a nodejs environment (a module object and an exports object exist) it won't expose the global JSZip variable. 如果UMD代码检测到AMD环境(存在具有amd 属性define 函数 )或nodejs环境(存在module 对象exports 对象 ),则不会公开全局JSZip变量。

In your browser, you should check if you are in this situation (these checks come from the generated jszip.js file): 在浏览器中,您应该检查您是否处于这种情况(这些检查来自生成的jszip.js文件):

console.log("looks like AMD", "function" == typeof define && define.amd);
console.log("looks like nodejs", "object" == typeof exports && "undefined" != typeof module);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM