javascript

Ajax Drupal Submenus

Our Seo department asked us to prevent the submenu items for the site's primary navigation from loading initially again, it had to be iframed or ajaxed in post load. I wanted a more standard solution to the issue, something I could safely reuse on multiple Drupal sites.

Solution:
I used our custom module for the site to output a new block 'Custom Main Menu' that I used to replace the default main menu. It added a small dependency to menu_block, but that's an awesome module anyway, and I'm happy to rely on it. The new main menu loads as normal for users that are logged in. For anonymous users, it loads the first level of the main menu, then request ajax requests the rest after page load, replacing the entire menu block with the full menu again to avoid flashing or complex replacements.

Limiting Textarea Length

I thought I'd share a sort of plug and play solution to text area length controls that I've been abusing. All credit here goes to Roy Jin, the original developer. I just thought I'd share what a good tool it was, and the $(document).ready() code you need to be up and running. You can pick up the jquery Textarea Counter on his site, as well as look up docs for tweaking things.

Post from Form inside Form

I've got a mass edit form for orders on one of the sites I work on. But each order needed link or button to track the shipments of that order using UPS. Well, today we added FedEx tracking as well. UPS was easy, they do everything via url, so a simple link worked fine. FedEx, not so much, you have to post everything over to them. Obviously that creates a sort of form within a form, and that's not valid html. Javascript becomes required, here's your setup:

Tags: 

Javascript Global Regex Match

I needed to do a case insensitive, multiline, global regex (/img) over some html. The matches kept coming back wrong using $.each() and Mozilla's directions. The while loop on the Mozilla docs site didn't work for me, every time it returned match as "true." That's no help, of course. So, a do while loop instead, and all is well.

Pages

Subscribe to RSS - javascript