Notes from Backporting Popups to Drupal 5

Backporting a Drupal 6 module with lots of Ajaxy goodness was more of a pain that I thought, but it is doable.

* Of course you have to do the obvious stuff, change the hook_menu items, your l() & url() calls, and the form API signatures.
* Garland's content area is hard to target in Drupal 6, and completely impossible in Drupal 5. People who want to popupify Garland will just have to modify their page.tpl.php and change line 75 to:

  <div id="content"> <?php print $content ?> </div>

* (The real PITA is how many other themes have copied Garland's non-semantic markup style).
* The biggest problem with doing Ajax in Drupal 5 is the lack of an equivalent to the Drupal.behavior system. I just sucked it up an wrote my own simple, hacked up version for the behaviors I needed.
* Of course, without Drupal.attachBehavior, you need to put a "if (Drupal.jsEnabled) { $(document).ready(function() {});};" clause in your js file.
* There is also no js Drupal.theme calls, so all of those functions will need to be renamed and renamespaced.
* In retrospect, I should have probably used jQuery Update. jQuery 1.0 is a lot quirkier than I remembered.
* $(selector, context) only works if context is in the DOM! To inject just part of the content returned by an Ajax call, you first need to put in all in the page (hidden), trim out the part you need, delete the hidden content, and the inject the trimmed bit. Super kludgerific!
* jQuery 1.0 doesn't have height and weight functions, so I installed the 1.0 dimensions plugin. Small complication, dimension wants it's values as strings, with 'px' appended then.
* The jQuery 1.0 forms plugin doesn't support the beforeSend options, but that was easily hacked in.
* jQuery 1.0 chokes and dies if you ask it to wrap html content with \n's in it. I used "replace(/\n/g, '')" to strip them out.

In retrospect, I should have

In retrospect, I should have probably used jQuery Update. jQuery 1.0 is a lot quirkier than I remembered.


I look forward to a d5 version of popups! :)

jQuery Update

When still having to do jQuery stuff for D5, I do not need to think a second about adding

dependencies = jquery_update

to the .info file. Now that Drupal 6 and jQuery Update 2.0 both use jQuery 1.2.6, it's a wonderful world to code in. :)

Anyway, great job!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.