colorbox_load.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @file
  3. * Colorbox module load js.
  4. */
  5. (function ($) {
  6. Drupal.behaviors.initColorboxLoad = {
  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. $.urlParams = function (url) {
  19. var p = {},
  20. e,
  21. a = /\+/g, // Regex for replacing addition symbol with a space.
  22. r = /([^&=]+)=?([^&]*)/g,
  23. d = function (s) { return decodeURIComponent(s.replace(a, ' ')); },
  24. q = url.split('?');
  25. while (e = r.exec(q[1])) {
  26. e[1] = d(e[1]);
  27. e[2] = d(e[2]);
  28. switch (e[2].toLowerCase()) {
  29. case 'true':
  30. case 'yes':
  31. e[2] = true;
  32. break;
  33. case 'false':
  34. case 'no':
  35. e[2] = false;
  36. break;
  37. }
  38. if (e[1] == 'width') { e[1] = 'innerWidth'; }
  39. if (e[1] == 'height') { e[1] = 'innerHeight'; }
  40. p[e[1]] = e[2];
  41. }
  42. return p;
  43. };
  44. $('.colorbox-load', context)
  45. .once('init-colorbox-load', function () {
  46. var params = $.urlParams($(this).attr('href'));
  47. $(this).colorbox($.extend({}, settings.colorbox, params));
  48. });
  49. }
  50. };
  51. })(jQuery);