colorbox_load.js 1.4 KB

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