Interim commit.
[yaffs-website] / web / modules / contrib / entity_browser / js / entity_browser.iframe.js
1 /**
2  * @file entity_browser.iframe.js
3  *
4  * Defines the behavior of the entity browser's iFrame display.
5  */
6
7 (function ($, Drupal, drupalSettings) {
8
9   'use strict';
10
11   /**
12    * Registers behaviours related to iFrame display.
13    */
14   Drupal.behaviors.entityBrowserIFrame = {
15     attach: function (context) {
16       $(context).find('.entity-browser-handle.entity-browser-iframe').once('iframe-click').on('click', Drupal.entityBrowserIFrame.linkClick);
17       $(context).find('.entity-browser-handle.entity-browser-iframe').once('iframe-auto-open').each(function () {
18         var uuid = $(this).attr('data-uuid');
19         if (drupalSettings.entity_browser.iframe[uuid].auto_open) {
20           $(this).click();
21         }
22       });
23     }
24   };
25
26   Drupal.entityBrowserIFrame = {};
27
28   /**
29    * Handles click on "Select entities" link.
30    */
31   Drupal.entityBrowserIFrame.linkClick = function () {
32     var uuid = $(this).attr('data-uuid');
33     var original_path = $(this).attr('data-original-path');
34     var iframeSettings = drupalSettings['entity_browser']['iframe'][uuid];
35     var iframe = $(
36       '<iframe />',
37       {
38         'src': iframeSettings['src'],
39         'width': '100%',
40         'height': iframeSettings['height'],
41         'data-uuid': uuid,
42         'data-original-path': original_path,
43         'name': 'entity_browser_iframe_' + iframeSettings['entity_browser_id'],
44         'id': 'entity_browser_iframe_' + iframeSettings['entity_browser_id']
45       }
46     );
47
48     var throbber = $('<div class="ajax-progress-fullscreen"></div>');
49     $(this).parent().css('width', iframeSettings['width']);
50
51     // Register callbacks.
52     if (drupalSettings.entity_browser.iframe[uuid].js_callbacks || false) {
53       Drupal.entityBrowser.registerJsCallbacks(this, drupalSettings.entity_browser.iframe[uuid].js_callbacks, 'entities-selected');
54     }
55
56     $(this).parent().append(throbber).append(iframe).trigger('entityBrowserIFrameAppend');
57     $(this).hide();
58   };
59
60 }(jQuery, Drupal, drupalSettings));