Closed (fixed)
Project:
D7 Media
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
28 Mar 2012 at 16:40 UTC
Updated:
6 Apr 2017 at 10:46 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
spearhead93 commentedEnclosed a patch setting up a class per style for a media element added through a wysiwyg editor.
Comment #2
areikiera commentedI think this would be wonderful to include in the module!
(In my case, I'm using responsive images and have full-width image styles for each breaking point, but due to slight inconsistencies between browsers, the image might switch slightly before or after the breakpoint and having a class specifically for my full-width responsive images has allowed me to apply styles (width: 100%) that hide those inconsistencies.)
Comment #3
mrfelton commentedGood idea. Can be very useful. Though I think this should also cover files uploaded to and rendered from a file field. I wonder if this should handed in file_entity?
Comment #4
kclarkson commentedI needed this and found some code on Drupal stackexchange. http://drupal.stackexchange.com/a/40483to
It uses a theme function to automatically creates a class name based on the image style name. All you do is paste this code at the bottom of your theme's template.php file and change the MYTHEME to the name of the theme. ex. if you use bartik it would be bartik_image_style.
function MYTHEME_image_style($variables) {
// Determine the dimensions of the styled image.
$dimensions = array(
'width' => $variables['width'],
'height' => $variables['height'],
);
image_style_transform_dimensions($variables['style_name'], $dimensions);
$variables['width'] = $dimensions['width'];
$variables['height'] = $dimensions['height'];
$variables['attributes'] = array(
'class' => $variables['style_name'],
);
// Determine the url for the styled image.
$variables['path'] = image_style_url($variables['style_name'], $variables['path']);
return theme('image', $variables);
}
Comment #5
johnpitcairn commentedThere is a hook available to alter wysiwyg media markup. I've been using this code in a module:
Comment #6
Anonymous (not verified) commentedRelated to this, it would be nice if there was a different class per file type. (E.g., media-image for images vs media-doc for documents.) :)
At least in 7.x-2.0, this doesn't seem to be the case, at least when inserting via the WYSIWYG plugin.
Wasn't sure if I should open a separate ticket for this or not.
Comment #7
arthurf commentedBy default media now adds these classes to files inserted that have these classes: media, media-element-container, and media-$view_mode. Otherwise you can use the media_token_to_markup_alter() mentioned in #5
Comment #8
gmclelland commented@arthur - I think does normally, but it doesn't seem to be working on when using media_vimeo
Here is the output from a media_vimeo-2.x-dev insert:
Here is the output from a media_youtube-2.x-dev insert:
Note: notice the file-4-x-3-video, that is the view mode
I will post an issue for media_vimeo. I just wanted to point out that some provider modules might not be updated yet.
Comment #9
gmclelland commentedHere is the issue for media_vimeo #1934632: Use the standard embedded media module output if you want the fix.
Comment #10
rahul_sankrit commentedAdding a class to Article body iframe for youtube embed code using jQuery drupal7