media.admin.js
4.92 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @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 thumbnail display
*/
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.
$('.media-display-switch a').bind('click', function () {
if ($(':checkbox:checked', $('form#media-admin')).length != 0) {
return confirm(Drupal.t('If you switch views, you will lose your selection.'));
}
});
// Configure the "Add file" link to fire the media browser popup.
var $launcherLink = $('<a class="media-launcher" href="#"></a>').html(Drupal.t('Add file'));
$launcherLink.bind('click', function () {
// This option format needs *serious* work.
// Not even bothering documenting it because it needs to be thrown.
// See media.browser.js and media.browser.inc - media_browser()
// For how it gets passed.
var options = {
disabledPlugins: ['library'],
multiselect: true
};
Drupal.media.popups.mediaBrowser(function (mediaFiles) {
// When the media browser succeeds, we refresh
// @TODO: Should jump to the new media file and perhaps highlight it.
parent.window.location.reload();
return false;
}, options);
});
$('ul.action-links', context).prepend($('<li></li>').append($launcherLink));
if ($('.media-display-thumbnails').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-admin > div')
// 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');
}
});
});
}
// When any checkboxes are clicked on this form check to see if any are checked.
// If any checkboxes are checked, show the edit options (@todo rename to edit-actions).
$('#media-admin :checkbox').bind('change', function () {
Drupal.behaviors.mediaAdmin.showOrHideEditOptions();
});
Drupal.behaviors.mediaAdmin.showOrHideEditOptions();
},
// Checks if any checkboxes on the form are checked, if so it will show the
// edit-options panel.
showOrHideEditOptions: function() {
var fieldset = $('#edit-options');
if (!$('#media-admin input[type=checkbox]:checked').size()) {
fieldset.slideUp('fast');
}
else {
fieldset.slideDown('fast');
}
}
};
/**
* JavaScript for the Media types administrative form.
*/
Drupal.behaviors.mediaTypesAdmin = {
attach: function (context) {
if ($('.form-item-match-type', context).length == 0) {
return;
}
// Toggle the 'other' text field on Match type.
if ($('.form-item-match-type input:checked').val() != 'other') {
$('.form-item-match-type-other').hide();
}
$('.form-item-match-type input').change(function () {
if ($(this).val() == 'other') {
$('.form-item-match-type-other').slideDown('fast');
}
else {
$('.form-item-match-type-other').slideUp('fast');
}
});
}
};
})(jQuery);