Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1105 diff -u -r1.1105 common.inc --- includes/common.inc 11 Feb 2010 15:52:12 -0000 1.1105 +++ includes/common.inc 15 Feb 2010 05:06:33 -0000 @@ -3955,8 +3955,8 @@ * ); * @endcode * - * 'js', 'css', and 'library' are types that get special handling. For any - * other kind of attached data, the array key must be the full name of the + * 'js', 'css', 'library' and 'effect' are types that get special handling. For + * any other kind of attached data, the array key must be the full name of the * callback function and each value an array of arguments. For example: * * @code @@ -3990,6 +3990,7 @@ 'library' => array(), 'js' => array(), 'css' => array(), + 'effect' => array(), ); // Add the libraries first. @@ -4031,6 +4032,12 @@ unset($elements['#attached'][$type]); } + // Add all the jQuery effects. + foreach ($elements['#attached']['effect'] as $effect) { + drupal_add_effect($effect); + } + unset($elements['#attached']['effect']); + // Add additional types of attachments specified in the render() structure. // Libraries, Javascript and CSS have been added already, as they require // special handling. @@ -4187,6 +4194,91 @@ } /** + * Adds a jQuery effect to the page. + * + * This is used to invoke any jQuery method on a given element. The effects + * can be bound to user events (like click or change), or be executed once the + * element is ready. + * + * @param $options + * An associative array with the following keys defining the jQuery action + * being added: + * - selector: The jQuery selector for the element to apply the effect to. + * - effect: (optional) The name of the jQuery function to be called. This + * allows calling functions like "show", "hide", etc. If not provided, + * will default to the name of the library in use, through "library". + * - arguments: (optional) An array of arguments that are passed to the + * element during execution. + * - library: (optional) The name of the library to add, if desired. Some + * examples are "ui.dialog", "ui.accordion", "farbtastic", "once", etc. + * - module: (optional) When adding a library, this represents the name of + * the module that originally registered the library. Defaults to "system". + * - event: (optional) The name of the bound event the effect should be + * applied to the element. Defaults to once the element is "ready". Other + * possible events include "click", "change", "mouseenter", etc. + * - bound_element: (optional) When binding on an event other than ready, + * will be the element that the event is bound to. Defaults to what was + * passed into the "selector" argument. + * - is: (optional) Allows applying the effect only when the given condition + * is met. To read more about "is", visit the jQuery documentation at: + * http://docs.jquery.com/Traversing/is . + * - is_selector: (optional) When acting on a conditioning attribute through + * the "is" parameter, this argument represents a jQuery selector pointing + * to the element that will be checked. Defaults to the "bound_element". + * - return_value: (optional) The value which should be returned after the + * effect is applied to the bound element. Defaults to FALSE. + * - effects: (optional) An array of different effects to take on the given + * element. All parameters are inherited from the parent effect, but can be + * overriden by the child. + */ +function drupal_add_effect(array $options = array()) { + // Merge in the defaults. + $options += array( + 'module' => 'system', + 'event' => 'ready', + ); + + // Prepare the Effect Drupal behavior. + static $added = FALSE; + if (!$added) { + $added = TRUE; + drupal_add_js('misc/effect.js'); + } + + // Allow multiple effects to be invoked on the element. + if (isset($options['effects'])) { + foreach ($options['effects'] as $effect) { + // The base elements are inherited from the parent effect so that the + // items don't have to be defined twice. + $effect = array_merge($options, $effect); + // Remove items that should not be inherited, and invoke the effect. + unset($effect['effects']); + drupal_add_effect($effect); + } + } + + // Add the depending library, if needed. + if (isset($options['library'])) { + drupal_add_library($options['module'], $options['library']); + + // The effect defaults to the associated library if not explicitly provided. + if (!isset($options['effect'])) { + // Remove the prefixing "ui." of jQuery UI widgets. + $options['effect'] = str_replace('ui.', '', $options['library']); + } + } + + // Add the settings so that the behaviors are attached to the elements. + if (isset($options['selector'])) { + $effect = $options['effect']; + // Remove items that the JavaScript doesn't need, and add it to the settings. + unset($options['module'], $options['library'], $options['effects']); + $settings['effect'][$effect][] = $options; + drupal_add_js($settings, 'setting'); + } +} + +/** * Assist in adding the tableDrag JavaScript behavior to a themed table. * * Draggable tables should be used wherever an outline or list of sortable items Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.315 diff -u -r1.315 filter.module --- modules/filter/filter.module 30 Jan 2010 22:47:24 -0000 1.315 +++ modules/filter/filter.module 15 Feb 2010 05:06:34 -0000 @@ -56,9 +56,6 @@ 'variables' => array('tips' => NULL, 'long' => FALSE), 'file' => 'filter.pages.inc', ), - 'filter_tips_more_info' => array( - 'variables' => array(), - ), 'filter_guidelines' => array( 'variables' => array('format' => NULL), ), @@ -713,11 +710,50 @@ '#attributes' => array('class' => array('filter-list')), ); $form['format_help'] = array( - '#prefix' => '
', - '#markup' => theme('filter_tips_more_info'), - '#suffix' => '
', + '#type' => 'container', + '#id' => $element_id . '-help', + '#attributes' => array('class' => array('filter-help')), '#weight' => 1, ); + $form['format_help']['link'] = array( + '#type' => 'link', + '#title' => t('More information about text formats'), + '#href' => 'filter/tips', + '#options' => array( + 'attributes' => array('class' => array('filter-help-link')), + ), + ); + // Create a dialog box for the filter tips. + $form['format_help_tips'] = array( + '#type' => 'container', + '#id' => 'filter-tips', + '#attributes' => array('class' => array('js-show')), + ); + $form['format_help_tips']['content'] = array( + '#theme' => 'filter_tips', + '#tips' => _filter_tips(-1, TRUE), + '#long' => TRUE, + ); + $form['format_help_tips']['#attached']['effect'][] = array( + 'library' => 'ui.dialog', + 'selector' => '#filter-tips', + 'arguments' => array( + array( + 'width' => 680, + 'height' => 400, + 'autoOpen' => FALSE, + 'title' => t('Filter tips'), + ), + ), + 'effects' => array( + // When the more information link is clicked, open the dialog box. + array( + 'event' => 'click', + 'bound_element' => '#' . $element_id . '-help a.filter-help-link', + 'arguments' => array('open'), + ), + ), + ); return $form; } @@ -826,15 +862,6 @@ } /** - * Format a link to the more extensive filter tips. - * - * @ingroup themeable - */ -function theme_filter_tips_more_info() { - return '

' . l(t('More information about text formats'), 'filter/tips') . '

'; -} - -/** * Format guidelines for a text format. * * @param $variables Index: modules/system/system-behavior.css =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system-behavior.css,v retrieving revision 1.3 diff -u -r1.3 system-behavior.css --- modules/system/system-behavior.css 13 Jan 2010 14:41:58 -0000 1.3 +++ modules/system/system-behavior.css 15 Feb 2010 05:06:35 -0000 @@ -284,6 +284,16 @@ } /** + * Show elements only when JavaScript is enabled. + */ +.js-show { + display: none; +} +html.js .js-show { + display: inherit; +} + +/** * Hide elements from all users. * * Used for elements which should not be immediately displayed to any user. An Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.889 diff -u -r1.889 system.module --- modules/system/system.module 13 Feb 2010 21:41:58 -0000 1.889 +++ modules/system/system.module 15 Feb 2010 05:06:37 -0000 @@ -1181,6 +1181,8 @@ ), 'dependencies' => array( array('system', 'ui'), + array('system', 'ui.draggable'), + array('system', 'ui.resizable'), ), ); $libraries['ui.draggable'] = array( Index: modules/php/php.test =================================================================== RCS file: /cvs/drupal/drupal/modules/php/php.test,v retrieving revision 1.23 diff -u -r1.23 php.test --- modules/php/php.test 10 Jan 2010 22:56:51 -0000 1.23 +++ modules/php/php.test 15 Feb 2010 05:06:34 -0000 @@ -82,7 +82,7 @@ $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->title)), t('PHP code filter turned on.')); // Make sure that the PHP code shows up as text. - $this->assertNoText('print "SimpleTest PHP was executed!"', t("PHP code isn't displayed.")); + $this->assertNoText('print "SimpleTest PHP was executed!"', t('PHP code is not displayed.')); $this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.')); } } @@ -110,7 +110,7 @@ // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->nid); - $this->assertText('print', t('PHP code was not evaluated.')); + $this->assertText('print "SimpleTest PHP was executed!"', t('PHP code is displayed.')); // Make sure that user doesn't have access to filter. $this->drupalGet('node/' . $node->nid . '/edit'); Index: modules/simpletest/tests/common.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v retrieving revision 1.102 diff -u -r1.102 common.test --- modules/simpletest/tests/common.test 11 Feb 2010 17:44:47 -0000 1.102 +++ modules/simpletest/tests/common.test 15 Feb 2010 05:06:35 -0000 @@ -1251,6 +1251,16 @@ $scripts = drupal_get_js(); $this->assertTrue(strpos($scripts, 'misc/farbtastic/farbtastic.js'), t('The attached_library property adds the additional libraries.')); } + + /** + * Tests the retrieval of libraries. + */ + function testGetLibrary() { + $libraries = drupal_get_library('common_test'); + $this->assertTrue(array_key_exists('farbtastic', $libraries), t('Retrieved all module libraries.')); + $farbtastic = drupal_get_library('common_test', 'farbtastic'); + $this->assertEqual($farbtastic['version'], '5.3', t('Retrieved a single library.')); + } } /** Index: misc/effect.js =================================================================== RCS file: misc/effect.js diff -N misc/effect.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/effect.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,52 @@ +// $Id$ +(function ($) { + +/** + * @file + * Provides the Effect Drupal behavior. + */ + +/** + * The jQuery Effect Drupal behavior. + * + * This will go through all desired effects and apply them to the appropriate + * elements, taking the function arguments and bound events into + * consideration. + */ +Drupal.behaviors.effect = { + attach: function (context, settings) { + // Iterate through each desired jQuery effect and apply it to each of the + // desired elements. + $.each(settings.effect || {}, function (effect, effects) { + $.each(effects, function (index, options) { + // See if we are to bind the tool to an event, or just apply it when + // the element itself is ready. + if (options.event == 'ready') { + // Apply the jQuery UI's effect. + $(options.selector, context).once('effect-' + effect + '-' + index, function() { + // Since we are calling the function with a dynamic set of + // arguments, we have to use the JavaScript apply function. + $(this)[effect].apply($(this), options.arguments); + }); + } + else { + // Apply the jQuery UI's effect on the bound event. If a bound + // element is not provided, we will use the original selected item. + $(options.bound_element || options.selector, context).once('effect-' + effect + '-' + options.event + '-' + index).bind(options.event, function() { + // Make sure the "is" argument is satisfied. + if (options.is ? $(options.is_selector ? options.is_selector : this).is(options.is) : true) { + // Apply the tool to the element using the arguments array. + var element = $(options.selector); + element[effect].apply(element, options.arguments); + } + // Return the expected value, defaulting to false to override + // the default functionality of the effect. + return options.return_value || false; + }); + } + }); + }); + } +}; + +})(jQuery); \ No newline at end of file