Posted by kkaefer on August 2, 2006 at 3:24pm
Some of my ideas for the future drupal.js:
Note: This is demo/fake code, not actual, working code.
var Drupal = { jsEnabled: false, basePath: 'http://example.com/drupal', locales: {}, settings: {}, addLocales: function(translations) { ... }, t: function(str, args) { ... }, watchdog: function(type, message, severity, link) { ... }, parseJson: function(data) { ... } }; jQuery.dimensions = function() { ... }; jQuery.absolutePosition = function() { ... }; jQuery.freezeHeight = function() { ... }; jQuery.redirectFormButton = function() { ... };
Drupal.jsEnabled
is of course set in$(document).ready();
.Drupal.basePath
could be either set in the page header or in a separate JavaScript file that is generated by PHP (better solution, IMHO).Drupal.locales
is an empty array that can be filled by adding JavaScript files to the page that callDrupal.addLocales({ ... });
. The addition of these translation files is done by modules. We could provide a standardized way to add js-translation files.Drupal.settings
will be the settings storage for all modules. (See also the issue “A centralized place for JavaScript settings”).
Drupal.addLocales()
performs the addition of locales to the global translation storage.Drupal.t()
is an equivalent to Drupal's server-sidet()
function: It tries to replace the english version of a string with a translation (if available) and replaces variables inside the string.Drupal.watchdog()
is an equivalent to Drupal's server-sidewatchdog()
function: It sends an AJAX request to the server which adds the message to Drupal's log.Drupal.parseJson()
tries to interpret JSON (as text) which is returned by some server requests.
We should try to convert as much functions as possible into jQuery “plugins” so that we just have to call $('fieldset.collapsible').makeFieldsetCollapsible();
or similar functions.
Comments
push An addition to the
push
An addition to the JavaScript translation thing: We should also take into account plural forms. Any suggestions?