Untitled diff

Erstellt Diff läuft nie ab
94 Entfernungen
376 Zeilen
33 Hinzufügungen
321 Zeilen
diff --git a/media_multiselect.js b/media_multiselect.js
diff --git a/media_multiselect.js b/media_multiselect.js
index 0523763..fc48a5d 100644
index 0523763..bc7c659 100644
--- a/media_multiselect.js
--- a/media_multiselect.js
+++ b/media_multiselect.js
+++ b/media_multiselect.js
@@ -4,35 +4,48 @@
@@ -4,35 +4,48 @@
for (var base in settings.ajax) {
for (var base in settings.ajax) {
var element_settings = settings.ajax[base];
var element_settings = settings.ajax[base];
if (element_settings.event == 'media_select' && !$('#' + base + '.media-multiselect-processed').length) {
if (element_settings.event == 'media_select' && !$('#' + base + '.media-multiselect-processed').length) {
+ $('#' + base).show();
+ $('#' + base).show();
// Bind a click-event to the 'add more' button.
// Bind a click-event to the 'add more' button.
$('#' + base).click((function(element) { return function(event) {
$('#' + base).click((function(element) { return function(event) {
var media_settings = settings.media.multi_select.elements[element];
var media_settings = settings.media.multi_select.elements[element];
- // Add a new beforeSerialize that adds in our fids
// Add a new beforeSerialize that adds in our fids
- Drupal.ajax[element].beforeSerialize = function (element, options) {
- Drupal.ajax[element].beforeSerialize = function (element, options) {
+ // Add a new beforeSerialize that adds in our fids.
+ Drupal.ajax[element].beforeSerialize = function(element, options) {
+ Drupal.ajax[element].beforeSerialize = function(element, options) {
// Add the fids to the form_values.
// Add the fids to the form_values.
$(this.media_multiselect_files).each(function() {
$(this.media_multiselect_files).each(function() {
options.data['media_multiselect_fids[' + this.fid + ']'] = this.fid;
options.data['media_multiselect_fids[' + this.fid + ']'] = this.fid;
- })
- })
+ });
+ });
Text moved with changes to lines 27-32 (99.8% similarity)
+
// Call the prototype, so we preseve any existing functionality in there.
- Drupal.ajax.prototype.beforeSerialize.call(this, element, options)
- }
-
- var button = this;
+ Drupal.ajax.prototype.beforeSerialize.call(this, element, options);
+ Drupal.ajax.prototype.beforeSerialize.call(this, element, options);
+ };
+ };
+
+
+ var wrapper = $(this).closest('div.form-wrapper');
+ var wrapper = $(this).closest('div.form-wrapper');
Text moved with changes from lines 23-28 (99.8% similarity)
- // Call the prototype, so we preseve any existing functionality in there.
- Drupal.ajax.prototype.beforeSerialize.call(this, element, options)
- }
-
- var button = this;
// Launch the Media Browser.
// Launch the Media Browser.
Drupal.media.popups.mediaBrowser(function(files) {
Drupal.media.popups.mediaBrowser(function(files) {
- Drupal.ajax[element].media_multiselect_files = files
- Drupal.ajax[element].media_multiselect_files = files
- $(button).trigger('media_select');
- $(button).trigger('media_select');
+ Drupal.ajax[element].media_multiselect_files = files;
+ Drupal.ajax[element].media_multiselect_files = files;
+ for (var i = 0; i < files.length; i++) {
+ for (var i = 0; i < files.length; i++) {
+ var button = wrapper.find('.multi-browse').first();
+ var button = wrapper.find('.multi-browse').first();
+ var uploadField = button.siblings('.upload');
+ var uploadField = button.siblings('.upload');
+
+
+ // Set the value of the hidden file ID field and trigger a change.
+ // Set the value of the hidden file ID field and trigger a change.
+ uploadField.val(files[i].fid);
+ uploadField.val(files[i].fid);
+ uploadField.trigger('change');
+ uploadField.trigger('change');
+
+
+ // Find the attach button and automatically trigger it.
+ // Find the attach button and automatically trigger it.
+ var attachButton = uploadField.siblings('.attach');
+ var attachButton = uploadField.siblings('.attach');
+ Drupal.ajax[attachButton.attr('id')].options.async = false;
+ Drupal.ajax[attachButton.attr('id')].options.async = false;
+ attachButton.trigger('mousedown');
+ attachButton.trigger('mousedown');
+ }
+ }
}, media_settings.global);
}, media_settings.global);
// Aaaand prevent default.
// Aaaand prevent default.
event.preventDefault();
event.preventDefault();
- }})(base))
- }})(base))
+ }})(base));
+ }})(base));
$('#' + base).addClass('media-multiselect-processed');
$('#' + base).addClass('media-multiselect-processed');
}
}
}
}
}
}
- }
- }
-})(jQuery);
+ };
})(jQuery);
\ No newline at end of file
\ No newline at end of file
+ };
+})(jQuery);
diff --git a/media_multiselect.module b/media_multiselect.module
diff --git a/media_multiselect.module b/media_multiselect.module
index 1ab4d38..8e498fd 100644
index 6caa609..666acb4 100644
--- a/media_multiselect.module
--- a/media_multiselect.module
+++ b/media_multiselect.module
+++ b/media_multiselect.module
@@ -62,7 +62,7 @@ function media_multiselect_field_widget_settings_form($field, $instance) {
@@ -84,7 +84,7 @@ function media_multiselect_field_widget_form(&$form, &$form_state, $field, $inst
function media_multiselect_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$form['#entity'] = (!empty($element['#entity'])) ? $element['#entity'] : NULL;
- // We cheat and alter the widget-type to the normal media widget
+ // We cheat and alter the widget-type to the normal media widget.
$instance['widget']['type'] = 'media_generic';
$instance['widget']['module'] = 'media';
@@ -77,13 +77,14 @@ function media_multiselect_field_widget_form(&$form, &$form_state, $field, $inst
$form,
$form_state
);
- } else {
+ }
+ else {
$real_cardinality = $field['cardinality'];
$field['cardinality'] = -1;
}
}
- // Then ask the Field API to generate that widget
// Then ask the Field API to generate that widget
- $element += field_multiple_value_form($field, $instance, $langcode, $items, $form, $form_state);
- $element += field_multiple_value_form($field, $instance, $langcode, $items, $form, $form_state);
+ // Then ask the Field API to generate that widget.
+ $element += media_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
+ $element += media_field_widget_form($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
// If we have a != 1, != unlimited field, we have a fixed amount of values
// If we have a != 1, != unlimited field, we have a fixed amount of values
// which we can't ajaxify the 'add-more' button of, as it does not have a
// which we can't ajaxify the 'add-more' button of, as it does not have a
@@ -92,53 +93,59 @@ function media_multiselect_field_widget_form(&$form, &$form_state, $field, $inst
@@ -93,55 +93,59 @@ function media_multiselect_field_widget_form(&$form, &$form_state, $field, $inst
return $element;
return $element;
}
}
- // Copy over the media-options
- // Copy over the media-options
- $element['#media_options'] = $element[0]['#media_options'];
- $element['#media_options'] = $element[0]['#media_options'];
- $element['#media_options']['global']['multiselect'] = TRUE;
- $element['#media_options']['global']['multiselect'] = TRUE;
-
+ $element[$element['#file_upload_delta']]['#media_options']['global']['multiselect'] = TRUE;
+ $element[$element['#file_upload_delta']]['#process'][] = 'media_multiselect_change_add_button';
- do {
- do {
- // Remove the empty placeholder-item at the bottom, and any access items in case
- // Remove the empty placeholder-item at the bottom, and any access items in case
- // we have a limited cardinality field that has too many items chosen!
- // we have a limited cardinality field that has too many items chosen!
- unset($element[$element['#max_delta']]);
- unset($element[$element['#max_delta']]);
- $element['#max_delta'] -= 1;
- $element['#max_delta'] -= 1;
- } while ($real_cardinality != -1 && $element['#max_delta'] >= $real_cardinality);
- } while ($real_cardinality != -1 && $element['#max_delta'] >= $real_cardinality);
-
-
- // Add our JS
- // Add our JS
+ $element[$element['#file_upload_delta']]['#media_options']['global']['multiselect'] = TRUE;
+ $element[$element['#file_upload_delta']]['#process'][] = 'media_multiselect_change_add_button';
+
+ // If we no longer have any items, change the theme to avoid an empty table.
+ // If we no longer have any items, change the theme to avoid an empty table.
+ if ($element['#file_upload_delta'] == 0) {
+ if ($element['#file_upload_delta'] == 0) {
+ $element[$element['#file_upload_delta']]['#add_button_title'] = t('Select media');
+ $element[$element['#file_upload_delta']]['#add_button_title'] = t('Select media');
+ }
+ }
+ elseif ($element['#file_upload_delta'] == $real_cardinality - 1) {
+ elseif ($element['#file_upload_delta'] == $real_cardinality - 1) {
+ $element[$element['#file_upload_delta']]['#add_button_access'] = FALSE;
+ $element[$element['#file_upload_delta']]['#add_button_access'] = FALSE;
+ }
+ }
+ else {
+ else {