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
3 Answers
Reset to default 6Make 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.
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 ashelper_js
: apparently Archetypes doesn't like the plus (+) sign (doesn't escape plus sign correctly if I understand it OK).You can define a page template named
archetypes_custom_js
with a macro calledjavascript_head
and it will automatically be loaded in edit form of all Archetypes. You can then check special conditions in that macro. Seebase_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
评论列表(0条)