Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.758 diff -u -r1.758 common.inc --- includes/common.inc 18 Feb 2008 16:53:36 -0000 1.758 +++ includes/common.inc 20 Feb 2008 12:01:01 -0000 @@ -3011,6 +3011,9 @@ 'form_element' => array( 'arguments' => array('element' => NULL, 'value' => NULL), ), + 'field_example' => array( + 'arguments' => array('text' => NULL), + ), ); } Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.267 diff -u -r1.267 form.inc --- includes/form.inc 12 Feb 2008 13:52:32 -0000 1.267 +++ includes/form.inc 20 Feb 2008 12:22:41 -0000 @@ -2002,11 +2002,32 @@ if (isset($element['#field_suffix'])) { $output .= ' '. $element['#field_suffix'] .''; } + + if (!empty($element['#example']) && empty($element['#value'])) { + $output .= theme('field_example', $element['#example']); + drupal_add_js('misc/jquery.example.js', 'module', 'footer'); + drupal_add_js("$(function() { + $('#{$element['#id']}').example('{$element['#example']}'); + $('#{$element['#id']}-wrapper .example-text').hide(); + });", 'inline', 'footer'); + } return theme('form_element', $element, $output) . $extra; } /** + * Format examples specified in FAPI #example properties. + * + * @param $example + * An example entry for the form field. + * @return + * A themed HTML string containing the example. + */ +function theme_field_example($example) { + return ' '. t('Example: ') .''. $example .''; +} + +/** * Format a form. * * @param $element Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.63 diff -u -r1.63 system.admin.inc --- modules/system/system.admin.inc 4 Feb 2008 12:35:48 -0000 1.63 +++ modules/system/system.admin.inc 20 Feb 2008 11:09:53 -0000 @@ -1142,7 +1142,8 @@ '#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => variable_get('site_slogan', ''), - '#description' => t("Your site's motto, tag line, or catchphrase (often displayed alongside the title of the site).") + '#description' => t("Your site's motto, tag line, or catchphrase (often displayed alongside the title of the site)."), + '#example' => t('The place to be!') ); $form['site_mission'] = array( '#type' => 'textarea', Index: modules/system/system.css =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.css,v retrieving revision 1.48 diff -u -r1.48 system.css --- modules/system/system.css 9 Jan 2008 09:56:39 -0000 1.48 +++ modules/system/system.css 20 Feb 2008 12:15:21 -0000 @@ -150,6 +150,16 @@ margin-top: 0.4em; margin-bottom: 0.4em; } +.form-item .example, .form-item .example-text { + color: #999; +} +.form-item .example-content { + font-size: 0.85em; + font-style: italic; +} +.form-item .example-caption { + font-size: 0.85em; +} .marker, .form-required { color: #f00; } Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.591 diff -u -r1.591 system.module --- modules/system/system.module 18 Feb 2008 19:19:47 -0000 1.591 +++ modules/system/system.module 20 Feb 2008 11:09:53 -0000 @@ -169,7 +169,7 @@ $type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah')); $type['button'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => FALSE, '#process' => array('form_expand_ahah')); $type['image_button'] = array('#input' => TRUE, '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah'), '#return_value' => TRUE, '#has_garbage_value' => TRUE, '#src' => NULL); - $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_expand_ahah')); + $type['textfield'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#autocomplete_path' => FALSE, '#process' => array('form_expand_ahah'), '#example' => ''); $type['password'] = array('#input' => TRUE, '#size' => 60, '#maxlength' => 128, '#process' => array('form_expand_ahah')); $type['password_confirm'] = array('#input' => TRUE, '#process' => array('expand_password_confirm')); $type['textarea'] = array('#input' => TRUE, '#cols' => 60, '#rows' => 5, '#resizable' => TRUE, '#process' => array('form_expand_ahah')); Index: modules/upload/upload.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.admin.inc,v retrieving revision 1.7 diff -u -r1.7 upload.admin.inc --- modules/upload/upload.admin.inc 10 Jan 2008 20:22:57 -0000 1.7 +++ modules/upload/upload.admin.inc 20 Feb 2008 12:09:39 -0000 @@ -70,8 +70,8 @@ '#default_value' => variable_get('upload_max_resolution', 0), '#size' => 15, '#maxlength' => 10, - '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0 for no restriction. If an image toolkit is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/settings/image-toolkit'))), - '#field_suffix' => ''. t('WIDTHxHEIGHT') .'' + '#description' => t('The maximum allowed image size. Set to 0 for no restriction. If an image toolkit is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/settings/image-toolkit'))), + '#example' => t('640x480') ); $form['settings_general']['upload_list_default'] = array( '#type' => 'select', Index: misc/jquery.example.js =================================================================== RCS file: misc/jquery.example.js diff -N misc/jquery.example.js *** /dev/null 1 Jan 1970 00:00:00 -0000 --- misc/jquery.example.js 1 Jan 1970 00:00:00 -0000 *************** *** 0 **** --- 1,27 ---- + // $Id$ + + /* + * jQuery Example Plugin 1.2 + * Populate form inputs with example text that disappears on focus. + * + * e.g. + * $('input#name').example('Bob Smith'); + * $('textarea#message').example('Type your message here', { + * class_name: 'example_text', + * hide_label: true + * }); + * + * Copyright (c) Paul Mucur (http://mucur.name), 2007-2008. + * Dual-licensed under the BSD and GPL Licenses (LICENSE.txt). + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + (function(A){A.fn.example=function(E,D){var C=A.extend({},A.fn.example.defaults,D);var B=A.data(document.body,"example")||[];if(A.inArray(C.class_name,B)==-1){A(window).unload(function(){A("."+C.class_name).val("");});A(this).parents("form:first").submit(function(){A("."+C.class_name).val("");});B.push(C.class_name);A.data(document.body,"example",B);}return this.each(function(){var F=A(this);if(F.val()==""){F.addClass(C.class_name);F.val(E);}if(C.hide_label){A("label[@for="+F.attr("id")+"]").next("br").andSelf().hide();}F.focus(function(){if(A(this).hasClass(C.class_name)){A(this).val("");A(this).removeClass(C.class_name);}});F.blur(function(){if(A(this).val()==""){A(this).addClass(C.class_name);A(this).val(E);}});});};A.fn.example.defaults={class_name:"example",hide_label:false};})(jQuery);