blob: 2341b6e7dc8127eee5f3abe2bece8d03c7eebad4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
(function ($) {
Drupal.behaviors.media_gallery = {};
Drupal.behaviors.media_gallery.attach = function (context, settings) {
// Bind a click handler to the 'add media' link.
$('a.media-gallery-add.launcher').once('media-gallery-add').bind('click', Drupal.media_gallery.open_browser);
};
Drupal.media_gallery = {};
Drupal.media_gallery.open_browser = function (event) {
event.preventDefault();
event.stopPropagation();
var pluginOptions = { 'id': 'media_gallery', 'multiselect' : true , 'types': Drupal.settings.mediaGalleryAllowedMediaTypes};
Drupal.media.popups.mediaBrowser(Drupal.media_gallery.add_media, pluginOptions);
};
Drupal.media_gallery.add_media = function (mediaFiles) {
// TODO AN-17966: Add the images to the node's media multifield on the client
// side instead of reloading the page.
var mediaAdded = function (returnedData, textStatus, XMLHttpRequest) {
parent.window.location.reload();
};
var errorCallback = function () {
//console.warn('Error: Media not added.');
};
var src = Drupal.settings.mediaGalleryAddImagesUrl;
var media = [];
for(var i = 0; i < mediaFiles.length; i++) {
media[i] = mediaFiles[i].fid;
}
$.ajax({
url: src,
type: 'POST',
dataType: 'json',
data: {files: media},
error: errorCallback,
success: mediaAdded
});
return false;
}
})(jQuery);
|