You are here

function viewport_preprocess_html in Viewport 7

Implements hook_preprocess_html().

File

./viewport.module, line 88
viewport module Allows to set a viewport metatag with custom settings for a selected set of pages.

Code

function viewport_preprocess_html(&$vars) {

  // Check if the viewport tag needs to be present.
  if (viewport_path_is_selected()) {
    $values_string = '';
    $values_string .= ($width = variable_get('viewport_width', FALSE)) ? "width={$width}, " : '';
    $values_string .= ($height = variable_get('viewport_height', FALSE)) ? "height={$height}, " : '';
    $values_string .= ($initial_scale = variable_get('viewport_initial_scale', FALSE)) ? "initial-scale={$initial_scale}, " : '';
    $values_string .= ($minimum_scale = variable_get('viewport_minimum_scale', FALSE)) ? "minimum-scale={$minimum_scale}, " : '';
    $values_string .= ($maximum_scale = variable_get('viewport_maximum_scale', FALSE)) ? "maximum-scale={$maximum_scale}, " : '';
    $values_string .= variable_get('viewport_user_scalable', TRUE) ? "user-scalable=yes" : 'user-scalable=no';
    $html_tag = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'name' => 'viewport',
        'content' => $values_string,
      ),
    );
    drupal_add_html_head($html_tag, 'viewport');
  }
}