tipsy.admin.inc

  1. cis7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  2. cle7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  3. ecd7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  4. elmsmedia7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  5. harmony7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  6. icor7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  7. meedjum_blog7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc
  8. mooc7 sites/all/modules/ulmus/tipsy/tipsy.admin.inc

Functions

Namesort descending Description
theme_tipsy_custom_selectors_form Theme the table form for tipsy rules
tipsy_admin Implementation of tipsy admin form
tipsy_admin_callback AJAX callback to render the tipsy rules form
tipsy_admin_submit Implementation of form submit function for the admin form
tipsy_admin_validate Implementation of hook_validate for admin form
tipsy_custom_selector_form Implementation of a single tipsy rule form
tipsy_options_form Implementation of form function for the tooltip options

File

sites/all/modules/ulmus/tipsy/tipsy.admin.inc
View source
  1. <?php
  2. /**
  3. * Implementation of tipsy admin form
  4. */
  5. function tipsy_admin($form, &$form_state) {
  6. $settings = _tipsy_get_settings();
  7. $form = array();
  8. $form['#attached']['js'][] = drupal_get_path('module', 'tipsy') . '/javascripts/tipsy.admin.js';
  9. $form['#attached']['css'][] = drupal_get_path('module', 'tipsy') . '/stylesheets/tipsy.admin.css';
  10. $form['drupal_forms'] = array(
  11. '#type' => 'fieldset',
  12. '#title' => t('Drupal forms general settings'),
  13. '#weight' => -5,
  14. '#collapsible' => TRUE,
  15. '#collapsed' => FALSE,
  16. );
  17. $form['drupal_forms']['forms'] = array(
  18. '#type' => 'checkbox',
  19. '#default_value' => $settings['drupal_forms']['forms'],
  20. '#title' => t('Apply Tipsy for form items descriptions on all Drupal forms.'),
  21. '#description' => t('This will automatically enable Tipsy tooltips to form elements descriptions.'),
  22. );
  23. $form['drupal_forms']['wrapper'] = array(
  24. '#tree' => TRUE,
  25. '#weight' => 0,
  26. '#prefix' => '<div class="clear-block" id="tipsy-drupal-forms-wrapper">',
  27. '#suffix' => '</div>',
  28. );
  29. $form['drupal_forms']['wrapper']['options'] = tipsy_options_form($settings['drupal_forms'], true);
  30. $form['custom_selectors'] = array(
  31. '#type' => 'fieldset',
  32. '#title' => t('Custom selectors'),
  33. '#weight' => -4,
  34. '#collapsible' => TRUE,
  35. '#collapsed' => FALSE,
  36. );
  37. $form['custom_selectors']['rules'] = array(
  38. '#tree' => TRUE,
  39. '#prefix' => '<div id="tipsy-custom-selectors">',
  40. '#suffix' => '</div>',
  41. '#theme' => 'tipsy_custom_selectors_form',
  42. );
  43. $form['custom_selectors']['rules_submit'] = array(
  44. '#type' => 'button',
  45. '#value' => t('Add another rule'),
  46. '#submit' => array('tipsy_custom_selectors_add'), // If no javascript action.
  47. '#ajax' => array(
  48. 'callback' => 'tipsy_admin_callback',
  49. 'wrapper' => 'tipsy-custom-selectors',
  50. 'method' => 'replace',
  51. 'effect' => 'fade',
  52. ),
  53. );
  54. if ($settings['custom_selectors']) {
  55. foreach ($settings['custom_selectors'] as $delta => $options) {
  56. $form['custom_selectors']['rules'][$delta] = tipsy_custom_selector_form($options);
  57. }
  58. }
  59. else {
  60. $form['custom_selectors']['rules'][0] = tipsy_custom_selector_form();
  61. }
  62. // The "Add another rule" button was clicked.
  63. if (isset($form_state['values']['rules_submit'])) {
  64. $form['custom_selectors']['rules'][] = tipsy_custom_selector_form();
  65. }
  66. $form['buttons']['submit'] = array(
  67. '#type' => 'submit',
  68. '#value' => t('Save configuration'),
  69. );
  70. $form['#theme'] = 'system_settings_form';
  71. $form['#submit'][] = 'tipsy_admin_submit';
  72. return $form;
  73. }
  74. /**
  75. * AJAX callback to render the tipsy rules form
  76. */
  77. function tipsy_admin_callback($form, $form_state) {
  78. return $form['custom_selectors']['rules'];
  79. }
  80. /**
  81. * Implementation of form function for the tooltip options
  82. */
  83. function tipsy_options_form($settings = FALSE, $drupal_forms = FALSE) {
  84. if ($settings == FALSE) {
  85. $settings = _tipsy_get_settings(true);
  86. }
  87. $form = array();
  88. $form['fade'] = array(
  89. '#type' => 'checkbox',
  90. '#default_value' => $settings['options']['fade'],
  91. '#description' => t('This will make the tooltip fade.'),
  92. '#title' => t('Make Tipsy tooltips fade.'),
  93. '#weight' => 0,
  94. '#prefix' => '<div class="tipsy-selector-options clear-block">',
  95. );
  96. $form['gravity'] = array(
  97. '#type' => 'select',
  98. '#default_value' => $settings['options']['gravity'],
  99. '#title' => t('Tipsy arrow position'),
  100. '#description' => t('Specify the position of the tooltip when it appears.'),
  101. '#weight' => 2,
  102. '#options' => array(
  103. 'nw' => t('North west'),
  104. 'n' => t('North'),
  105. 'ne' => t('North east'),
  106. 'w' => t('West'),
  107. 'e' => t('East'),
  108. 'sw' => t('South west'),
  109. 's' => t('South'),
  110. 'se' => t('South east'),
  111. 'autoNS' => t('Auto detect North/South'),
  112. 'autoWE' => t('Auto detect West/East'),
  113. ),
  114. );
  115. $form['delayIn'] = array(
  116. '#type' => 'textfield',
  117. '#default_value' => $settings['options']['delayIn'],
  118. '#title' => t('Delay when appearing'),
  119. '#description' => t('Amount of milliseconds for the tooltip to appear.'),
  120. '#size' => 5,
  121. '#maxlength' => 5,
  122. '#weight' => 3,
  123. );
  124. $form['delayOut'] = array(
  125. '#type' => 'textfield',
  126. '#default_value' => $settings['options']['delayOut'],
  127. '#title' => t('Delay when disappearing'),
  128. '#description' => t('Amount of milliseconds for the tooltip to disappear.'),
  129. '#size' => 5,
  130. '#maxlength' => 5,
  131. '#weight' => 4,
  132. );
  133. $form['trigger'] = array(
  134. '#type' => 'select',
  135. '#default_value' => $settings['options']['trigger'],
  136. '#description' => t('Specify what action will make the tooltip appear.'),
  137. '#title' => t('Tipsy trigger'),
  138. '#weight' => 5,
  139. '#options' => array(
  140. 'focus' => t('Focus'),
  141. 'hover' => t('Hover'),
  142. ),
  143. );
  144. $form['opacity'] = array(
  145. '#type' => 'textfield',
  146. '#default_value' => $settings['options']['opacity'],
  147. '#title' => t('Tooltip opacity'),
  148. '#description' => t('A value between 0 and 1.'),
  149. '#size' => 5,
  150. '#maxlength' => 4,
  151. '#weight' => 6,
  152. );
  153. $form['offset'] = array(
  154. '#type' => 'textfield',
  155. '#default_value' => $settings['options']['offset'],
  156. '#title' => t('Tooltip offset'),
  157. '#description' => t('Number of pixels in which the tooltip will distance from the element.'),
  158. '#size' => 5,
  159. '#maxlength' => 5,
  160. '#weight' => 7,
  161. );
  162. if ($drupal_forms == false) {
  163. $form['html'] = array(
  164. '#type' => 'checkbox',
  165. '#default_value' => $settings['options']['html'],
  166. '#description' => t('This will let HTML code be parsed inside the tooltip.'),
  167. '#title' => t('Allow HTML in tooltip content.'),
  168. '#weight' => 1,
  169. );
  170. $form['tooltip_content'] = array(
  171. '#type' => 'fieldset',
  172. '#title' => t('Tooltip content'),
  173. '#weight' => 9,
  174. );
  175. $form['tooltip_content']['source'] = array(
  176. '#type' => 'radios',
  177. '#title' => t('Source'),
  178. '#default_value' => $settings['options']['tooltip_content']['source'],
  179. '#options' => array('attribute' => t('HTML attribute'), 'child' => t('Child element')),
  180. );
  181. $form['tooltip_content']['selector'] = array(
  182. '#type' => 'textarea',
  183. '#title' => t('Selector'),
  184. '#default_value' => $settings['options']['tooltip_content']['selector'],
  185. '#description' => t("The name of the HTML attribute or a selector pointing to the child element (e.g: .content). <br /> Refer to the module's README.txt for more information."),
  186. '#rows' => 1,
  187. '#maxlength' => 400,
  188. );
  189. }
  190. $form['closure'] = array(
  191. '#weight' => 10,
  192. '#suffix' => '</div>',
  193. );
  194. return $form;
  195. }
  196. /**
  197. * Implementation of a single tipsy rule form
  198. */
  199. function tipsy_custom_selector_form($options = false) {
  200. $form = array();
  201. $form['#tree'] = TRUE;
  202. $form['selector'] = array(
  203. '#type' => 'textarea',
  204. '#weight' => 1,
  205. '#rows' => 2,
  206. '#default_value' => $options['selector'],
  207. );
  208. $form['options'] = tipsy_options_form($options);
  209. return $form;
  210. }
  211. /**
  212. * Theme the table form for tipsy rules
  213. */
  214. function theme_tipsy_custom_selectors_form($variables) {
  215. $form = $variables['form'];
  216. $rows = array();
  217. $headers = array(t('Selectors'), t('Options'));
  218. foreach (element_children($form) as $key) {
  219. $row = array(
  220. 'data' => array(
  221. array('data' => drupal_render($form[$key]['selector'])),
  222. array('data' => drupal_render($form[$key]['options'])),
  223. ),
  224. );
  225. $rows[] = $row;
  226. }
  227. $output = theme('table', array('header' => $headers, 'rows' => $rows));
  228. $output .= drupal_render_children($form);
  229. return $output;
  230. }
  231. /**
  232. * Implementation of hook_validate for admin form
  233. */
  234. function tipsy_admin_validate($form, &$form_values) {
  235. $drupal_forms = $form_values['values']['wrapper'];
  236. if ($form_values['values']['forms'] != 0) {
  237. if (!is_numeric($drupal_forms['options']['delayIn']) || $drupal_forms['options']['delayIn'] == '') {
  238. form_set_error('wrapper][options][delayIn', t('Invalid value'));
  239. }
  240. if (!is_numeric($drupal_forms['options']['delayOut']) || $drupal_forms['options']['delayOut'] == '') {
  241. form_set_error('wrapper][options][delayOut', t('Invalid value'));
  242. }
  243. if (!is_numeric($drupal_forms['options']['opacity']) || $drupal_forms['options']['opacity'] == '') {
  244. form_set_error('wrapper][options][opacity', t('Invalid value'));
  245. }
  246. if (!is_numeric($drupal_forms['options']['offset']) || $drupal_forms['options']['offset'] == '') {
  247. form_set_error('wrapper][options][offset', t('Invalid value'));
  248. }
  249. }
  250. foreach ($form_values['values']['rules'] as $delta => $rule) {
  251. if (trim($rule['selector']) != '') {
  252. if (!is_numeric($rule['options']['delayIn']) || $rule['options']['delayIn'] == '') {
  253. form_set_error('rules][' . $delta . '][options][delayIn', t('Invalid value'));
  254. }
  255. if (!is_numeric($rule['options']['delayOut']) || $rule['options']['delayOut'] == '') {
  256. form_set_error('rules][' . $delta . '][options][delayOut', t('Invalid value'));
  257. }
  258. if (!is_numeric($rule['options']['opacity']) || $rule['options']['opacity'] == '') {
  259. form_set_error('rules][' . $delta . '][options][opacity', t('Invalid value'));
  260. }
  261. if (!is_numeric($rule['options']['offset']) || $rule['options']['offset'] == '') {
  262. form_set_error('rules][' . $delta . '][options][offset', t('Invalid value'));
  263. }
  264. if (trim($rule['options']['tooltip_content']['selector']) == '') {
  265. form_set_error('rules][' . $delta . '][options][tooltip_content][selector', t("Invalid value set for title. Use <em>title</em> if you don't know what you are doing"));
  266. }
  267. }
  268. }
  269. }
  270. /**
  271. * Implementation of form submit function for the admin form
  272. */
  273. function tipsy_admin_submit($form, &$form_values) {
  274. $settings = array();
  275. $drupal_forms = $form_values['values']['wrapper'];
  276. $settings['drupal_forms'] = array(
  277. 'forms' => $form_values['values']['forms'],
  278. 'options' => array(
  279. 'fade' => $drupal_forms['options']['fade'],
  280. 'gravity' => $drupal_forms['options']['gravity'],
  281. 'delayIn' => trim($drupal_forms['options']['delayIn']),
  282. 'delayOut' => trim($drupal_forms['options']['delayOut']),
  283. 'trigger' => $drupal_forms['options']['trigger'],
  284. 'opacity' => trim($drupal_forms['options']['opacity']),
  285. 'offset' => trim($drupal_forms['options']['offset']),
  286. ),
  287. );
  288. foreach ($form_values['values']['rules'] as $delta => $rule) {
  289. if (trim($rule['selector']) != '') {
  290. $settings['custom_selectors'][] = array(
  291. 'selector' => trim($rule['selector']),
  292. 'options' => array(
  293. 'fade' => $rule['options']['fade'],
  294. 'gravity' => $rule['options']['gravity'],
  295. 'trigger' => $rule['options']['trigger'],
  296. 'delayIn' => trim($rule['options']['delayIn']),
  297. 'delayOut' => trim($rule['options']['delayOut']),
  298. 'opacity' => trim($rule['options']['opacity']),
  299. 'offset' => trim($rule['options']['offset']),
  300. 'html' => $rule['options']['html'],
  301. 'tooltip_content' => array(
  302. 'source' => $rule['options']['tooltip_content']['source'],
  303. 'selector' => trim($rule['options']['tooltip_content']['selector']),
  304. ),
  305. ),
  306. );
  307. }
  308. }
  309. variable_set('tipsy', $settings);
  310. drupal_set_message(t('Configuration saved'));
  311. }