Index: modules/php/php.test =================================================================== RCS file: /cvs/drupal/drupal/modules/php/php.test,v retrieving revision 1.16 diff -u -r1.16 php.test --- modules/php/php.test 28 Aug 2009 16:23:04 -0000 1.16 +++ modules/php/php.test 2 Sep 2009 04:35:17 -0000 @@ -56,7 +56,7 @@ // Make sure that the PHP code shows up as text. $this->drupalGet('node/' . $node->nid); - $this->assertText('print', t('PHP code is displayed.')); + $this->assertText('print "SimpleTest PHP was executed!"', t('PHP code is displayed.')); // Change filter to PHP filter and see that PHP code is evaluated. $edit = array(); @@ -66,7 +66,7 @@ $this->assertRaw(t('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', t('PHP code isn\'t displayed.')); + $this->assertNoText('print "SimpleTest PHP was executed!"', t('PHP code isn\'t displayed.')); $this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.')); } } Index: modules/filter/filter.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.pages.inc,v retrieving revision 1.7 diff -u -r1.7 filter.pages.inc --- modules/filter/filter.pages.inc 8 Mar 2009 21:25:18 -0000 1.7 +++ modules/filter/filter.pages.inc 2 Sep 2009 04:35:17 -0000 @@ -11,14 +11,7 @@ * Menu callback; show a page with long filter tips. */ function filter_tips_long() { - $format = arg(2); - if ($format) { - $output = theme('filter_tips', _filter_tips($format, TRUE), TRUE); - } - else { - $output = theme('filter_tips', _filter_tips(-1, TRUE), TRUE); - } - return $output; + return theme('filter_tips', _filter_tips(-1, TRUE), TRUE); } Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.287 diff -u -r1.287 filter.module --- modules/filter/filter.module 30 Aug 2009 06:04:09 -0000 1.287 +++ modules/filter/filter.module 2 Sep 2009 04:35:16 -0000 @@ -57,9 +57,6 @@ 'arguments' => array('tips' => NULL, 'long' => FALSE), 'file' => 'filter.pages.inc', ), - 'filter_tips_more_info' => array( - 'arguments' => array(), - ), 'filter_guidelines' => array( 'arguments' => array('format' => NULL), ), @@ -635,10 +632,18 @@ ); $form['format_help'] = array( '#prefix' => '
', - '#markup' => theme('filter_tips_more_info'), + '#attached_dialog' => array(array( + 'trigger_selector' => '.filter-tips-modal', + 'content_selector' => '#filter-tips-modal-dialog', + 'options' => array( + 'width' => 600, + 'height' => 500, + ), + )), '#suffix' => '
', '#weight' => 1, ); + $form['format_help'] = array_merge($form['format_help'], filter_tips_more_info()); return $form; } @@ -736,12 +741,16 @@ } /** - * Format a link to the more extensive filter tips. - * - * @ingroup themeable + * Build a render() array which links to the more extensive filter tips. */ -function theme_filter_tips_more_info() { - return '

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

'; +function filter_tips_more_info() { + $build['more'] = array('#markup' => l(t('More information about text formats'), 'filter/tips', array('attributes' => array('class' => 'filter-tips-modal')))); + $build['long'] = array( + '#prefix' => '
', + '#markup' => filter_tips_long(), + '#suffix' => '
', + ); + return $build; } /** Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.981 diff -u -r1.981 common.inc --- includes/common.inc 31 Aug 2009 18:43:12 -0000 1.981 +++ includes/common.inc 2 Sep 2009 04:35:07 -0000 @@ -3177,14 +3177,18 @@ } /** - * Adds all the attached libraries, JavaScript and CSS to the page. + * Add to the page all structures attached to the element. + + * Structures like libraries, JavaScript, CSS and other types of custom + * are processed and added to the page. Attached structures can be added to the + * elements using the corresponding #attached_ property. The property name for + * attached structures begin with #attached_ and the rest if the type of + * structure being added. For example: #attached_library, #attached_js, + * #attached_css. A function named drupal_add_ must exists, where + * is the type of structure being addded. * - * @param $libraries - * An array of depending libraries to be added. - * @param $js - * An array of JavaScript components to add. - * @param $css - * An array of cascading stylesheets to add. + * @param $elements + * The structured array describing the data being rendered. * @param $weight * The default weight of JavaScript and CSS being added. This is only applied * to the stylesheets and JavaScript items that don't have an explicit weight @@ -3197,12 +3201,26 @@ * Will return FALSE if there were any missing library dependencies. TRUE will * be returned if all library dependencies were met. * - * @see drupal_add_library(), drupal_render() - */ -function drupal_process_attached(array $libraries = array(), array $js = array(), array $css = array(), $weight = JS_DEFAULT, $dependency_check = FALSE) { + * @see drupal_add_library(). + * @see drupal_add_js(). + * @see drupal_add_css(). + * @see drupal_render(). + */ +function drupal_process_attached($elements, $weight = JS_DEFAULT, $dependency_check = FALSE) { + $attached = element_attached($elements); + // If there is nothing to process return + if (empty($attached)) { + return; + } + $elements += array( + '#attached_library' => array(), + '#attached_js' => array(), + '#attached_css' => array(), + ); + // Add the libraries first. $success = TRUE; - foreach ($libraries as $library) { + foreach ($elements['#attached_library'] as $library) { if (drupal_add_library($library[0], $library[1]) === FALSE) { $success = FALSE; // Exit if the dependency is missing. @@ -3213,8 +3231,8 @@ } // Add both the JavaScript and the CSS. - foreach (array('js' => $js, 'css' => $css) as $type => $items) { - foreach ($items as $data => $options) { + foreach (array('js', 'css') as $type) { + foreach ($elements["#attached_$type"] as $data => $options) { // If the value is not an array, it's a filename and passed as first // (and only) argument. if (!is_array($options)) { @@ -3234,6 +3252,13 @@ call_user_func('drupal_add_' . $type, $data, $options); } } + + // Add additional types of attachments specified in the render() structure. + $attached = array_diff($attached, array('#attached_library', '#attached_js', '#attached_css')); + foreach ($attached as $type) { + call_user_func_array('drupal_add_'. str_replace('#attached_', '', $type), $elements[$type]); + } + return $success; } @@ -3266,7 +3291,12 @@ if (!isset($added[$module][$name])) { if ($library = drupal_get_library($module, $name)) { // Add all components within the library. - $added[$module][$name] = drupal_process_attached($library['dependencies'], $library['js'], $library['css'], JS_LIBRARY, TRUE); + $elements = array( + '#attached_library' => $library['dependencies'], + '#attached_js' => $library['js'], + '#attached_css' => $library['css'], + ); + $added[$module][$name] = drupal_process_attached($elements, JS_LIBRARY, TRUE); } else { // Requested library does not exist. @@ -4115,12 +4145,9 @@ } } - // Add additional libraries, CSS and JavaScript associated with this element. - drupal_process_attached( - isset($elements['#attached_library']) ? $elements['#attached_library'] : array(), - isset($elements['#attached_js']) ? $elements['#attached_js'] : array(), - isset($elements['#attached_css']) ? $elements['#attached_css'] : array() - ); + // Add additional libraries, CSS, JavaScript an other custom + // attached structures associated with this element. + drupal_process_attached($elements); $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : ''; $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; @@ -4226,12 +4253,9 @@ $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache'; if (!empty($cid) && $cache = cache_get($cid, $bin)) { - // Add additional libraries, CSS and JavaScript associated with this element. - drupal_process_attached( - isset($cache->data['#attached_library']) ? $cache->data['#attached_library'] : array(), - isset($cache->data['#attached_js']) ? $cache->data['#attached_js'] : array(), - isset($cache->data['#attached_css']) ? $cache->data['#attached_css'] : array() - ); + // Add additional libraries, JavaScript, CSS and other custom structures + // attached to this element. + drupal_process_attached($cache->data); // Return the rendered output. return $cache->data['#markup'];; } @@ -4409,6 +4433,23 @@ } /** + * Check if the key is an attached property. + */ +function element_attached_property($key) { + return strpos($key, '#attached_') === 0; +} + +/** + * Get attached properties of a structured array element. Attached properties + * begin with '#attached_' and the rest after the underscore is used + * for the type of the attached structure. For example: #attached_js, + * #attached_css, #attached_library. + */ +function element_attached($element) { + return array_filter(array_keys((array) $element), 'element_attached_property'); +} + +/** * Get properties of a structured array element. Properties begin with '#'. */ function element_properties($element) { @@ -5409,3 +5450,40 @@ return call_user_func_array('_xmlrpc', $args); } +/** + * Adds a dialog using jQuery UI. + * + * @param $options + * An array of options with the following keys: + * - 'trigger_selector' + * A jQuery selector which should open a dialog when clicked. + * Example: 'a#modal-link'. + * - 'content_selector' + * A jQuery selector which contains the content for display in the dialog. + * - 'options' + * An array of dialog options keyed by option name. + * See @link http://docs.jquery.com/UI/Dialog#options for available + * options. + */ +function drupal_add_dialog(array $options = array()) { + $dialogs = &drupal_static(__FUNCTION__, array()); + // Add default options to the options array. + $options += array( + 'options' => array(), + ); + if (!count($dialogs)) { + drupal_add_library('system', 'ui.dialog'); + drupal_add_library('system', 'ui.draggable'); + drupal_add_library('system', 'ui.resizable'); + drupal_add_js('misc/dialog.js'); + } + $trigger_selector = $options['trigger_selector']; + if (!isset($dialogs[$trigger_selector])) { + $dialogs[$trigger_selector] = array( + 'content_selector' => $options['content_selector'], + 'options' => $options['options'], + ); + drupal_add_js(array('dialogs' => $dialogs), 'setting'); + } + return $dialogs; +} Index: misc/dialog.js =================================================================== RCS file: misc/dialog.js diff -N misc/dialog.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/dialog.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,31 @@ +// $Id$ +(function ($) { + +/** + * Initialize all modal dialogs requested by drupal_add_dialog(). + */ +Drupal.behaviors.dialog = { + attach: function (context, settings) { + for (var key in Drupal.settings.dialogs) { + if (!$(key).hasClass('dialog-processed')) { + var dialog = Drupal.settings.dialogs[key]; + // Initialize the dialog with some default settings. + // Other default settings are defined by http://docs.jquery.com/UI/Dialog. + $(dialog.content_selector).dialog({ + autoOpen: false + }); + // Alter the dialog with any custom settings. + for (var optionName in dialog.options) { + $(dialog.content_selector).dialog('option', optionName, dialog.options[optionName]); + } + $(key).click(function() { + $(dialog.content_selector).dialog('open'); + return false; + }) + .addClass('dialog-processed'); + } + } + } +} + +})(jQuery);