Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / big_pipe / js / big_pipe.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal, drupalSettings) {
9   function bigPipeProcessPlaceholderReplacement(index, placeholderReplacement) {
10     var placeholderId = placeholderReplacement.getAttribute('data-big-pipe-replacement-for-placeholder-with-id');
11     var content = this.textContent.trim();
12
13     if (typeof drupalSettings.bigPipePlaceholderIds[placeholderId] !== 'undefined') {
14       var response = mapTextContentToAjaxResponse(content);
15
16       if (response === false) {
17         $(this).removeOnce('big-pipe');
18       } else {
19         var ajaxObject = Drupal.ajax({
20           url: '',
21           base: false,
22           element: false,
23           progress: false
24         });
25
26         ajaxObject.success(response, 'success');
27       }
28     }
29   }
30
31   function mapTextContentToAjaxResponse(content) {
32     if (content === '') {
33       return false;
34     }
35
36     try {
37       return JSON.parse(content);
38     } catch (e) {
39       return false;
40     }
41   }
42
43   function bigPipeProcessDocument(context) {
44     if (!context.querySelector('script[data-big-pipe-event="start"]')) {
45       return false;
46     }
47
48     $(context).find('script[data-big-pipe-replacement-for-placeholder-with-id]').once('big-pipe').each(bigPipeProcessPlaceholderReplacement);
49
50     if (context.querySelector('script[data-big-pipe-event="stop"]')) {
51       if (timeoutID) {
52         clearTimeout(timeoutID);
53       }
54       return true;
55     }
56
57     return false;
58   }
59
60   function bigPipeProcess() {
61     timeoutID = setTimeout(function () {
62       if (!bigPipeProcessDocument(document)) {
63         bigPipeProcess();
64       }
65     }, interval);
66   }
67
68   var interval = drupalSettings.bigPipeInterval || 50;
69
70   var timeoutID = void 0;
71
72   bigPipeProcess();
73
74   $(window).on('load', function () {
75     if (timeoutID) {
76       clearTimeout(timeoutID);
77     }
78     bigPipeProcessDocument(document);
79   });
80 })(jQuery, Drupal, drupalSettings);