colorbox_load.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. (function ($) {
  2. Drupal.behaviors.initColorboxLoad = {
  3. attach: function (context, settings) {
  4. if (!$.isFunction($.colorbox)) {
  5. return;
  6. }
  7. $.urlParams = function (url) {
  8. var p = {},
  9. e,
  10. a = /\+/g, // Regex for replacing addition symbol with a space
  11. r = /([^&=]+)=?([^&]*)/g,
  12. d = function (s) { return decodeURIComponent(s.replace(a, ' ')); },
  13. q = url.split('?');
  14. while (e = r.exec(q[1])) {
  15. e[1] = d(e[1]);
  16. e[2] = d(e[2]);
  17. switch (e[2].toLowerCase()) {
  18. case 'true':
  19. case 'yes':
  20. e[2] = true;
  21. break;
  22. case 'false':
  23. case 'no':
  24. e[2] = false;
  25. break;
  26. }
  27. if (e[1] == 'width') { e[1] = 'innerWidth'; }
  28. if (e[1] == 'height') { e[1] = 'innerHeight'; }
  29. p[e[1]] = e[2];
  30. }
  31. return p;
  32. };
  33. $('.colorbox-load', context)
  34. .once('init-colorbox-load', function () {
  35. var params = $.urlParams($(this).attr('href'));
  36. $(this).colorbox($.extend({}, settings.colorbox, params));
  37. });
  38. }
  39. };
  40. })(jQuery);