You are here

API.txt in Menu Minipanels 7

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

Custom style(s) for Menu_MiniPanels.

File

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