PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/sites/all/modules/media/js/media.admin.js

https://github.com/rtdean93/tbytam
JavaScript | 149 lines | 102 code | 17 blank | 30 comment | 22 complexity | 81bc7e4d6bac4e59a359e94e7807a79e MD5 | raw file
  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. (function ($) {
  9. /**
  10. * Functionality for the thumbnail display
  11. */
  12. Drupal.behaviors.mediaAdmin = {
  13. attach: function (context) {
  14. var show_confirm_if_existing_selections = function () {
  15. if ($(':checkbox:checked', $('form#media-admin')).length != 0) {
  16. return confirm(Drupal.t('If you switch views, you will lose your selection.'));
  17. }
  18. }
  19. $('.media-display-switch a').bind('click', show_confirm_if_existing_selections)
  20. // Configure the "Add file" link to fire the media browser popup.
  21. $('ul.action-links li', context).remove();
  22. if ($('form.media-list-operation', context).length != 0) {
  23. return;
  24. }
  25. var $launcherLink = $('<a class="media-launcher" href="#"></a>').html('Add file');
  26. $launcherLink.bind('click', function () {
  27. // This option format needs *serious* work.
  28. // Not even bothering documenting it because it needs to be thrown.
  29. // See media.browser.js and media.browser.inc - media_browser()
  30. // For how it gets passed.
  31. var options = {
  32. disabledPlugins: ['library'],
  33. multiselect: true
  34. };
  35. Drupal.media.popups.mediaBrowser(function (mediaFiles) {
  36. // When the media browser succeeds, we refresh
  37. // @TODO: Should jump to the new media file and perhaps highlight it.
  38. parent.window.location.reload();
  39. return false;
  40. }, options);
  41. });
  42. $('ul.action-links', context).append($('<li></li>').append($launcherLink));
  43. if ($('body.page-admin-content-media-thumbnails').length != 0) {
  44. // Implements 'select all/none' for thumbnail view.
  45. // @TODO: Support grabbing more than one page of thumbnails.
  46. var allLink = $('<a href="#">' + Drupal.t('all') + '</a>')
  47. .click(function () {
  48. $('.media-display-thumbnails', $(this).parents('form')).find(':checkbox').attr('checked', true).change();
  49. return false;
  50. });
  51. var noneLink = $('<a href="#">' + Drupal.t('none') + '</a>')
  52. .click(function () {
  53. $('.media-display-thumbnails', $(this).parents('form')).find(':checkbox').attr('checked', false).change();
  54. return false;
  55. });
  56. $('<div class="media-thumbnails-select" />')
  57. .append('<strong>' + Drupal.t('Select') + ':</strong> ')
  58. .append(allLink)
  59. .append(', ')
  60. .append(noneLink)
  61. .prependTo('#media-admin > div')
  62. // If the media item is clicked anywhere other than on the image itself
  63. // check the checkbox. For the record, JS thinks this is wonky.
  64. $('.media-item').bind('click', function (e) {
  65. if ($(e.target).is('img, a')) {
  66. return;
  67. }
  68. var checkbox = $(this).parent().find(':checkbox');
  69. if (checkbox.is(':checked')) {
  70. checkbox.attr('checked', false).change();
  71. } else {
  72. checkbox.attr('checked', true).change();
  73. }
  74. });
  75. // Add an extra class to selected thumbnails.
  76. $('.media-display-thumbnails :checkbox').each(function () {
  77. var checkbox = $(this);
  78. if (checkbox.is(':checked')) {
  79. $(checkbox.parents('li').find('.media-item')).addClass('selected');
  80. }
  81. checkbox.bind('change.media', function () {
  82. if (checkbox.is(':checked')) {
  83. $(checkbox.parents('li').find('.media-item')).addClass('selected');
  84. }
  85. else {
  86. $(checkbox.parents('li').find('.media-item')).removeClass('selected');
  87. }
  88. });
  89. });
  90. }
  91. // When any checkboxes are clicked on this form check to see if any are checked.
  92. // If any checkboxes are checked, show the edit options (@todo rename to edit-actions).
  93. $('#media-admin :checkbox').bind('change', function () {
  94. Drupal.behaviors.mediaAdmin.showOrHideEditOptions();
  95. });
  96. Drupal.behaviors.mediaAdmin.showOrHideEditOptions();
  97. },
  98. // Checks if any checkboxes on the form are checked, if so it will show the
  99. // edit-options panel.
  100. showOrHideEditOptions: function() {
  101. var fieldset = $('#edit-options');
  102. if (!$('#media-admin input[type=checkbox]:checked').size()) {
  103. fieldset.slideUp('fast');
  104. }
  105. else {
  106. fieldset.slideDown('fast');
  107. }
  108. }
  109. };
  110. /**
  111. * JavaScript for the Media types administrative form.
  112. */
  113. Drupal.behaviors.mediaTypesAdmin = {
  114. attach: function (context) {
  115. if ($('.form-item-match-type', context).length == 0) {
  116. return;
  117. }
  118. // Toggle the 'other' text field on Match type.
  119. if ($('.form-item-match-type input:checked').val() != 'other') {
  120. $('.form-item-match-type-other').hide();
  121. }
  122. $('.form-item-match-type input').change(function () {
  123. if ($(this).val() == 'other') {
  124. $('.form-item-match-type-other').slideDown('fast');
  125. }
  126. else {
  127. $('.form-item-match-type-other').slideUp('fast');
  128. }
  129. });
  130. }
  131. };
  132. })(jQuery);