Bladeren bron

#114015, advanced menu settings to place menu anywhere on page, patch by Steve McKenzie, modified by me

Ted Serbinski 18 jaren geleden
bovenliggende
commit
6085946d1d
2 gewijzigde bestanden met toevoegingen van 51 en 8 verwijderingen
  1. 16 3
      simplemenu.js
  2. 35 5
      simplemenu.module

+ 16 - 3
simplemenu.js

@@ -3,9 +3,22 @@
 $(document).ready(function() {
   // get the Drupal basepath
   var basePath = Drupal.settings.simplemenu.basePath;
-                              
-  // insert extra <br /> so menu doesn't overlap theme
-  $('<ul id="simplemenu" class="clear-block"></ul>').prependTo('body');
+  // get the element to add the menu to
+  var element = Drupal.settings.simplemenu.element;                        
+  var menu = '<ul id="simplemenu" class="clear-block"></ul>';
+  
+  switch (Drupal.settings.simplemenu.placement) {
+    case 'prepend':
+      $(menu).prependTo(element);
+      break;
+    case 'append':
+      $(menu).appendTo(element);
+      break;
+    case 'replace':
+      $(element).html(menu);
+      break;
+  }  
+  
   $('body').css('margin-top', '23px');
   
   // Drupal menu callback

+ 35 - 5
simplemenu.module

@@ -33,11 +33,17 @@ function simplemenu_menu($may_cache) {
   // We put this in !$may_cache so it's only added once per request
   elseif (user_access('view simplemenu')) {
     $path = drupal_get_path('module', 'simplemenu');
-    drupal_add_css($path .'/simplemenu.css');
-  
-    // pass in base path to the JS file
-    // url() handles appending ?q= but in this case, we need to pass in the variable so the menus work when mod_rewrite is off
-    drupal_add_js(array('simplemenu' => array('basePath' => base_path() . (variable_get('clean_url', 0) ? '' : '?q='))), 'setting');
+    drupal_add_css($path .'/simplemenu.css');  
+    
+    $settings = array(                       
+      // pass in base path to the JS file
+      // url() handles appending ?q= but in this case, we need to pass in the variable so the menus work when mod_rewrite is off
+      'basePath' => base_path() . (variable_get('clean_url', 0) ? '' : '?q='),
+      'placement' => variable_get('simplemenu_element_method', 'prepend'),
+      'element' => variable_get('simplemenu_element', 'body')
+    );
+    
+    drupal_add_js(array('simplemenu' => $settings), 'setting');
     drupal_add_js($path .'/simplemenu.js');
   }
 
@@ -68,6 +74,30 @@ function simplemenu_admin_settings() {
     '#title' => t('Add devel module links'),
     '#default_value' => variable_get('simplemenu_devel', 0),
     '#description' => t('Add devel module links for those users that can access the devel module.')
+  );                             
+  
+  $form['default_menu']['advanced'] = array(
+    '#type' => 'fieldset', 
+    '#title' => t('Advanced settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE
+  );
+  
+  $form['default_menu']['advanced']['simplemenu_element'] = array(
+    '#type' => 'textfield',
+    '#title' => t('CSS selector to attach menu to'),
+    '#default_value' => variable_get('simplemenu_element', 'body'),
+    '#description' => t('A valid CSS selector to attach the menu to. <em>Example: body, #primary, div.my-class</em>'),
+    '#required' => TRUE
+  );
+  
+  $form['default_menu']['advanced']['simplemenu_element_method'] = array(
+    '#type' => 'radios',
+    '#title' => 'Attach method', 
+    '#options' => drupal_map_assoc(array('prepend', 'append', 'replace')),
+    '#default_value' => variable_get('simplemenu_element_method', 'prepend'),
+    '#description' => t('Choose how the menu should be attached to the above selector.'),
+    '#required' => TRUE
   );
   
   return system_settings_form($form);