Commit 72fe72c5 authored by brockfanning's avatar brockfanning Committed by olstjos

Issue #2842391 by brockfanning, joseph.olstad: better support for float media...

Issue #2842391 by brockfanning, joseph.olstad: better support for float media left and float media right
parent b3c88f97
/**
* @file
* Styles to apply to all user-facing pages for alignment support.
*/
.media-wysiwyg-align-left {
float: left;
margin-right: 20px;
}
.media-wysiwyg-align-right {
float: right;
margin-left: 20px;
}
.media-wysiwyg-align-center {
text-align: center;
}
......@@ -18,3 +18,20 @@
#media-wysiwyg-format-form .form-item-format label {
display: inline;
}
/* Styles for within the WYSIWYG, to support alignment. */
.media-wysiwyg-align-left {
float: left;
margin-right: 20px;
}
.media-wysiwyg-align-right {
float: right;
margin-left: 20px;
}
.media-wysiwyg-align-center {
text-align: center;
}
img.media-wysiwyg-align-center {
margin: auto;
display: block;
}
......@@ -207,6 +207,18 @@ function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE, $langcode = NUL
return '';
}
// Remove any alignment classes from $settings, because it will be added later
// in this function to the media's wrapper, and we don't want to confuse CSS
// by having it on both the wrapper and the element.
if (isset($settings['attributes']['class'])) {
$alignment_classes = array(
'media-wysiwyg-align-left',
'media-wysiwyg-align-right',
'media-wysiwyg-align-center',
);
$settings['attributes']['class'] = array_diff($settings['attributes']['class'], $alignment_classes);
}
// If the tag has link text stored with it, override the filename with it for
// the rest of this function, so that if the file is themed as a link, the
// desired text will be used (see, for example, theme_file_link()).
......@@ -288,6 +300,14 @@ function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE, $langcode = NUL
$element['#pre_render'][] = 'media_wysiwyg_pre_render_cached_filter';
}
}
if (!empty($element['content']) && !empty($tag_info['fields']['alignment'])) {
// Set a CSS class if an alignment has been specified and is correct.
$alignment = $tag_info['fields']['alignment'];
if (in_array($alignment, array('left', 'right', 'center'))) {
$alignment_class = 'media-wysiwyg-align-' . $alignment;
$element['content']['#attributes']['class'][] = $alignment_class;
}
}
drupal_alter('media_wysiwyg_token_to_markup', $element, $tag_info, $settings, $langcode);
$output = drupal_render($element);
unset($recursion_stop[$file->fid]);
......
......@@ -83,6 +83,28 @@ function media_wysiwyg_format_form($form, &$form_state, $file) {
they are inserted into an editor.')
);
// If necessary, display the alignment widget.
if (variable_get('media_wysiwyg_alignment', FALSE)) {
$align_default = empty($query_fields['alignment']) ? '' : $query_fields['alignment'];
$align_options = array(
'' => t('None'),
'left' => t('Left'),
'right' => t('Right'),
'center' => t('Center'),
);
if (!isset($align_options[$align_default])) {
// Safety code for a malformed token.
$align_default = '';
}
$form['options']['alignment'] = array(
'#type' => 'select',
'#title' => t('Alignment'),
'#options' => $align_options,
'#description' => t('Choose how you would like the media to be aligned with surrounding content.'),
'#default_value' => $align_default,
);
}
// Add fields from the file, so that we can override them if necessary.
$form['options']['fields'] = array();
foreach ($fields as $field_name => $field_value) {
......
......@@ -282,6 +282,13 @@
});
classes.push('file-' + info.view_mode.replace(/_/g, '-'));
}
// Check for alignment info, after removing any existing alignment class.
element.removeClass (function (index, css) {
return (css.match (/\bmedia-wysiwyg-align-\S+/g) || []).join(' ');
});
if (info.fields && info.fields.alignment) {
classes.push('media-wysiwyg-align-' + info.fields.alignment);
}
element.addClass(classes.join(' '));
// Apply link_text if present.
......
......@@ -56,6 +56,9 @@ function media_wysiwyg_schema() {
*/
function media_wysiwyg_install() {
media_wysiwyg_update_7204();
// Start off with the alignment feature enabled.
variable_set('media_wysiwyg_alignment', TRUE);
}
/**
......@@ -72,6 +75,7 @@ function media_wysiwyg_uninstall() {
variable_del('media_wysiwyg_wysiwyg_browser_plugins');
variable_del('media_wysiwyg_wysiwyg_override_field_types');
variable_del('media_wysiwyg_use_link_text_for_filename');
variable_del('media_wysiwyg_alignment');
}
/**
......@@ -223,3 +227,13 @@ function media_wysiwyg_update_7205() {
module_invoke_all('modules_uninstalled', array($module));
}
/**
* Notify upgraders that there's optional media alignment functionality that needs to be enabled.
*/
function media_wysiwyg_update_7206() {
$message = t('If you would like to be able to align your embedded media (left, right, or center), go to /admin/config/media/browser and check "Provide alignment option when embedding media", and save the settings.');
drupal_set_message($message,'warning',TRUE);
}
......@@ -17,6 +17,20 @@ require_once dirname(__FILE__) . '/includes/media_wysiwyg.uuid.inc';
// Functions for features integration.
require_once dirname(__FILE__) . '/includes/media_wysiwyg.features.inc';
/**
* Implements hook_page_build().
*/
function media_wysiwyg_page_build(&$page) {
// We need to load some minor CSS if media alignment is enabled.
if (variable_get('media_wysiwyg_alignment', FALSE)) {
$page['page_bottom']['media_wysiwyg']['#attached']['css'] = array(
drupal_get_path('module', 'media_wysiwyg') . '/css/media_wysiwyg.base.css' => array(
'every_page' => TRUE,
),
);
}
}
/**
* Implements hook_hook_info().
*/
......@@ -292,6 +306,13 @@ function media_wysiwyg_form_media_admin_config_browser_alter(&$form, &$form_stat
'#description' => t('When formatting inserted media, allow editable link text to be used in place of the filename. Turn this off if your file view modes handle link formatting.'),
);
$form['wysiwyg']['media_wysiwyg_alignment'] = array(
'#type' => 'checkbox',
'#title' => t('Provide alignment option when embedding media'),
'#default_value' => variable_get('media_wysiwyg_alignment', FALSE),
'#description' => t('If checked, there will be an alignment (left/right/center) option when embedding media in a WYSIWYG.'),
);
$form['#submit'][] = 'media_wysiwyg_admin_config_browser_pre_submit';
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment