root / drupal7 / sites / all / modules / media / js / media.admin.js @ 6ae446a4
1 |
/**
|
---|---|
2 |
* @file
|
3 |
* Javascript for the interface at admin/content/media and also for interfaces
|
4 |
* related to setting up media fields and for media type administration.
|
5 |
*
|
6 |
* Basically, if it's on the /admin path, it's probably here.
|
7 |
*/
|
8 |
|
9 |
(function ($) { |
10 |
|
11 |
/**
|
12 |
* Functionality for the administrative file listings.
|
13 |
*/
|
14 |
Drupal.behaviors.mediaAdmin = { |
15 |
attach: function (context) { |
16 |
// Show a JavaScript confirmation dialog if a user has files selected and
|
17 |
// they try to switch between the "Thumbnail" and "List" local tasks.
|
18 |
$('.tabs.secondary a').once('media-admin').bind('click', function () { |
19 |
if ($(':checkbox:checked', $('.file-entity-admin-file-form')).length != 0) { |
20 |
return confirm(Drupal.t('If you switch views, you will lose your selection.')); |
21 |
} |
22 |
}); |
23 |
|
24 |
if ($('.media-display-thumbnails').length && !$('.media-thumbnails-select').length) { |
25 |
// Implements 'select all/none' for thumbnail view.
|
26 |
// @TODO: Support grabbing more than one page of thumbnails.
|
27 |
var allLink = $('<a href="#">' + Drupal.t('all') + '</a>') |
28 |
.click(function () {
|
29 |
$('.media-display-thumbnails', $(this).parents('form')).find(':checkbox').attr('checked', true).change(); |
30 |
return false; |
31 |
}); |
32 |
var noneLink = $('<a href="#">' + Drupal.t('none') + '</a>') |
33 |
.click(function () {
|
34 |
$('.media-display-thumbnails', $(this).parents('form')).find(':checkbox').attr('checked', false).change(); |
35 |
return false; |
36 |
}); |
37 |
$('<div class="media-thumbnails-select" />') |
38 |
.append('<strong>' + Drupal.t('Select') + ':</strong> ') |
39 |
.append(allLink) |
40 |
.append(', ')
|
41 |
.append(noneLink) |
42 |
.prependTo('.media-display-thumbnails')
|
43 |
// If the media item is clicked anywhere other than on the image itself
|
44 |
// check the checkbox. For the record, JS thinks this is wonky.
|
45 |
$('.media-item').bind('click', function (e) { |
46 |
if ($(e.target).is('img, a')) { |
47 |
return;
|
48 |
} |
49 |
var checkbox = $(this).parent().find(':checkbox'); |
50 |
if (checkbox.is(':checked')) { |
51 |
checkbox.attr('checked', false).change(); |
52 |
} else {
|
53 |
checkbox.attr('checked', true).change(); |
54 |
} |
55 |
}); |
56 |
|
57 |
// Add an extra class to selected thumbnails.
|
58 |
$('.media-display-thumbnails :checkbox').each(function () { |
59 |
var checkbox = $(this); |
60 |
if (checkbox.is(':checked')) { |
61 |
$(checkbox.parents('li').find('.media-item')).addClass('selected'); |
62 |
} |
63 |
|
64 |
checkbox.bind('change.media', function () { |
65 |
if (checkbox.is(':checked')) { |
66 |
$(checkbox.parents('li').find('.media-item')).addClass('selected'); |
67 |
} |
68 |
else {
|
69 |
$(checkbox.parents('li').find('.media-item')).removeClass('selected'); |
70 |
} |
71 |
}); |
72 |
}); |
73 |
} |
74 |
} |
75 |
}; |
76 |
|
77 |
})(jQuery); |