Override Module for mobile users I'm using Manual Crop, which is not functional on a mobile phone (you can't drag the resize tool), so I'd like to prevent the init on a mobile device.

Any advice on how to override a module for smaller screen widths?

I could set the mobile user to not have access via Mobile Tools, but I'm not confident that module will work for D7, plus it may be overkill for my needs.

Thoughts? Is this even possible?

Kate H
I can think of two approaches.

The quick(er) dirty way:  

Hide it with CSS!

Problems:


I assume you're using seven or some other admin theme that you can't edit so all this will need to go in a module with drupal_add_js() or some other method for inserting JS.
After we determine if the visitor is on a touch device, we can't hide the element with simple jQuery because the element is dynamically inserted.


First, we'll need a way for JS to add CSS to the page. This function will let us do that:

function addCss(cssCode) {
  var styleElement = document.createElement("style");
  styleElement.type = "text/css";
  if (styleElement.styleSheet) {
    styleElement.styleSheet.cssText = cssCode;
  } else {
    styleElement.appendChild(document.createTextNode(cssCode));
  }
  document.getElementsByTagName("head")[0].appendChild(styleElement);
}


Then determine if the current visitor is on a touch device:

var is_touch_device = 'ontouchstart' in document.documentElement;


If so, add some CSS to page that hides the "Crop" button.

if (is_touch_device) {
  addCss('.manualcrop-style-button-holder {display: none;}');
}


The harder way:
Somehow determine if the current visitor is on a touch device via PHP. I don't have a foolproof method for this, but you can look into something like php-mobile-detect.

If you can determine that the visitor is on a touch device in PHP, you can return the manualcrop_croptool_process() function early. (Line 151 of manualcrop.helpers.inc). Of course, that will require filing an issue with module maintainer and providing a patch of those changes.