plone - Registering a Javascript to be loaded on edit view - Stack Overflow

What is the remended way to register a Javascript to be loaded on the edit view (Archetypes) of certain

What is the remended way to register a Javascript to be loaded on the edit view (Archetypes) of certain content types?

  • Javascript would be merged and pressed if it's portal_javascripts
  • Creating portal_javascript condition is a problem: how to create a condition line checking for edit views of a certain content types and so that the line doesn't look like the leftovers of fighting crows
  • Archetypes widgets support old fashioned way to dump files directly to using macro slot fill

Any examples of existing implementations?

What is the remended way to register a Javascript to be loaded on the edit view (Archetypes) of certain content types?

  • Javascript would be merged and pressed if it's portal_javascripts
  • Creating portal_javascript condition is a problem: how to create a condition line checking for edit views of a certain content types and so that the line doesn't look like the leftovers of fighting crows
  • Archetypes widgets support old fashioned way to dump files directly to using macro slot fill

Any examples of existing implementations?

Share Improve this question asked Mar 29, 2011 at 8:35 Mikko OhtamaaMikko Ohtamaa 83.7k61 gold badges287 silver badges468 bronze badges 4
  • 1 I just wanted to add: while there are answers to this question, none of them are ideal. We really need a much more general solution going forward, one that will deal with dependencies and will minimize points of injection. – SteveM Commented Mar 29, 2011 at 15:14
  • @SteveM, what do you mean by "deal with dependencies"? – marcosfromero Commented Mar 29, 2011 at 17:28
  • @SteveM I don't agree; from a site performance and cache-ability POV you want to minimize the number of Javascript files to load at all times. Thus, it's best to just load all JS together regardless of exactly what pages need them. – Martijn Pieters Commented Mar 29, 2011 at 20:02
  • I'm thinking of something like zc.resourcelibrary or fantastic fanstatic. But, Martijn's point is a really good one. The gotcha is that some of these javascript libraries are truly huge and may only be needed on a few pages -- or for editing a few pages. – SteveM Commented Mar 30, 2011 at 15:14
Add a ment  | 

3 Answers 3

Reset to default 6
  1. Make sure your JavaScript code works OK in those content type edit forms and doesn't break on other situations (jQuery is your friend). Then add it to portal_javascripts.

  2. If you can associate the JavaScript to certain widgets, add it as helper_js for those widgets. Be careful with JavaScript as browser resources because I had trouble with '++resoure++'-like URLs as helper_js: apparently Archetypes doesn't like the plus (+) sign (doesn't escape plus sign correctly if I understand it OK).

  3. You can define a page template named archetypes_custom_js with a macro called javascript_head and it will automatically be loaded in edit form of all Archetypes. You can then check special conditions in that macro. See base_edit.cpt line 47.

To be honest is such cases I like the approach that use old fill-slot directly in the edit form of the type. The edit form is often not-so-frequently called (and for sure not from anonymous) so a little overhead due to downloading not-fully cached code is not so bad.

Best practice is to have your javascript merged with as many other scripts as possible. Just load it either without a condition or only for authenticated users. All javascript code pertaining to editing included in Plone already loads for all authenticated users regardless.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742314340a4420534.html

相关推荐

  • plone - Registering a Javascript to be loaded on edit view - Stack Overflow

    What is the remended way to register a Javascript to be loaded on the edit view (Archetypes) of certain

    12小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信