/** * @file * Colorbox module init js. */ (function ($) { Drupal.behaviors.initColorbox = { attach: function (context, settings) { if (!$.isFunction($('a, area, input', context).colorbox) || typeof settings.colorbox === 'undefined') { return; } if (settings.colorbox.mobiledetect && window.matchMedia) { // Disable Colorbox for small screens. var mq = window.matchMedia("(max-device-width: " + settings.colorbox.mobiledevicewidth + ")"); if (mq.matches) { return; } } // Use "data-colorbox-gallery" if set otherwise use "rel". settings.colorbox.rel = function () { if ($(this).data('colorbox-gallery')) { return $(this).data('colorbox-gallery'); } else { return $(this).attr('rel'); } }; $('.colorbox', context) .once('init-colorbox').each(function(){ // Only images are supported for the "colorbox" class. // The "photo" setting forces the href attribute to be treated as an image. var extendParams = { photo: true }; // If a title attribute is supplied, sanitize it. var title = $(this).attr('title'); if (title) { extendParams.title = Drupal.checkPlain(title); } $(this).colorbox($.extend({}, settings.colorbox, extendParams)); }); $(context).bind('cbox_complete', function () { Drupal.attachBehaviors('#cboxLoadedContent'); }); } }; })(jQuery);