Experimental project

This is a sandbox project, which contains experimental code for developer use only.

About

Responsify allows you to set up devices which have FROM and TO pixel breakpoints. You can use these devices in drupal_add_js calls to load in different JavaScript depending on whether the user is in the device bounds you specified. This allows you to for example load in different libraries if the user is on a mobile device width.

How to install and configure

Activate the module, setup permissions, and then go to admin/settings/responsify to set up your devices.

How to use

Let's say you set up a device in the admin settings called "mobile" with a from breakpoint of "0" and a to breakpoint of "480" and you had a mymobilestuff.js which you only wanted to load in on mobile device widths. You would add your JS file like this:

drupal_add_js(path_to_theme() . '/js/mymobilestuff.js?device=mobile');

If you want to know when a new device has loaded in listen to a custom deviceload event on the html element. This is useful because there is no automatic way to "unload" JavaScript. For the sake of older jQuery I will demonstrate with the bind handler:

$('html').bind('deviceload', function(ev, device_name, breakpoint_from, breakpoint_to) {...});

The settings page also gives the option to dynamically load in new JavaScript if the browser window width changes.

Important: Remember to use Drupal Behaviors in your JS files that are loaded with Responsify as they are not guaranteed to be loaded before the document ready event.

Performance Tips

It is best to load the bulk of your scripts normally to avoid visual delays. By default Responsify will load your scripts sequentially - that is to say it will wait for a script to return from the server before loading the next. If your script however does not depend on others that are loaded with the device arg then you can add the argument async=true to your drupal_add_js call and these will load without waiting for each other to complete.

Project information

  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Project categories: Developer tools
  • Created by ferahl on , updated