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.
Code Maturity & Comments to Reviewers
I started writing this code in Spring 2012 and it has been tested, adapted, simplified until now for use on a high traffic website. On that site it doesn't exist as a module but I have just written it out as one because I think it will be a nice contribution to the community as I couldn't find something similar.
Git checkout: git clone --recursive --branch master ferahl@git.drupal.org:sandbox/ferahl/1789654.git responsify
Sandbox Project Link: http://drupal.org/sandbox/ferahl/1789654
Core: 7.x
Comments
Comment #1
teknic commentedHello,
1. You need to delete the master branch and create a version specific branch in GIT (http://drupal.org/node/1127732)
2. You incorrectly named your README.TXT, it should be README.txt
3. Automated tools picked up errors you'll need to review first (http://ventral.org/pareview/httpgitdrupalorgsandboxferahl1789654git)
4. Your admin.inc file should be called responsify.admin.inc
Comment #2
webdorado commentedWe have tested the module and found some small bugs:
Comment #3
ferahl commentedThanks a lot for your time and helpful comments, I'll update it and get back to you.
Comment #4
ferahl commentedI have:
- changed the branch according to those instructions
- only a few warnings across all the files on http://ventral.org/pareview/httpgitdrupalorgsandboxferahl1789654git
- from breakpoint has to be less than to breakpoint
- added a .install file to remove the variables
git clone --recursive --branch 7.x-1.x ferahl@git.drupal.org:sandbox/ferahl/1789654.git responsify
Comment #5
ferahl commentedHi any news? Cheers
Comment #6
klausiYou need to set the status to "needs review" if you want to get a review, see http://drupal.org/node/532400
We are currently quite busy with all the project applications and I can only review projects with a review bonus. Please help me reviewing and I'll take a look at your project right away :-)
Comment #6.0
klausiadded comment on additional options in settings page
Comment #7
ferahl commentedThanks a lot I am going to see about reviewing something now.
Comment #8
ferahl commentedComment #9
dSero commentedHi,
I look like a very nice project that probably will help many drupal users.
Your automatic report is loaded with open issues. I recommend you to go over each of them and make sure it's clean before asking another review: http://ventral.org/pareview/httpgitdrupalorgsandboxferahl1789654git
Please notice several issues that you may consider to take care of:
1. README.txt file inludes lines with more than 80 characters
2. So in other files remarks
3. responsify.admin.inc: responsify_admin_form_remove_device: from security point of view it's better to perform if () return rather than canonical if
4. You have an hook_uninstall but no hook_install
5. responsify_preprocess_page: having so many JS files included on a single page from a single source may reduce the UX. Is it really unnecessary?
Best Regards,
Moshe
Comment #10
ferahl commented1. README.txt file inludes lines with more than 80 characters
2. So in other files remarks
- This is going a bit far isn't it? I have made sure code lines are short, but the fact that a few comments extend to 80 or 90 characters to improve readability - does this really matter?! I mean, we aren't using 800x600 res screens anymore right?
3. responsify.admin.inc: responsify_admin_form_remove_device: from security point of view it's better to perform if () return rather than canonical if
- Sorry I am not sure what you mean by this?
4. You have an hook_uninstall but no hook_install
- You are right, this might have been easier, but I have written the code so that it handles if the variables don't already exist. Changing this could just introduce regression bugs.
5. responsify_preprocess_page: having so many JS files included on a single page from a single source may reduce the UX. Is it really unnecessary?
- These are commented out and used for testing purposes.
Thanks for the review I appreciate it!
Comment #11
klausiClosing due to lack of activity. Feel free to reopen if you are still working on this application.
If you reopen this please keep in mind that we are currently quite busy with all the project applications and I can only review projects with a review bonus. Please help me reviewing and I'll take a look at your project right away :-)
Comment #11.0
klausiUpdated info to sync with info on project page