diff --git includes/common.inc includes/common.inc index 75953a0..62e90fc 100644 --- includes/common.inc +++ includes/common.inc @@ -3781,8 +3781,8 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { * ); * @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 @@ -3817,6 +3817,7 @@ function drupal_process_attached($elements, $weight = JS_DEFAULT, $dependency_ch 'library' => array(), 'js' => array(), 'css' => array(), + 'effect' => array(), ); // Add the libraries first. @@ -3858,6 +3859,12 @@ function drupal_process_attached($elements, $weight = JS_DEFAULT, $dependency_ch 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. @@ -4020,6 +4027,91 @@ function drupal_get_library($module, $name) { } /** + * 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 diff --git modules/filter/filter.module modules/filter/filter.module index 2b4bddf..9ae544d 100644 --- modules/filter/filter.module +++ modules/filter/filter.module @@ -59,9 +59,6 @@ function filter_theme() { 'text_format_wrapper' => array( 'render element' => 'element', ), - 'filter_tips_more_info' => array( - 'variables' => array(), - ), 'filter_guidelines' => array( 'variables' => array('format' => NULL), ), @@ -841,14 +838,50 @@ function filter_process_format($element) { '#attributes' => array('class' => array('filter-list')), '#parents' => array_merge($element['#parents'], array('format')), ); - $element['format']['help'] = array( '#type' => 'container', - '#theme' => 'filter_tips_more_info', '#attributes' => array('class' => array('filter-help')), '#weight' => 0, ); - + $element['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. + $element['format_help_tips'] = array( + '#type' => 'container', + '#id' => 'filter-tips', + '#attributes' => array('class' => array('js-show')), + ); + $element['format_help_tips']['content'] = array( + '#theme' => 'filter_tips', + '#tips' => _filter_tips(-1, TRUE), + '#long' => TRUE, + ); + $element['format_help_tips']['#attached']['effect'][] = array( + 'library' => 'ui.dialog', + 'selector' => '#filter-tips', + 'arguments' => array( + array( + 'width' => 720, + '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' => '.filter-help a.filter-help-link', + 'arguments' => array('open'), + ), + ), + ); // Lastly, disallow editing of this field if the user is not allowed to use // the stored and preselected text format. But only, if that format actually // exists. @@ -1099,15 +1132,6 @@ function filter_dom_serialize_escape_cdata_element($dom_document, $dom_element, } /** - * Returns HTML for 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') . '

'; -} - -/** * Returns HTML for guidelines for a text format. * * @param $variables diff --git modules/php/php.test modules/php/php.test index caa2224..143c6f7 100644 --- modules/php/php.test +++ modules/php/php.test @@ -82,7 +82,7 @@ class PHPFilterTestCase extends PHPTestCase { $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 @@ class PHPAccessTestCase extends PHPTestCase { // 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'); diff --git modules/simpletest/tests/common.test modules/simpletest/tests/common.test index 777b413..e686c08 100644 --- modules/simpletest/tests/common.test +++ modules/simpletest/tests/common.test @@ -1284,6 +1284,14 @@ class JavaScriptTestCase extends DrupalWebTestCase { $query_string = substr(variable_get('css_js_query_string', '0'), 0, 1); $this->assertRaw(drupal_get_path('module', 'node') . '/node.js?arg1=value1&arg2=value2&' . $query_string, t('Query string was appended correctly to js.')); } + + /** + * Tests the retrieval of libraries. + */ + function testGetLibrary() { + $farbtastic = drupal_get_library('common_test', 'farbtastic'); + $this->assertEqual($farbtastic['version'], '5.3', t('Retrieved a single library.')); + } } /** diff --git modules/system/system-behavior.css modules/system/system-behavior.css index 66e71a8..8a63b10 100644 --- modules/system/system-behavior.css +++ modules/system/system-behavior.css @@ -274,6 +274,16 @@ html.js .js-hide { } /** + * 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 diff --git modules/system/system.module modules/system/system.module index 28e2e7b..826cdc6 100644 --- modules/system/system.module +++ modules/system/system.module @@ -1211,6 +1211,8 @@ function system_library() { ), 'dependencies' => array( array('system', 'ui.widget'), + array('system', 'ui.draggable'), + array('system', 'ui.resizable'), ), ); $libraries['ui.draggable'] = array(