Conditional RJS
Conditional RJS is difficult to understand for a newbie, but it starts making sense when you start thinking abour it.
First of all RJS is not Javascript. RJS is Ruby code that gets translated into Javascript. Take for example the following code:
if @delivery_locations.blank?
page[:previous_delivery_locations].remove if page[:previous_deliver_locations]
else
if page[:previous_deliver_locations]
page[:previous_delivery_locations].replace_html @delivery_locations
else
page.insert_html :top, 'delivery_details', @delivery_locations
end
It all makes perfect sense. Hang on. How can Ruby check if an element is on a page if page[:previous_delivery_locations] if it's server-side, not client-side? Again, Ruby only generates Javascript which then gets executed client-side. What we want in this case is something along the lines:
if @company_delivery_locations.blank?
page << "if ( $('previous_delivery_locations') ) {"
page[:previous_delivery_locations].remove
page << "}"
else
page << "if ( $('previous_delivery_locations') ) {"
page[:previous_delivery_locations].replace_html @delivery_locations
page << "}else{"
page.insert_html :top, 'delivery_details', @delivery_locations
page << "}"
end
Notice the page <<. Everything that follows is raw Javascript and gets inserted exactly as we write it. That's more like it!
Remember, if you aren't sure about your RJS, always check the generated source through your best friend Firebug (or well, just View Source), and double check if it's what you hoped for.
If you want to read more on the subject, take a look here: Conditional RJS Explained.
glz_custom_fields 1.1 released
A new version of glz_custom_fields has been released. Not all features on the roadmap made it in, but these did:
- an improved help (explanations in French, German, Spanish, Italian, Greek & Russian to follow shortly)
- a
jquery.jsfix suggested by Sam Weiss. I gave up the idea of using the latest jquery from code.jquery.com becuse I found it to be too much hassle (permissions, offline websites etc.) glz_custom_fieldandglz_if_custom_fieldtags work nicely with custom fields that contain multiple values. Custom fields > 10 on single articles need a hack to work (please read below)- plays nicely now with sed_section_fields
- TXP 4.0.6 compatible. If – for whatever reason – you didn’t upgrade TXP to 4.0.6, make sure jquery.js under the textpattern folder is at least 1.2. Upgrade to 4.0.6 strongly recommended.
- a custom field can be a multi-select as well (the only one remaining is textarea…)
For glz_custom_field & if_glz_custom_field to look into custom fields above 10 on single articles, you will need to apply the following patch: publish_r2777.patch (490.00B) . If you are familiar with SVN, all you have to do is run the following command in the textpattern directory:
patch -p1 -i path/to/publish_r2777.php publish.php
For the ones that aren’t familiar with SVN, replace getCustomFields() with the following.
The above patch is for the publish.php that comes with the latest stable TXP, 4.0.6. An upgrade is strongly recommended.
The post starting the glz_custom_fields forum thread was updated accordingly.
I would like to thank everyone that has supported this plugin, all you guys are great!
Comment [8]
glz_custom_fields unveiled
It's official, glz_custom_fields has been launched. For the ones that have no idea what I'm talking about here, take a look at drop down lists for custom fields on Textpattern Forum. For the ones that do know and would like to see the plugin in action, glz_custom_fields_unveiled.mov (10.33MB). A few screenshots while you're waiting for the screencast to download:
As you might know from the forum, this plugin is for grabs for £10 (or $20, or €10). It's a big (1,5k lines of code big), complex plugin that took me a few months to develop.
Since my original post back in December 2005 - 10 more custom fields please - a fellow TXP user, Randy, asked me to make a private plugin which was using the unlimited, pimped custom fields concept. 3 months later, after having finished the plugin for Randy and realizing that putting the hack in a plugin was possible, here we are, the custom fields plugin happening.
The £10 will get you updates for life and unleash the true potential of your favourite blogging tool.
After donating, you will be taken straight to a copy of glz_custom fields v1.2.3. Let's rock!
Comment [24]
<< Older posts ...