colorbox.js 956 B

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