diff --git a/includes/media.fields.inc b/includes/media.fields.inc
index 9153cc9..caf2282 100644
--- a/includes/media.fields.inc
+++ b/includes/media.fields.inc
@@ -434,20 +434,8 @@ function theme_media_widget($variables) {
$element = $variables['element'];
$output = '';
- // Merge provided attributes with existing ones.
// The "form-media" class is required for proper Ajax functionality.
- $attributes = array(
- 'class' => array("media-widget", "form-media", "clearfix"),
- );
- if (!empty($element['#attributes'])) {
- $attributes = array_merge_recursive($attributes, $element['#attributes']);
- }
- if (!empty($element['#id'])) {
- $attributes = array_merge_recursive($attributes, array('id' => $element['#id'] . '--widget'));
- }
-
- // Render attributes into div in one go.
- $output .= '
';
+ $output .= '
';
$output .= drupal_render_children($element);
$output .= '
';
diff --git a/media.module b/media.module
index 6bffdff..711c495 100644
--- a/media.module
+++ b/media.module
@@ -714,8 +714,14 @@ function media_element_process($element, &$form_state, $form) {
// Append the '-upload' to the #id so the field label's 'for' attribute
// corresponds with the textfield element.
- $original_id = $element['#id'];
+ $original_id = $element['#original_id'] = $element['#id'];
$element['#id'] .= '-upload';
+ if (preg_match('/(^.*)(--\d+)/', $original_id, $matches)) {
+ $settings_id = $matches[1] . '-upload' . $matches[2];
+ }
+ else {
+ $settings_id = $element['#id'];
+ }
$fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;
// Set some default element properties.
@@ -832,7 +838,7 @@ function media_element_process($element, &$form_state, $form) {
$element['browse_button']['#attached']['js'] = array(
array(
'type' => 'setting',
- 'data' => array('media' => array('elements' => array('#' . $element['#id'] => $element['#media_options'])))
+ 'data' => array('media' => array('elements' => array('#' . $settings_id => $element['#media_options'])))
)
);