colorbox_inline.js 2.1 KB

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