1464fdd968202268b4a23be8e1004e4d1152fc3f
[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       if (content === '') {
15         $(this).removeOnce('big-pipe');
16       } else {
17         var response = JSON.parse(content);
18
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 bigPipeProcessDocument(context) {
32     if (!context.querySelector('script[data-big-pipe-event="start"]')) {
33       return false;
34     }
35
36     $(context).find('script[data-big-pipe-replacement-for-placeholder-with-id]').once('big-pipe').each(bigPipeProcessPlaceholderReplacement);
37
38     if (context.querySelector('script[data-big-pipe-event="stop"]')) {
39       if (timeoutID) {
40         clearTimeout(timeoutID);
41       }
42       return true;
43     }
44
45     return false;
46   }
47
48   function bigPipeProcess() {
49     timeoutID = setTimeout(function () {
50       if (!bigPipeProcessDocument(document)) {
51         bigPipeProcess();
52       }
53     }, interval);
54   }
55
56   var interval = drupalSettings.bigPipeInterval || 50;
57
58   var timeoutID = void 0;
59
60   bigPipeProcess();
61
62   $(window).on('load', function () {
63     if (timeoutID) {
64       clearTimeout(timeoutID);
65     }
66     bigPipeProcessDocument(document);
67   });
68 })(jQuery, Drupal, drupalSettings);