function parallax_bg_admin in Parallax Background 7
Callback function for admin setting.
1 string reference to 'parallax_bg_admin'
- parallax_bg_menu in ./
parallax_bg.module - Implementation of hook_menu().
File
- ./
parallax_bg.module, line 45 - Basic Module file.
Code
function parallax_bg_admin($form, &$form_state) {
// This module will not work if used in overlay paths such as
// admin/* , node/add etc if user has overlay access.
// Since the form builder is called after every AJAX request, we rebuild
// the form based on $form_state.
$settings = variable_get('parallax_bg_settings');
$num_elements = isset($settings['triggers_fieldset']) ? count($settings['triggers_fieldset']) + 1 : 1;
$form_state['triggers'] = $num_elements;
$options['helper'] = array(
'#markup' => t('Parallax Background activates a script that simulates the parallax effect using a different scroll speed on the background.'),
);
$options['triggers_fieldset'] = array(
'#tree' => TRUE,
'#title' => t("Target elements"),
// The prefix/suffix provide the div that we're replacing, named by
// #ajax['wrapper'] above.
'#prefix' => '<div id="triggers-div">',
'#suffix' => '</div>',
'#type' => 'vertical_tabs',
'#description' => t('Elements where Parallax Effect will be added'),
);
$i = 1;
$triggers = isset($settings['triggers_fieldset']) ? $settings['triggers_fieldset'] : array();
foreach ($triggers as $trigger) {
$options['triggers_fieldset']["trigger{$i}"] = array(
'#type' => 'fieldset',
'#title' => isset($trigger["element"]) ? $trigger["element"] : t('New element'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'triggers_fieldset',
);
$options['triggers_fieldset']["trigger{$i}"]["element"] = array(
'#type' => 'textfield',
'#default_value' => isset($trigger["element"]) ? $trigger["element"] : '',
'#title' => "Valid jQuery selector",
'#required' => TRUE,
);
$options['triggers_fieldset']["trigger{$i}"]["position"] = array(
'#type' => 'select',
'#title' => "Position",
'#default_value' => isset($trigger["position"]) ? $trigger["position"] : '50%',
'#options' => array(
'0' => t('Left'),
'50%' => t('Middle'),
'100%' => t('Right'),
),
);
$options['triggers_fieldset']["trigger{$i}"]["speed"] = array(
'#type' => 'select',
'#title' => "Relative speed",
'#default_value' => isset($trigger["speed"]) ? $trigger["speed"] : '0.1',
'#options' => array(
'0.1' => 0.1,
'0.2' => 0.2,
'0.3' => 0.3,
'0.4' => 0.4,
'0.5' => 0.5,
'0.6' => 0.6,
'0.7' => 0.7,
'0.8' => 0.8,
'0.9' => 0.9,
'1' => 1,
'1.25' => 1.25,
'1.5' => 1.5,
'1.75' => 1.75,
'2' => 2,
'2.5' => 2.5,
'3' => 3,
),
);
$options['triggers_fieldset']["trigger{$i}"]['delete'] = array(
'#type' => 'button',
'#value' => t('Delete element'),
'#name' => 'delete-' . $i,
'#submit' => array(
'parallax_bg_delete_submit',
),
);
$i++;
}
$options['triggers_fieldset']["trigger{$i}"] = array(
'#type' => 'fieldset',
'#title' => t('New element'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#group' => 'triggers_fieldset',
);
$options['triggers_fieldset']["trigger{$i}"]["element"] = array(
'#type' => 'textfield',
'#default_value' => NULL,
'#title' => "Valid jQuery selector",
'#description' => "A valid jQuery selector of the element of the DOM that holds the background. For example <strong>#top-content</strong>, <strong>body.one-page #super-banner</strong>.",
'#required' => FALSE,
);
$options['triggers_fieldset']["trigger{$i}"]["position"] = array(
'#type' => 'select',
'#title' => "Position",
'#description' => "Horizontal position of the element",
'#options' => array(
'0' => t('Left'),
'50%' => t('Middle'),
'100%' => t('Right'),
),
);
$options['triggers_fieldset']["trigger{$i}"]["speed"] = array(
'#type' => 'select',
'#title' => "Relative speed",
'#description' => "speed to move relative to vertical scroll. Example: 0.1 is one tenth the speed of scrolling, 2 is twice the speed of scrolling",
'#default_value' => '0.1',
'#options' => array(
'0.1' => 0.1,
'0.2' => 0.2,
'0.3' => 0.3,
'0.4' => 0.4,
'0.5' => 0.5,
'0.6' => 0.6,
'0.7' => 0.7,
'0.8' => 0.8,
'0.9' => 0.9,
'1' => 1,
'1.25' => 1.25,
'1.5' => 1.5,
'1.75' => 1.75,
'2' => 2,
'2.5' => 2.5,
'3' => 3,
),
);
$options['#tree'] = TRUE;
$form['parallax_bg_settings'] = $options;
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['#submit'][] = 'parallax_bg_admin_form_submit';
// Disable automatic defaults, which don't work with nested values.
return $form;
}