1<?php
2/**
3 * Virtual Keyboard plugin
4 *
5 * $Id: action.php 22 2007-01-04 02:08:26Z wingedfox $
6 * $HeadURL: https://svn.debugger.ru/repos/common/DokuWiki/VirtualKeyboard/tags/VirtualKeyboard.v0.2.1/action.php $
7 *
8 * @license    LGPL 2 (http://www.gnu.org/licenses/lgpl.html)
9 * @author     Ilya Lebedev <ilya@lebedev.net>
10 * @copyright  2007 Ilya Lebedev
11 */
12
13if(!defined('DOKU_INC')) die();
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15require_once(DOKU_PLUGIN.'action.php');
16
17class action_plugin_virtualkeyboard extends DokuWiki_Action_Plugin {
18
19  /**
20   *  Flags to embed loader, if keyboard has been embedded somewhere, except the edit page
21   *
22   *  @type Boolean
23   *  @access private
24   */
25  var $injectKeyboard = false;
26  /**
27   * return some info
28   */
29  function getInfo(){
30    return array(
31                 'author' => 'Ilya Lebedev',
32                 'email'  => 'ilya@lebedev.net',
33                 'date'   => '$Date: 2007-01-04 05:08:26 +0300 (Чтв, 04 Янв 2007) $',
34                 'name'   => 'Virtual Keyboard',
35                 'desc'   => 'Adds the VirtualKeyboard control to the edit form.',
36                 'url'    => 'http://wiki.splitbrain.org/plugin:virtualkeyboard',
37                 );
38  }
39
40  /*
41   * plugin should use this method to register its handlers with the dokuwiki's event controller
42   */
43  function register(&$controller) {
44    $controller->register_hook('HTML_EDITFORM_INJECTION','AFTER', $this, '_inject_keyboard');
45    $controller->register_hook('TPL_METAHEADER_OUTPUT','BEFORE', $this, '_inject_loader');
46  }
47
48  /**
49   *  Inject the virtual keyboard loaders
50   *
51   *  @author Ilya Lebedev <ilya@lebedev.net>
52   *  @param $event object target event
53   *  @param $param mixed event parameters passed from register_hook
54   */
55  function _inject_loader (&$event, $param) {
56      global $INFO;
57      global $ACT;
58
59      // inject loader and styles
60      $js_edit  = ($ACT=='edit' || $ACT=='preview' || $ACT=='recover' || $ACT=='wordblock' ) ? 1 : 0;
61      $js_write = ($INFO['writable']) ? 1 : 0;
62
63      if ($js_edit && $js_write){
64          $this->injectKeyboard = true;
65          $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', 'src' => DOKU_BASE.'lib/plugins/virtualkeyboard/vk/vk_loader.js'
66                                           ,'_data'=>'');
67          $event->data['link'][] = array( 'rel'=>'stylesheet', 'type'=>'text/css', 'title'=>'VirtualKeyboard'
68                                         ,'href'=>DOKU_BASE.'lib/plugins/virtualkeyboard/vk/keyboard/keyboard.css'
69                                         ,'_data'=>'');
70      }
71  }
72
73  /**
74   *  Inject the virtual keyboard itself
75   *
76   *  @author Ilya Lebedev <ilya@lebedev.net>
77   *  @param $event object target event
78   *  @param $param mixed event parameters passed from register_hook
79   */
80  function _inject_keyboard (&$event, $param) {
81    global $INFO;
82
83    if (!$event->data['writable'] || !$this->injectKeyboard) return;
84
85//            <div style="width: 100%; border: 1px solid green;">
86//              <fieldset class="virtualKeyboard">
87//                  <legend>VirtualKeyboard</legend>
88//              </fieldset>
89//            </div>
90    echo <<< EOQ
91                <div style="width: 100%;">
92                  VirtualKeyboard: <select accesskey="v" id="showVKeyboard" onChange="this.value=='0'?VirtualKeyboard.close():(VirtualKeyboard.show(this.form.elements['wikitext'],'virtualKeyboardHolder'),VirtualKeyboard.switchLayout.apply(this,this.value.split('\u00a0-\u00a0')));" ><option value="0">Closed</option></select>
93                  <script type="text/javascript"><!--//--><![CDATA[//><!--
94                      if (window.addEventListener) window.addEventListener ('load', function() {(new Selectbox('showVKeyboard')).addOptionsList(VirtualKeyboard.getLayouts())}, false);
95                      else if (window.attachEvent) window.attachEvent ('onload', function() {(new Selectbox('showVKeyboard')).addOptionsList(VirtualKeyboard.getLayouts())});
96                  //--><!]]></script>
97                  <div id="virtualKeyboardHolder" style="width: 100%"></div>
98                </div>
99EOQ;
100  }
101}
102