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