且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery插件及其依赖项的指南

更新时间:2022-12-12 22:05:58

Personally, when I build a plugin, I try to make it dependent as little as possible on other resources as to avoid this issue. Sometimes you can't avoid using external stylesheets in which case I've always put them with my other CSS files even if they are originally included in the same folder as the plugins. This avoids any ambiguity when trying to decide which stylesheets should go where etc. You will manually have to include them anyways. If the plugin has any dependencies, they go in the JS folder, organized in a similar manner as the other plugins. Images, in this case, would then go with all of the other images.

在构建插件时,您可以通过允许用户定义类来使其更灵活应用于某些对象,或让用户定义插件将操作的结构。所有这一切都可以在提供一组良好的默认值时完成,同时尽可能少地依赖外部资源。

When building a plugin, you can make it more flexible by allowing the user to define the classes that are applied to certain objects, or let the user define the structure of what the plugin will manipulate. All of this can be done while giving it a set of good defaults to follow while relying as little as possible on external resources.

关于是否已定义***实践这些情况,我还没有找到。我只在jQuery网站上找到了插件创作指南: http://docs.jquery.com/Plugins/创作

As to whether best practices have been defined for these situations, I have not found any yet. I have only found the plugin authoring guidelines on the jQuery site: http://docs.jquery.com/Plugins/Authoring.

编辑:

关于插件的说明依赖组织:

As to clarify about plugin dependency organization:

当你说你有jquery.x.js和jquery.y.js时。它们都依赖于jquery.z.js。我总是将jquery.z.js放在与jquery.x.js和jquery.y.js相同的文件夹中。这避免了重复以及与违反组织惯例相关的任何混淆。所以:

When say you have jquery.x.js and jquery.y.js. They both depend on jquery.z.js. I have always put jquery.z.js in the same folder as jquery.x.js and jquery.y.js. This avoids duplication and any confusion related to breaking the organizational convention. So:


  • ./ jquery.x.js

  • ./ jquery.y.js

  • ./ jquery.z.js

我通常组织我的文件夹:

I normally organize my folders as such:


  • ./ js / jquery-xxxjs

  • ./ js / plugins / jquery.x.js

  • ./ js / plugins / jquery.y.js

  • ./ js / plugins / jquery.z.js

  • ./js/jquery-x.x.x.js
  • ./js/plugins/jquery.x.js
  • ./js/plugins/jquery.y.js
  • ./js/plugins/jquery.z.js