You are here

class sweaver_plugin_kb in Sweaver 6

Same name and namespace in other branches
  1. 7 plugins/sweaver_plugin_kb/sweaver_plugin_kb.inc \sweaver_plugin_kb

@file Key bindings plugin.

Hierarchy

Expanded class hierarchy of sweaver_plugin_kb

1 string reference to 'sweaver_plugin_kb'
_sweaver_sweaver_plugins in ./sweaver.registry.inc
Sweaver plugins.

File

plugins/sweaver_plugin_kb/sweaver_plugin_kb.inc, line 7
Key bindings plugin.

View source
class sweaver_plugin_kb extends sweaver_plugin {

  /**
   * Sweaver dependencies.
   */
  public function sweaver_dependencies() {
    if (!variable_get('sweaver_plugin_status_sweaver_plugin_styles', FALSE)) {
      return array(
        'Manage styles',
      );
    }
    return array();
  }

  /**
   * Menu registry.
   */
  public function sweaver_menu(&$weight, $page_arguments, $base) {
    $items = array();
    $items['admin/settings/sweaver/kb'] = $base + array(
      'title' => 'Keyboard',
      'page arguments' => array(
        $page_arguments,
      ),
      'type' => MENU_LOCAL_TASK,
      'weight' => $weight++,
    );
    return $items;
  }

  /**
   * Frontend css and js.
   */
  public function sweaver_form_css_js(&$inline_settings) {
    drupal_add_js(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_kb/jquery.hotkeys.js', 'module');
    drupal_add_js(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_kb/sweaver_plugin_kb.js', 'module');
    $first_key = variable_get('sweaver_plugin_kb_firstkey', '') != '' ? variable_get('sweaver_plugin_kb_firstkey', '') . '+' : '';
    $bindings = $this
      ->sweaver_kb_bindings();
    foreach ($bindings as $key => $value) {

      // Do not add when a certain variable isn't set. (eg delete tab)
      if (isset($value['variable']) && !variable_get($value['variable'], FALSE)) {
        continue;
      }

      // Get keyboard key. Make sure it's not empty.
      $keyboard_key = variable_get('sweaver_plugin_kb_' . $key, $value['default']);
      if (!empty($keyboard_key)) {
        $inline_settings['sweaver']['kb'][$key] = array(
          'combination' => $value['double'] ? $first_key . $keyboard_key : $keyboard_key,
          'element' => isset($value['element']) ? $value['element'] : '',
        );
      }
    }
  }

  /**
   * Keyboard bindings settings form.
   */
  public function sweaver_menu_callback() {
    $form = array();
    $bindings = $this
      ->sweaver_kb_bindings();
    $binding_options_firstkey = drupal_map_assoc($this
      ->sweaver_kb_binding_firstkeys());
    $binding_options = drupal_map_assoc($this
      ->sweaver_kb_binding_options());
    $form['info'] = array(
      '#type' => 'markup',
      '#value' => t('Select keys for every event possible. Note, there is no validation when saving this form, so make sure every event has a unique key combination.'),
    );
    $form['sweaver_plugin_kb_firstkey'] = array(
      '#type' => 'select',
      '#title' => t('First key'),
      '#options' => $binding_options_firstkey,
      '#description' => t('Can be used for all events, except the close popup'),
      '#default_value' => variable_get('sweaver_plugin_kb_firstkey', ''),
    );
    foreach ($bindings as $key => $value) {
      $form['sweaver_plugin_kb_' . $key] = array(
        '#type' => 'select',
        '#options' => $binding_options,
        '#title' => $value['title'],
        '#default_value' => variable_get('sweaver_plugin_kb_' . $key, $value['default']),
      );
    }
    return system_settings_form($form);
  }

  /**
   * Possible keyboard bindings.
   */
  public function sweaver_kb_bindings() {
    $bindings = array(
      'save' => array(
        'title' => t('Save style popup'),
        'default' => 's',
        'element' => '.save-style-popup',
        'double' => TRUE,
      ),
      'load' => array(
        'title' => t('Load style popup'),
        'default' => 'l',
        'element' => '.load-style-popup',
        'double' => TRUE,
      ),
      'publish' => array(
        'title' => t('Publish style popup'),
        'default' => 'p',
        'element' => '.publish-style-popup',
        'double' => TRUE,
      ),
      'delete' => array(
        'title' => t('Delete style popup'),
        'default' => 'd',
        'variable' => 'sweaver_styles_delete_tab',
        'element' => '.delete-style-popup',
        'double' => TRUE,
      ),
      'close' => array(
        'title' => t('Close popup'),
        'default' => 'esc',
        'double' => FALSE,
      ),
    );
    return $bindings;
  }

  /**
   * First key options
   */
  public function sweaver_kb_binding_firstkeys() {
    return array(
      '',
      'shift',
      'ctrl',
      'alt',
    );
  }

  /**
   * All possible keyboard bindings.
   */
  public function sweaver_kb_binding_options() {
    return array(
      '',
      'esc',
      'left',
      'up',
      'right',
      'down',
      '0',
      '1',
      '2',
      '3',
      '4',
      '5',
      '6',
      '7',
      '8',
      '9',
      'a',
      'b',
      'c',
      'd',
      'e',
      'f',
      'g',
      'h',
      'i',
      'j',
      'k',
      'l',
      'm',
      'n',
      'o',
      'p',
      'q',
      'r',
      's',
      't',
      'u',
      'v',
      'w',
      'x',
      'y',
      'z',
      'f1',
      'f2',
      'f3',
      'f4',
      'f5',
      'f6',
      'f7',
      'f8',
      'f9',
      'f10',
      'f11',
      'f12',
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
sweaver_plugin::sweaver_form public function Sweaver form. 8
sweaver_plugin::sweaver_form_render public function Sweaver form render. 2
sweaver_plugin::sweaver_form_submit public function Sweaver submit handler. 6
sweaver_plugin::sweaver_images_handler public function Images handler. 1
sweaver_plugin::sweaver_init public function Init function. 2
sweaver_plugin::sweaver_menu_callback_submit public function Menu callback submit. 2
sweaver_plugin::sweaver_menu_callback_validate public function Menu callback validate.
sweaver_plugin::sweaver_objects_alter public function Sweaver objects alter. 1
sweaver_plugin::sweaver_popups_render protected function Helper function render the popups.
sweaver_plugin::sweaver_preprocess_page public function Preprocess page function. 1
sweaver_plugin::sweaver_theme public function Theme registry. 1
sweaver_plugin_kb::sweaver_dependencies public function Sweaver dependencies. Overrides sweaver_plugin::sweaver_dependencies
sweaver_plugin_kb::sweaver_form_css_js public function Frontend css and js. Overrides sweaver_plugin::sweaver_form_css_js
sweaver_plugin_kb::sweaver_kb_bindings public function Possible keyboard bindings.
sweaver_plugin_kb::sweaver_kb_binding_firstkeys public function First key options
sweaver_plugin_kb::sweaver_kb_binding_options public function All possible keyboard bindings.
sweaver_plugin_kb::sweaver_menu public function Menu registry. Overrides sweaver_plugin::sweaver_menu
sweaver_plugin_kb::sweaver_menu_callback public function Keyboard bindings settings form. Overrides sweaver_plugin::sweaver_menu_callback