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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/**
* @file
* Javascript for the interface at admin/content/media and also for interfaces
* related to setting up media fields and for media type administration.
*
* Basically, if it's on the /admin path, it's probably here.
*/
(function ($) {
/**
* Functionality for the administrative file listings.
*/
Drupal.behaviors.mediaAdmin = {
attach: function (context) {
// Show a javascript confirmation dialog if a user has files selected and
// they try to switch between the "Thumbnail" and "List" local tasks.
$('.tabs.secondary a').once('media-admin').bind('click', function () {
if ($(':checkbox:checked', $('.file-entity-admin-file-form')).length != 0) {
return confirm(Drupal.t('If you switch views, you will lose your selection.'));
}
});
if ($('.media-display-thumbnails').length && !$('.media-thumbnails-select').length) {
// Implements 'select all/none' for thumbnail view.
// @TODO: Support grabbing more than one page of thumbnails.
var allLink = $('<a href="#">' + Drupal.t('all') + '</a>')
.click(function () {
$('.media-display-thumbnails', $(this).parents('form')).find(':checkbox').attr('checked', true).change();
return false;
});
var noneLink = $('<a href="#">' + Drupal.t('none') + '</a>')
.click(function () {
$('.media-display-thumbnails', $(this).parents('form')).find(':checkbox').attr('checked', false).change();
return false;
});
$('<div class="media-thumbnails-select" />')
.append('<strong>' + Drupal.t('Select') + ':</strong> ')
.append(allLink)
.append(', ')
.append(noneLink)
.prependTo('.media-display-thumbnails')
// If the media item is clicked anywhere other than on the image itself
// check the checkbox. For the record, JS thinks this is wonky.
$('.media-item').bind('click', function (e) {
if ($(e.target).is('img, a')) {
return;
}
var checkbox = $(this).parent().find(':checkbox');
if (checkbox.is(':checked')) {
checkbox.attr('checked', false).change();
} else {
checkbox.attr('checked', true).change();
}
});
// Add an extra class to selected thumbnails.
$('.media-display-thumbnails :checkbox').each(function () {
var checkbox = $(this);
if (checkbox.is(':checked')) {
$(checkbox.parents('li').find('.media-item')).addClass('selected');
}
checkbox.bind('change.media', function () {
if (checkbox.is(':checked')) {
$(checkbox.parents('li').find('.media-item')).addClass('selected');
}
else {
$(checkbox.parents('li').find('.media-item')).removeClass('selected');
}
});
});
}
}
};
})(jQuery);
|