colorbox_inline.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @file
  3. * Colorbox module inline js.
  4. */
  5. (function ($) {
  6. Drupal.behaviors.initColorboxInline = {
  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. $.urlParam = function(name, url){
  19. if (name == 'fragment') {
  20. var results = new RegExp('(#[^&#]*)').exec(url);
  21. }
  22. else {
  23. var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
  24. }
  25. if (!results) { return ''; }
  26. return results[1] || '';
  27. };
  28. $('.colorbox-inline', context).once('init-colorbox-inline').colorbox({
  29. transition:settings.colorbox.transition,
  30. speed:settings.colorbox.speed,
  31. opacity:settings.colorbox.opacity,
  32. slideshow:settings.colorbox.slideshow,
  33. slideshowAuto:settings.colorbox.slideshowAuto,
  34. slideshowSpeed:settings.colorbox.slideshowSpeed,
  35. slideshowStart:settings.colorbox.slideshowStart,
  36. slideshowStop:settings.colorbox.slideshowStop,
  37. current:settings.colorbox.current,
  38. previous:settings.colorbox.previous,
  39. next:settings.colorbox.next,
  40. close:settings.colorbox.close,
  41. overlayClose:settings.colorbox.overlayClose,
  42. maxWidth:settings.colorbox.maxWidth,
  43. maxHeight:settings.colorbox.maxHeight,
  44. innerWidth:function(){
  45. return $.urlParam('width', $(this).attr('href'));
  46. },
  47. innerHeight:function(){
  48. return $.urlParam('height', $(this).attr('href'));
  49. },
  50. title:function(){
  51. return decodeURIComponent($.urlParam('title', $(this).attr('href')));
  52. },
  53. iframe:function(){
  54. return $.urlParam('iframe', $(this).attr('href'));
  55. },
  56. inline:function(){
  57. return $.urlParam('inline', $(this).attr('href'));
  58. },
  59. href:function(){
  60. return $.urlParam('fragment', $(this).attr('href'));
  61. }
  62. });
  63. }
  64. };
  65. })(jQuery);