PageSourceSearch

https://sag.cl/core/modules/contextual/js/contextual.js?v=9.3.11

js sag.cl collected 2026-10-02 03:57:32 UTC 5,201 bytes, 161 lines download raw bytes

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, _, Backbone, JSON, storage) {
9  var options = $.extend(drupalSettings.contextual, {
10    strings: {
11      open: Drupal.t('Open'),
12      close: Drupal.t('Close')
13    }
14  });
15  var cachedPermissionsHash = storage.getItem('Drupal.contextual.permissionsHash');
16  var permissionsHash = drupalSettings.user.permissionsHash;
17
18  if (cachedPermissionsHash !== permissionsHash) {
19    if (typeof permissionsHash === 'string') {
20      _.chain(storage).keys().each(function (key) {
21        if (key.substring(0, 18) === 'Drupal.contextual.') {
22          storage.removeItem(key);
23        }
24      });
25    }
26
27    storage.setItem('Drupal.contextual.permissionsHash', permissionsHash);
28  }
29
30  function adjustIfNestedAndOverlapping($contextual) {
31    var $contextuals = $contextual.parents('.contextual-region').eq(-1).find('.contextual');
32
33    if ($contextuals.length <= 1) {
34      return;
35    }
36
37    var firstTop = $contextuals.eq(0).offset().top;
38    var secondTop = $contextuals.eq(1).offset().top;
39
40    if (firstTop === secondTop) {
41      var $nestedContextual = $contextuals.eq(1);
42      var height = 0;
43      var $trigger = $nestedContextual.find('.trigger');
44      $trigger.removeClass('visually-hidden');
45      height = $nestedContextual.height();
46      $trigger.addClass('visually-hidden');
47      $nestedContextual.css({
48        top: $nestedContextual.position().top + height
49      });
50    }
51  }
52
53  function initContextual($contextual, html) {
54    var $region = $contextual.closest('.contextual-region');
55    var contextual = Drupal.contextual;
56    $contextual.html(html).addClass('contextual').prepend(Drupal.theme('contextualTrigger'));
57    var destination = "destination=".concat(Drupal.encodePath(Drupal.url(drupalSettings.path.currentPath)));
58    $contextual.find('.contextual-links a').each(function () {
59      var url = this.getAttribute('href');
60      var glue = url.indexOf('?') === -1 ? '?' : '&';
61      this.setAttribute('href', url + glue + destination);
62    });
63    var model = new contextual.StateModel({
64      title: $region.find('h2').eq(0).text().trim()
65    });
66    var viewOptions = $.extend({
67      el: $contextual,
68      model: model
69    }, options);
70    contextual.views.push({
71      visual: new contextual.VisualView(viewOptions),
72      aural: new contextual.AuralView(viewOptions),
73      keyboard: new contextual.KeyboardView(viewOptions)
74    });
75    contextual.regionViews.push(new contextual.RegionView($.extend({
76      el: $region,
77      model: model
78    }, options)));
79    contextual.collection.add(model);
80    $(document).trigger('drupalContextualLinkAdded', {
81      $el: $contextual,
82      $region: $region,
83      model: model
84    });
85    adjustIfNestedAndOverlapping($contextual);
86  }
87
88  Drupal.behaviors.contextual = {
89    attach: function attach(context) {
90      var $context = $(context);
91      var $placeholders = $(once('contextual-render', '[data-contextual-id]', context));
92
93      if ($placeholders.length === 0) {
94        return;
95      }
96
97      var ids = [];
98      $placeholders.each(function () {
99        ids.push({
100          id: $(this).attr('data-contextual-id'),
101          token: $(this).attr('data-contextual-token')
102        });
103      });
104      var uncachedIDs = [];
105      var uncachedTokens = [];
106      ids.forEach(function (contextualID) {
107        var html = storage.getItem("Drupal.contextual.".concat(contextualID.id));
108
109        if (html && html.length) {
110          window.setTimeout(function () {
111            initContextual($context.find("[data-contextual-id=\"".concat(contextualID.id, "\"]:empty")).eq(0), html);
112          });
113          return;
114        }
115
116        uncachedIDs.push(contextualID.id);
117        uncachedTokens.push(contextualID.token);
118      });
119
120      if (uncachedIDs.length > 0) {
121        $.ajax({
122          url: Drupal.url('contextual/render'),
123          type: 'POST',
124          data: {
125            'ids[]': uncachedIDs,
126            'tokens[]': uncachedTokens
127          },
128          dataType: 'json',
129          success: function success(results) {
130            _.each(results, function (html, contextualID) {
131              storage.setItem("Drupal.contextual.".concat(contextualID), html);
132
133              if (html.length > 0) {
134                $placeholders = $context.find("[data-contextual-id=\"".concat(contextualID, "\"]"));
135
136                for (var i = 0; i < $placeholders.length; i++) {
137                  initContextual($placeholders.eq(i), html);
138                }
139              }
140            });
141          }
142        });
143      }
144    }
145  };
146  Drupal.contextual = {
147    views: [],
148    regionViews: []
149  };
150  Drupal.contextual.collection = new Backbone.Collection([], {
151    model: Drupal.contextual.StateModel
152  });
153
154  Drupal.theme.contextualTrigger = function () {
155    return '<button class="trigger visually-hidden focusable" type="button"></button>';
156  };
157
158  $(document).on('drupalContextualLinkAdded', function (event, data) {
159    Drupal.ajax.bindAjaxLinks(data.$el[0]);
160  });
161})(jQuery, Drupal, drupalSettings, _, Backbone, window.JSON, window.sessionStorage);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.