You are here

function masonry_add_options_to_form in Masonry API 7.3

Same name and namespace in other branches
  1. 7.2 masonry.module \masonry_add_options_to_form()

Add Masonry options to an existing form.

Parameters

$form: A form array to add Masonry options to.

$default_values: An array of default form values.

File

./masonry.module, line 132
Provides an API for integrating the jQuery Masonry plugin with Drupal.

Code

function masonry_add_options_to_form(&$form, $default_values) {
  $form['masonry_column_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Column width'),
    '#description' => t("The width of each column, enter pixels, percentage, or string of css selector"),
    '#default_value' => $default_values['masonry_column_width'],
  );
  $form['masonry_column_width_units'] = array(
    '#type' => 'radios',
    '#title' => t('Column width units'),
    '#description' => t("The units to use for the column width."),
    '#options' => array(
      'px' => t("Pixels"),
      '%' => t("Percentage (of container's width)"),
      'css' => t("CSS selector (you must configure your css to set widths for .masonry-item)"),
    ),
    '#default_value' => $default_values['masonry_column_width_units'],
  );
  $form['masonry_gutter_width'] = array(
    '#type' => 'textfield',
    '#title' => t('Gutter width'),
    '#description' => t("The spacing between each column."),
    '#default_value' => $default_values['masonry_gutter_width'],
    '#size' => 4,
    '#maxlength' => 3,
    '#field_suffix' => t('px'),
  );
  $form['masonry_stamp_selector'] = array(
    '#type' => 'textfield',
    '#title' => t('Stamp Selector'),
    '#description' => t("Specifies which elements are stamped within the layout using css selector"),
    '#default_value' => $default_values['masonry_stamp_selector'],
  );
  $form['masonry_resizable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Resizable'),
    '#description' => t("Automatically rearrange items when the container is resized."),
    '#default_value' => $default_values['masonry_resizable'],
  );
  $form['masonry_animated'] = array(
    '#type' => 'checkbox',
    '#title' => t('Animated'),
    '#description' => t("Animate item rearrangements."),
    '#default_value' => $default_values['masonry_animated'],
    '#states' => array(
      'visible' => array(
        'input.form-checkbox[name$="[masonry_resizable]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['masonry_animation_duration'] = array(
    '#type' => 'textfield',
    '#title' => t('Animation duration'),
    '#description' => t("The duration of animations (1000 ms = 1 sec)."),
    '#default_value' => $default_values['masonry_animation_duration'],
    '#size' => 5,
    '#maxlength' => 4,
    '#field_suffix' => t('ms'),
    '#states' => array(
      'visible' => array(
        'input.form-checkbox[name$="[masonry_resizable]"]' => array(
          'checked' => TRUE,
        ),
        'input.form-checkbox[name$="[masonry_animated]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['masonry_fit_width'] = array(
    '#type' => 'checkbox',
    '#title' => t('Fit width'),
    '#description' => t("Sets the width of the container to the nearest column. Ideal for centering Masonry layouts. See the <a href='http://masonry.desandro.com/demos/centered.html'>'Centered' demo</a> for more information."),
    '#default_value' => $default_values['masonry_fit_width'],
  );
  $form['masonry_rtl'] = array(
    '#type' => 'checkbox',
    '#title' => t('RTL layout'),
    '#description' => t("Display items from right-to-left."),
    '#default_value' => $default_values['masonry_rtl'],
  );
  $form['masonry_images_first'] = array(
    '#type' => 'checkbox',
    '#title' => t('Load images first'),
    '#description' => t("Load all images first before triggering Masonry."),
    '#default_value' => $default_values['masonry_images_first'],
  );
  $form['masonry_percent_position'] = array(
    '#type' => 'checkbox',
    '#title' => t('Percent position'),
    '#description' => t("Sets item positions in percent values, rather than pixel values. Checking this will works well with percent-width items, as items will not transition their position on resize. See the <a href='http://masonry.desandro.com/options.html#percentposition'>masonry doc</a> for more information."),
    '#default_value' => $default_values['masonry_percent_position'],
  );

  // Allow other modules to alter the form
  drupal_alter('masonry_options_form', $form, $default_values);
}