Knowledge resources

We like to share some of our experiences in the hope that other developers wont have to waste hours on the same battles that we have already fought and won.

Refreshing hash part of URL to trigger scrolling

For the admin pages of the "Unified Database" we've built, I recently wrote a simple jump link generator using javascript/jquery. It basically looks up all <h2> headings on the page, inserts an anchor link inside and adds a corresponding jump link to a navigation box in the side menu.

jQuery ajax callback not being called?

When replacing calls to some legacy ajax help functions, I recently came across a problem it took a while for me to resolve. According to Firebug (a very useful FireFox plugin, in case you don't know about it), the ajax call was made and the response looked perfectly fine, but my callback function was never invoked. In the end, for testing, I had a simple snippet like this:

$.get('/some/url', function(){ alert('called'); });

Passing custom arguments to jQuery ajax callback functions

When phasing out our old collection of ajax help functions, I ran into a problem with passing custom arguments to the callback function of the ajax request. Our old ajax functions were based on eval()'ing and could accept custom arguments as a literal string that was used together with the function name to construct the call of the callback. When using jQuery, the situation is different, since jQuery provides the callback function with a fixed set of arguments:

$.get('/some/url', function(data, textStatus, XMLHttpRequest) {
	//do something
});

Cfquery result structs

In old Coldfusion 6, you could access the number of rows returned for a select query by going queryName.recordcount.

In CF8, cfquery now has a result attribute, which is used for naming a struct containing additional information about the query executed. So now for the query:

<cfquery name="a" result="aRes" datasource="uid">
...
</cfquery>

You can do both a.recordcount and aRes.recordcount, but only the latter works for update or delete queries!

Improving user experience in Google translated mode

We recently added a simple translate menu to a client's website, which offered the website to be google translated into a few different languages. Since there is no easy way to get rid of the translated mode's frame layout and go back to the original language without Google's top bar, the client wanted us to open the translation in a new window. This was easily achieved by adding target="_blank" to the form responsible for launching the translation.

Drupal Gmap and Views 1.x integration

According to the Gmap API.txt that comes with the Drupal 5.x module:

In Views 1.x, you need to use the "argument handling code" box to apply settings to a map view.
You can set a custom macro with $view->GMap_macro.
    $view->GMap_macro = '[GMap |behavior=+autozoom]';

Unfortunately this is not quite try and caused some frustration when we tried to adjust the size of a map in the View's page mode and not in the block mode.

Localizing a mixed-language website with Arabic and the Drupal CMS

Scenario

  • We are building a multi-language website for a non-profit project in 4 languages, one of which is Arabic and thus opens the issue or right-to-left direction text.
  • Menu items, major headings and introductory pages have been translated, but we will never have the budget to translate all items on the site (especially a comprehensive "library" of reference material in 20+ languages) meaning that most pages will have at least some blocks of text in English

Editing Arabic text in JSP

I just found a neat solution to a small problem of editing Arabic text (and probably any right-to-left text) inside a JSP context. The problem that that I was trying to paste in a street address on multiple lines in Arabic with
line breaks.

Calculating center of geographic region from country coordinates

For using our country database table together with Google Maps we added latitude and longitude coordinates for all of them, which were easy to find on the 'net.

Our map page was designed so that it automatically centered the map view on a country or region selected in one of the dropdowns. We didn't have any region coordinates though, and we couldn't find any lists online that corresponded to our regions and subregions.

Managing Locales in Drupal 5

We have been using Drupal 5 for a number of multilingual sites, and recently came across a problem of junk locale strings left over from modules we have stopped using and since deleted - namely CivicRM which inserted thousands of locales. Our client is just about to start translating these strings and they were messing up the view.

Subscribe to Knowledge resources