linkit.imce.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @file
  3. * IMCE integration for Linkit.
  4. */
  5. (function ($, Drupal, drupalSettings) {
  6. 'use strict';
  7. /**
  8. * @namespace
  9. *
  10. * Need to be in the global namespace, otherwise the IMCE window will not show
  11. * the 'select' button in the toolbar.
  12. */
  13. var linkitImce = window.linkitImce = {};
  14. /**
  15. * Drupal behavior to handle imce linkit integration.
  16. */
  17. Drupal.behaviors.linkitImce = {
  18. attach: function (context, settings) {
  19. var $link = $(context).find('.linkit-imce-open').once('linkit-imce-open');
  20. if ($link.length) {
  21. $link.bind('click', function (event) {
  22. event.preventDefault();
  23. window.open($(this).attr('href'), '', 'width=760,height=560,resizable=1');
  24. });
  25. }
  26. }
  27. };
  28. /**
  29. * Handler for imce sendto operation.
  30. */
  31. linkitImce.sendto = function (file, win) {
  32. var imce = win.imce;
  33. var items = imce.getSelection();
  34. if (imce.countSelection() > 1) {
  35. imce.setMessage(Drupal.t('You can only select one file.'));
  36. return;
  37. }
  38. var path = imce.getConf('root_url') + '/' + imce.getItemPath(items[0]);
  39. $('[data-drupal-selector="edit-attributes-href"]').val(path);
  40. win.close();
  41. };
  42. })(jQuery, Drupal, drupalSettings);