colorbox.js 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @file
  3. * Colorbox module init js.
  4. */
  5. (function ($) {
  6. Drupal.behaviors.initColorbox = {
  7. attach: function (context, settings) {
  8. if (!$.isFunction($.colorbox) || typeof settings.colorbox === 'undefined') {
  9. return;
  10. }
  11. if (settings.colorbox.mobiledetect && window.matchMedia) {
  12. // Disable Colorbox for small screens.
  13. var mq = window.matchMedia("(max-device-width: " + settings.colorbox.mobiledevicewidth + ")");
  14. if (mq.matches) {
  15. return;
  16. }
  17. }
  18. // Use "data-colorbox-gallery" if set otherwise use "rel".
  19. settings.colorbox.rel = function () {
  20. if ($(this).data('colorbox-gallery')) {
  21. return $(this).data('colorbox-gallery');
  22. }
  23. else {
  24. return $(this).attr('rel');
  25. }
  26. };
  27. $('.colorbox', context)
  28. .once('init-colorbox')
  29. .colorbox(settings.colorbox);
  30. $(context).bind('cbox_complete', function () {
  31. Drupal.attachBehaviors('#cboxLoadedContent');
  32. });
  33. }
  34. };
  35. })(jQuery);