1

I'm using this jQuery for an (excellent) lightbox-like plugin called zoombox:

        $('a.zoombox').zoombox({...});

It takes a links in the form http://vimeo.com/15171582, parses the vimeo id (15171582) and pops up a lightbox which loads an iframe with this URL:

http://player.vimeo.com/video/15171582?autoplay=1&title=0&byline=0&portrait=0&wmode=transparent

How can I modify the jQuery so that, when viewed on a mobile browser,

  1. the lightbox doesn't launch, and
  2. the simple link gets converted to the iframe link?
Dan
  • 1,001
  • 2
  • 12
  • 24

1 Answers1

5

You can use this: http://detectmobilebrowsers.com/ to detect mobile devices.

Or detect window width like:

function isMobile() {
   if(window.innerWidth <= 600) {
     return true;
   } else {
     return false;
   }
}

And make it responsive like:

// keep original url
$('a.zoombox').each(function() {
  var url = $(this).attr('href');
  $(this).data('url',url);
});

// on load
doMagic();

// resizing
$(window).resize(function() {
  doMagic();
});

// lightbox?
function doMagic() {
  $('a.zoombox').each(function() {
    var url = $(this).data('url');
    $(this).attr('href',url);
  });
  if (!isMobile) {
    $('a.zoombox').zoombox({...}); // lightbox here
  }
}

// detect mobile
function isMobile() {
  if(window.innerWidth <= 600) {
    return true;
  } else {
    return false;
  }
}

NOT TESTED

edit: add doMagic call on load..

Marek Fajkus
  • 584
  • 4
  • 13