You are here

API.txt in Menu Minipanels 6

Same filename and directory in other branches
  1. 7.2 API.txt
  2. 7 API.txt

Custom style(s) for Menu_MiniPanels.

File

API.txt
View source
  1. Menu_MiniPanels API
  2. -------------------
  3. The following APIs are available:
  4. * Override menu display defaults (PHP).
  5. * Add custom styles (PHP & JS).
  6. * Custom callbacks (JS).
  7. Override menu display defaults
  8. ------------------------------
  9. By implementing hook_menu_minipanels_defaults_alter() a module may override
  10. the default display settings that are given to new menus.
  11. Add custom styles
  12. -----------------
  13. By implementing hook_menu_minipanels_style() and hook_menu_minipanels_styles()
  14. a module can add new display styles. Please note that due to JS dependencies,
  15. the custom styles must be loaded *after* the core qtip and menu_minipansls.js
  16. files, so this is the easiest way of handling it.
  17. There are three steps necessary in order to make this work:
  18. Step 1: Add a JS file called e.g. "mymodule_style.js" with the desired style
  19. settings.
  20. /**
  21. * @file
  22. * Custom style(s) for Menu_MiniPanels.
  23. */
  24. // Last part is the internal name of the style.
  25. jQuery.fn.qtip.styles.mystyle = {
  26. background: '#A2D959',
  27. border: {
  28. color: '#A2D959',
  29. radius: 5,
  30. width: 7,
  31. },
  32. color: 'black',
  33. };
  34. Part 2: List the new styles, to be added to mymodule.module:
  35. /**
  36. * Implements hook_menu_minipanels_styles().
  37. */
  38. function mymodule_menu_minipanels_styles() {
  39. $styles = array(
  40. 'mystyle' => t('My new style'),
  41. );
  42. return $styles;
  43. }
  44. ?>
  45. Step 3: Tell Drupal to load the new JS file, to be added to mymodule.module:
  46. /**
  47. * Implements hook_menu_minipanels_style().
  48. */
  49. function mymodule_menu_minipanels_style($menu_config) {
  50. // Load the custom styles in the footer, make sure this is loaded after the
  51. // Menu_MiniPanels files.
  52. drupal_add_js(drupal_get_path('module', 'mymodule_styles') . '/menu_minipanels_styles.js', 'module', 'footer', FALSE, TRUE, FALSE);
  53. }
  54. ?>
  55. Note:
  56. * Because the qTips script is loaded in the footer scope, the custom styles
  57. should also be added to the footer scope. If, due to module weighting, the
  58. custom styles JS loads after the qTip JS file it may be necessary to move the
  59. JS file to the theme layer.
  60. To help deciding on what settings to use, the qTips defaults are:
  61. {
  62. background: 'white',
  63. color: '#111',
  64. overflow: 'hidden',
  65. textAlign: 'left',
  66. width: {
  67. min: 0,
  68. max: 250,
  69. },
  70. padding: '5px 9px',
  71. border: {
  72. width: 3,
  73. radius: 0,
  74. color: '#d3d3d3',
  75. },
  76. tip: {
  77. corner: topLeft,
  78. color: false,
  79. size: { x: 12, x: 12 },
  80. opacity: 1,
  81. },
  82. title: {
  83. background: '#e1e1e1',
  84. fontWeight: 'bold',
  85. padding: '7px 12px',
  86. },
  87. button: {
  88. cursor: 'pointer'
  89. },
  90. classes: {
  91. target: '',
  92. tip: 'qtip-tip',
  93. title: 'qtip-title',
  94. button: 'qtip-button',
  95. content: 'qtip-content',
  96. active: 'qtip-active',
  97. }
  98. }
  99. Custom JavaScript callbacks
  100. ---------------------------
  101. All of qTips' callbacks are available to JavaScript via the
  102. MenuMiniPanels.setCallback() function, e.g.:
  103. MenuMiniPanels.setCallback('onShow', function(qTip, event, content) {
  104. alert('onShow');
  105. });
  106. The following callbacks are available:
  107. MenuMiniPanels.setCallback('beforeRender', function(qTip, event, content) {}
  108. MenuMiniPanels.setCallback('onRender', function(qTip, event, content) {}
  109. MenuMiniPanels.setCallback('beforePositionUpdate', function(qTip, event, content) {}
  110. MenuMiniPanels.setCallback('onPositionUpdate', function(qTip, event, content) {}
  111. MenuMiniPanels.setCallback('beforeShow', function(qTip, event, content) {}
  112. MenuMiniPanels.setCallback('onShow', function(qTip, event, content) {}
  113. MenuMiniPanels.setCallback('beforeHide', function(qTip, event, content) {}
  114. MenuMiniPanels.setCallback('onHide', function(qTip, event, content) {}
  115. MenuMiniPanels.setCallback('beforeContentUpdate', function(qTip, event, content) {}
  116. MenuMiniPanels.setCallback('onContentUpdate', function(qTip, event, content) {}
  117. MenuMiniPanels.setCallback('beforeContentLoad', function(qTip, event, content) {}
  118. MenuMiniPanels.setCallback('onContentLoad', function(qTip, event, content) {}
  119. MenuMiniPanels.setCallback('beforeTitleUpdate', function(qTip, event, content) {}
  120. MenuMiniPanels.setCallback('onTitleUpdate', function(qTip, event, content) {}
  121. MenuMiniPanels.setCallback('beforeDestroy', function(qTip, event, content) {}
  122. MenuMiniPanels.setCallback('onDestroy', function(qTip, event, content) {}
  123. MenuMiniPanels.setCallback('beforeFocus', function(qTip, event, content) {}
  124. MenuMiniPanels.setCallback('onFocus', function(qTip, event, content) {}
  125. Use a web browser debugging tool, e.g. Firebug or Safari's Web Inspector to
  126. identify the capabilities of each callback.
  127. To aid working with the menu system, the DOM path used to identify the menu
  128. item which activated a given MiniPanel is available from the string
  129. "qTip.options.activator", thus the object itself is available as
  130. $(qTip.options.activator).
  131. If either the "beforeShow" or "beforeHide" callbacks are to be used then the
  132. default callbacks must be disabled via the module's main settings page; see
  133. menu_minipanels.callbacks.js for further details.
  134. An example usage would be to make the menu item retain its 'active' state when
  135. its MiniPanel is displayed. Note: the module already adds the class
  136. "qtip-hover" to the menu items, this example shows how to add another class.
  137. /**
  138. * @file
  139. * Custom callbacks for Menu_MiniPanels.
  140. */
  141. (function($) {
  142. /**
  143. * Callback for the beforeShow qTip event.
  144. */
  145. MenuMiniPanels.setCallback('beforeShow', function(qTip, event, content) {
  146. // Mark target element as selected.
  147. var $target = $(qTip.elements.target.get(0));
  148. if ($target !== undefined) {
  149. $target.addClass('active');
  150. }
  151. });
  152. /**
  153. * Callback for the beforeHide qTip event.
  154. */
  155. MenuMiniPanels.setCallback('beforeHide', function(qTip, event) {
  156. // Unmark target element as selected.
  157. var $target = $(qTip.elements.target.get(0));
  158. if ($target !== undefined) {
  159. $target.removeClass('active');
  160. }
  161. });
  162. })(jQuery);