diff --git a/modal_forms.admin.inc b/modal_forms.admin.inc index 77dd7f1..bf40c58 100644 --- a/modal_forms.admin.inc +++ b/modal_forms.admin.inc @@ -224,6 +224,36 @@ function modal_forms_admin_settings() { '#default_value' => variable_get('modal_forms_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*"), '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), ); - + + // Mobile detection capabilities + $can_detect_mobile = function_exists('browscap_get_browser'); + $can_detect_mobile_tablet = function_exists('mobile_detect_get_object'); + + // Descriptions for the mobile detection form elements, conditionally selected + // based on installed modules and what they support. + $descriptions = array( + t('You need to install the Browscap or Mobile Detect module to enable mobile detection. Use Mobile Detect if you would like a tablet-specific option below.', array('@browscap' => 'http://drupal.org/project/browscap/', '@mobile_detect' => 'http://drupal.org/project/mobile_detect')), + t('You need to install the Mobile Detect module to enable tablet specific detection.', array('@mobile_detect' => 'http://drupal.org/project/mobile_detect')), + 'This will disable Modal forms for mobile devices (including tablets).', + 'This will disable Modal forms specifically for mobile devices. Tablets are controlled via a separate option below.', + 'This will disable Modal forms specifically for tablet devices. Other mobile devices are controlled through the mobile option above.', + ); + + // Mobile detection settings + $form['modal_forms_advanced_settings']['modal_forms_mobile_deactivate'] = array( + '#type' => 'checkbox', + '#title' => t('Disable modal forms for mobile devices.'), + '#description' => (($can_detect_mobile_tablet) ? $descriptions[3] : (($can_detect_mobile) ? $descriptions[2] : $descriptions[0])), + '#default_value' => variable_get('modal_forms_mobile_deactivate', 0), + '#disabled' => (!$can_detect_mobile && !$can_detect_mobile_tablet) ? TRUE : FALSE, + ); + $form['modal_forms_advanced_settings']['modal_forms_tablet_deactivate'] = array( + '#type' => 'checkbox', + '#title' => t('Disable modal forms for tablets.'), + '#description' => ($can_detect_mobile_tablet) ? $descriptions[4] : $descriptions[1], + '#default_value' => variable_get('modal_forms_tablet_deactivate', 0), + '#disabled' => !$can_detect_mobile_tablet, + ); + return system_settings_form($form); } diff --git a/modal_forms.module b/modal_forms.module index 8c4645d..f39ebee 100644 --- a/modal_forms.module +++ b/modal_forms.module @@ -174,7 +174,29 @@ function _modal_forms_active() { $page_match = $page_match || drupal_match_path($_GET['q'], $modal_forms_pages); } $page_match = variable_get('modal_forms_visibility', 0) == 0 ? !$page_match : $page_match; - + + // Deactivate Modal forms for mobile devices if set/configured + if (variable_get('modal_forms_mobile_deactivate', 0) || variable_get('modal_forms_tablet_deactivate', 0)) { + + if (function_exists('mobile_detect_get_object') && $detect = mobile_detect_get_object()) { + + if (variable_get('modal_forms_tablet_deactivate', 0) && $detect->isTablet()) { + return FALSE; + } + elseif ($detect->isMobile()) { + return FALSE; + } + } + elseif (function_exists('browscap_get_browser') && $browscap = browscap_get_browser()) { + + // Browscap's exact return format for ismobiledevice varies between + // versions... so we use a lenient filter_var to check it. + if (filter_var($browscap['ismobiledevice'], FILTER_VALIDATE_BOOLEAN) == TRUE) { + return FALSE; + } + } + } + return $page_match; }