diff --git a/includes/common.inc b/includes/common.inc index 1454cf0..4f11231 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1,5 +1,5 @@ array(), + 'js' => array(), + 'css' => array(), + ); + // Add the libraries first. $success = TRUE; - foreach ($libraries as $library) { + foreach ($attachments['library'] as $library) { if (drupal_add_library($library[0], $library[1]) === FALSE) { $success = FALSE; // Exit if the dependency is missing. @@ -3213,7 +3226,7 @@ function drupal_process_attached(array $libraries = array(), array $js = array() } // Add both the JavaScript and the CSS. - foreach (array('js' => $js, 'css' => $css) as $type => $items) { + foreach (array('js' => $attachments['js'], 'css' => $attachments['css']) as $type => $items) { foreach ($items as $data => $options) { // If the value is not an array, it's a filename and passed as first // (and only) argument. @@ -3234,6 +3247,13 @@ function drupal_process_attached(array $libraries = array(), array $js = array() call_user_func('drupal_add_' . $type, $data, $options); } } + + // Attach other types of attachments specified in the reder() structure. + $types = array_diff(array_keys($attachments), array('library', 'css', 'js')); + foreach ($types as $type) { + call_user_func_array('drupal_add_'. $type, $attachments[$type]); + } + return $success; } @@ -3266,7 +3286,12 @@ function drupal_add_library($module, $name) { 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); + $attachments = array( + 'library' => $library['dependencies'], + 'js' => $library['js'], + 'css' => $library['css'], + ); + $added[$module][$name] = drupal_process_attached($attachments, JS_LIBRARY, TRUE); } else { // Requested library does not exist. @@ -4115,12 +4140,15 @@ function drupal_render(&$elements) { } } - // 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 + // attachment associated with this element. + $attached = element_attached($elements); + $attachments = array(); + foreach ($attached as $key) { + $type = str_replace('#attached_', '', $key); + $attachments[$type] = $elements[$key]; + } + drupal_process_attached($attachments); $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : ''; $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; @@ -4226,12 +4254,15 @@ function drupal_render_cache_get($elements) { $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, CSS and JavaScript an other custom + // attachment associated with this elementassociated with this element. + $attached = element_attached($cache->data); + $attachments = array(); + foreach ($attached as $key) { + $type = str_replace('#attached_', '', $key); + $attachments[$type] = $cache->data[$key]; + } + drupal_process_attached($attachments); // Return the rendered output. return $cache->data['#markup'];; } @@ -4409,6 +4440,21 @@ function element_property($key) { } /** + * Check if the key is an attachment. + */ +function element_attachment($key) { + return strpos($key, '#attached_') === 0; +} + +/** + * Get attachments of a structured array element. Attachments begin with + * '#attached_'. + */ +function element_attached($element) { + return array_filter(array_keys((array) $element), 'element_attachment'); +} + +/** * Get properties of a structured array element. Properties begin with '#'. */ function element_properties($element) { @@ -4479,8 +4525,6 @@ function drupal_common_theme() { 'maintenance_page' => array( 'arguments' => array('content' => NULL, 'show_messages' => TRUE), 'template' => 'maintenance-page', - 'path' => 'includes', - 'file' => 'theme.maintenance.inc', ), 'update_page' => array( 'arguments' => array('content' => NULL, 'show_messages' => TRUE), @@ -5411,3 +5455,37 @@ function xmlrpc($url) { return call_user_func_array('_xmlrpc', $args); } +/** + * Adds a dialog using jQuery UI. + * + * @param $options + * An array of options, with 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 http://docs.jquery.com/UI/Dialog#options for available options. + */ +function drupal_add_dialog(array $options = array()) { + kpr($options); + $dialogs = &drupal_static(__FUNCTION__, 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; +} diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc index 92b3cd1..7780e89 100644 --- a/modules/filter/filter.admin.inc +++ b/modules/filter/filter.admin.inc @@ -1,5 +1,5 @@ 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 @@ function filter_form($selected_format = FILTER_FORMAT_DEFAULT, $weight = NULL, $ ); $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 @@ function filter_dom_serialize($dom_document) { } /** - * 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; } /** diff --git a/modules/filter/filter.pages.inc b/modules/filter/filter.pages.inc index 5d76af4..a2b2f0d 100644 --- a/modules/filter/filter.pages.inc +++ b/modules/filter/filter.pages.inc @@ -1,5 +1,5 @@