PageSourceSearch

https://aytocdo.es/modules/contrib/colorbox/js/colorbox.js?v=10.3.10

js aytocdo.es collected 2026-10-09 05:05:35 UTC 3,949 bytes, 126 lines download raw bytes

1/**
2 * @file
3 * Colorbox JS.
4 */
5
6(function ($, Drupal, drupalSettings, once) {
7
8  'use strict';
9
10  Drupal.behaviors.initColorbox = {
11    attach: function (context, settings) {
12      if (typeof $.colorbox !== 'function' || typeof settings.colorbox === 'undefined') {
13        return;
14      }
15
16      // The colorbox library uses jQuery.isFunction().
17      // This function was removed in jQuery 3.3.0.
18      // This is a workaround to avoid fixing the library.
19      if (!$.isFunction) {
20        $.isFunction = function (obj) {
21          return typeof obj === 'function' || false;
22        };
23      }
24
25      if (settings.colorbox.mobiledetect && window.matchMedia) {
26        // Disable Colorbox for small screens.
27        var mq = window.matchMedia('(max-device-width: ' + settings.colorbox.mobiledevicewidth + ')');
28        if (mq.matches) {
29          $.colorbox.remove();
30          return;
31        }
32      }
33
34      settings.colorbox.rel = function () {
35        return $(this).data('colorbox-gallery');
36      };
37
38      settings.colorbox.html = function () {
39        var $modalContent = $(this).find('> .modal-content');
40        return $modalContent.length ? $(this).find('> .modal-content').children().clone() : false;
41      };
42
43      $(once('init-colorbox', '.colorbox', context))
44        .each(function() {
45        // Only images are supported for the "colorbox" class.
46        // The "photo" setting forces the href attribute to be treated as an image.
47        var extendParams = {
48          photo: true
49        };
50        // If a title attribute is supplied, sanitize it.
51        var title = $(this).attr('title');
52        if (title) {
53          extendParams.title = Drupal.colorbox.sanitizeMarkup(title);
54        }
55        $(this).colorbox($.extend({}, settings.colorbox, extendParams));
56      });
57
58      $('.colorbox', context).colorbox({
59        onComplete: function (e) {
60          var focus = $('#cboxContent').find('#cboxPrevious').css('display') !== 'none' ? $('#cboxContent').find('#cboxPrevious') : $('#cboxContent').find('#cboxClose');
61          focus.focus();
62
63          $('#cboxContent').on('keydown', function (e) {
64            var keyCode = e.keyCode || e.which;
65            var firstElement = $('#cboxContent').find('#cboxPrevious').last().is(':focus');
66            var lastElement = $('#cboxContent').find('#cboxClose').first().is(':focus');
67            if (keyCode === 9 && !e.shiftKey && lastElement) {
68              e.preventDefault();
69              $('#cboxContent').find('#cboxPrevious').first().focus();
70            }
71            else if (keyCode === 9 && e.shiftKey && firstElement) {
72              e.preventDefault();
73              $('#cboxContent').find('#cboxClose').first().focus();
74            }
75          });
76        }
77      });
78    }
79  };
80
81  // Create colorbox namespace if it doesn't exist.
82  if (!Drupal.hasOwnProperty('colorbox')) {
83    Drupal.colorbox = {};
84  }
85
86  /**
87   * Global function to allow sanitizing captions and control strings.
88   *
89   * @param markup
90   *   String containing potential markup.
91   * @return @string
92   *  Sanitized string with potentially dangerous markup removed.
93   */
94  Drupal.colorbox.sanitizeMarkup = function(markup) {
95    // If DOMPurify installed, allow some HTML. Otherwise, treat as plain text.
96    if (typeof DOMPurify !== 'undefined') {
97      var purifyConfig = {
98        ALLOWED_TAGS: [
99          'a',
100          'b',
101          'strong',
102          'i',
103          'em',
104          'u',
105          'cite',
106          'code',
107          'br'
108        ],
109        ALLOWED_ATTR: [
110          'href',
111          'hreflang',
112          'title',
113          'target'
114        ]
115      }
116      if (drupalSettings.hasOwnProperty('dompurify_custom_config')) {
117        purifyConfig = drupalSettings.dompurify_custom_config;
118      }
119      return DOMPurify.sanitize(markup, purifyConfig);
120    }
121    else {
122      return Drupal.checkPlain(markup);
123    }
124  }
125
126})(jQuery, Drupal, drupalSettings, once);

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.