home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (date_api.js)

This example Drupal source code file (date_api.js) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

children, custom, format, function, getjson, hide, input, php, show, span, this, url, var

The date_api.js Drupal example source code

/**
 * Show/hide custom format sections on the date-time settings page.
 */
Drupal.behaviors.dateDateTime = function(context) {
  // Show/hide custom format depending on the select's value.
  $('select.date-format:not(.date-time-processed)', context).change(function() {
    $(this).addClass('date-time-processed').parents("div.date-container").children("div.custom-container")[$(this).val() == "custom" ? "show" : "hide"]();
  });

  // Attach keyup handler to custom format inputs.
  $('input.custom-format:not(.date-time-processed)', context).addClass('date-time-processed').keyup(function() {
    var input = $(this);
    var url = Drupal.settings.dateDateTime.lookup +(Drupal.settings.dateDateTime.lookup.match(/\?q=/) ? "&format=" : "?format=") + Drupal.encodeURIComponent(input.val());
    $.getJSON(url, function(data) {
      $("div.description span", input.parent()).html(data);
    });
  });

  // Trigger the event handler to show the form input if necessary.
  $('select.date-format', context).trigger('change');
};

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal date_api.js source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.